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)
| 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): |