| 882 | |
| 883 | |
| 884 | class _SharedFile: |
| 885 | def __init__(self, file, pos, close, lock, writing): |
| 886 | self._file = file |
| 887 | self._pos = pos |
| 888 | self._close = close |
| 889 | self._lock = lock |
| 890 | self._writing = writing |
| 891 | self.seekable = file.seekable |
| 892 | |
| 893 | def tell(self): |
| 894 | return self._pos |
| 895 | |
| 896 | def seek(self, offset, whence=0): |
| 897 | with self._lock: |
| 898 | if self._writing(): |
| 899 | raise ValueError("Can't reposition in the ZIP file while " |
| 900 | "there is an open writing handle on it. " |
| 901 | "Close the writing handle before trying to read.") |
| 902 | if whence == os.SEEK_CUR: |
| 903 | self._file.seek(self._pos + offset) |
| 904 | else: |
| 905 | self._file.seek(offset, whence) |
| 906 | self._pos = self._file.tell() |
| 907 | return self._pos |
| 908 | |
| 909 | def read(self, n=-1): |
| 910 | with self._lock: |
| 911 | if self._writing(): |
| 912 | raise ValueError("Can't read from the ZIP file while there " |
| 913 | "is an open writing handle on it. " |
| 914 | "Close the writing handle before trying to read.") |
| 915 | self._file.seek(self._pos) |
| 916 | data = self._file.read(n) |
| 917 | self._pos = self._file.tell() |
| 918 | return data |
| 919 | |
| 920 | def close(self): |
| 921 | if self._file is not None: |
| 922 | fileobj = self._file |
| 923 | self._file = None |
| 924 | self._close(fileobj) |
| 925 | |
| 926 | # Provide the tell method for unseekable stream |
| 927 | class _Tellable: |
no outgoing calls
no test coverage detected
searching dependent graphs…