MCPcopy Index your code
hub / github.com/python/cpython / close

Method close

Lib/bz2.py:97–118  ·  view source on GitHub ↗

Flush and close the file. May be called more than once without error. Once the file is closed, any other operation on it will raise a ValueError.

(self)

Source from the content-addressed store, hash-verified

95 self._pos = 0
96
97 def close(self):
98 """Flush and close the file.
99
100 May be called more than once without error. Once the file is
101 closed, any other operation on it will raise a ValueError.
102 """
103 if self.closed:
104 return
105 try:
106 if self._mode == _MODE_READ:
107 self._buffer.close()
108 elif self._mode == _MODE_WRITE:
109 self._fp.write(self._compressor.flush())
110 self._compressor = None
111 finally:
112 try:
113 if self._closefp:
114 self._fp.close()
115 finally:
116 self._fp = None
117 self._closefp = False
118 self._buffer = None
119
120 @property
121 def closed(self):

Callers 7

bz2openMethod · 0.95
testFilenoMethod · 0.95
testSeekableMethod · 0.95
testReadableMethod · 0.95
testWritableMethod · 0.95
testContextProtocolMethod · 0.95

Calls 2

writeMethod · 0.45
flushMethod · 0.45

Tested by 6

testFilenoMethod · 0.76
testSeekableMethod · 0.76
testReadableMethod · 0.76
testWritableMethod · 0.76
testContextProtocolMethod · 0.76