MCPcopy Index your code
hub / github.com/RustPython/RustPython / ZipPathInfo

Class ZipPathInfo

Lib/test/test_pathlib/support/zip_path.py:117–200  ·  view source on GitHub ↗

PathInfo implementation for an existing zip file member.

Source from the content-addressed store, hash-verified

115
116
117class ZipPathInfo(PathInfo):
118 """
119 PathInfo implementation for an existing zip file member.
120 """
121 __slots__ = ('zip_file', 'zip_info', 'parent', 'children')
122
123 def __init__(self, zip_file, parent=None):
124 self.zip_file = zip_file
125 self.zip_info = None
126 self.parent = parent or self
127 self.children = {}
128
129 def exists(self, follow_symlinks=True):
130 if follow_symlinks and self.is_symlink():
131 return self.resolve().exists()
132 return True
133
134 def is_dir(self, follow_symlinks=True):
135 if follow_symlinks and self.is_symlink():
136 return self.resolve().is_dir()
137 elif self.zip_info is None:
138 return True
139 elif fmt := S_IFMT(self.zip_info.external_attr >> 16):
140 return S_ISDIR(fmt)
141 else:
142 return self.zip_info.filename.endswith('/')
143
144 def is_file(self, follow_symlinks=True):
145 if follow_symlinks and self.is_symlink():
146 return self.resolve().is_file()
147 elif self.zip_info is None:
148 return False
149 elif fmt := S_IFMT(self.zip_info.external_attr >> 16):
150 return S_ISREG(fmt)
151 else:
152 return not self.zip_info.filename.endswith('/')
153
154 def is_symlink(self):
155 if self.zip_info is None:
156 return False
157 elif fmt := S_IFMT(self.zip_info.external_attr >> 16):
158 return S_ISLNK(fmt)
159 else:
160 return False
161
162 def resolve(self, path=None, create=False, follow_symlinks=True):
163 """
164 Traverse zip hierarchy (parents, children and symlinks) starting
165 from this PathInfo. This is called from three places:
166
167 - When a zip file member is added to ZipFile.filelist, this method
168 populates the ZipPathInfo tree (using create=True).
169 - When ReadableZipPath.info is accessed, this method is finds a
170 ZipPathInfo entry for the path without resolving any final symlink
171 (using follow_symlinks=False)
172 - When ZipPathInfo methods are called with follow_symlinks=True, this
173 method resolves any symlink in the final path position.
174 """

Callers 2

resolveMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected