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

Method close

Lib/compression/zstd/_zstdfile.py:96–119  ·  view source on GitHub ↗

Flush and close the file. May be called multiple times. Once the file has been closed, any other operation on it will raise ValueError.

(self)

Source from the content-addressed store, hash-verified

94 self._buffer = io.BufferedReader(raw)
95
96 def close(self):
97 """Flush and close the file.
98
99 May be called multiple times. Once the file has been closed,
100 any other operation on it will raise ValueError.
101 """
102 if self._fp is None:
103 return
104 try:
105 if self._mode == _MODE_READ:
106 if getattr(self, '_buffer', None):
107 self._buffer.close()
108 self._buffer = None
109 elif self._mode == _MODE_WRITE:
110 self.flush(self.FLUSH_FRAME)
111 self._compressor = None
112 finally:
113 self._mode = _MODE_CLOSED
114 try:
115 if self._close_fp:
116 self._fp.close()
117 finally:
118 self._fp = None
119 self._close_fp = False
120
121 def write(self, data, /):
122 """Write a bytes-like object *data* to the file.

Callers 15

zstopenMethod · 0.95
test_closeMethod · 0.95
test_closedMethod · 0.95
test_filenoMethod · 0.95
test_nameMethod · 0.95
test_seekableMethod · 0.95
test_readableMethod · 0.95
test_writableMethod · 0.95
test_read_bad_argsMethod · 0.95
test_read1_bad_argsMethod · 0.95
test_write_bad_argsMethod · 0.95
test_seek_bad_argsMethod · 0.95

Calls 1

flushMethod · 0.95

Tested by 13

test_closeMethod · 0.76
test_closedMethod · 0.76
test_filenoMethod · 0.76
test_nameMethod · 0.76
test_seekableMethod · 0.76
test_readableMethod · 0.76
test_writableMethod · 0.76
test_read_bad_argsMethod · 0.76
test_read1_bad_argsMethod · 0.76
test_write_bad_argsMethod · 0.76
test_seek_bad_argsMethod · 0.76
test_tell_bad_argsMethod · 0.76