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

Class _SharedFile

Lib/zipfile/__init__.py:884–924  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

882
883
884class _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
927class _Tellable:

Callers 1

openMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…