88
99import errno
1010import io
11- import pathlib .types
1211import posixpath
1312import stat
1413import zipfile
1514from stat import S_IFMT , S_ISDIR , S_ISREG , S_ISLNK
1615
16+ from . import is_pypi
17+
18+ if is_pypi :
19+ from pathlib_abc import PathInfo , _ReadablePath , _WritablePath
20+ else :
21+ from pathlib .types import PathInfo , _ReadablePath , _WritablePath
22+
1723
1824class ZipPathGround :
1925 can_symlink = True
@@ -31,7 +37,10 @@ def create_file(self, path, data=b''):
3137 path .zip_file .writestr (str (path ), data )
3238
3339 def create_dir (self , path ):
34- path .zip_file .mkdir (str (path ))
40+ zip_info = zipfile .ZipInfo (str (path ) + '/' )
41+ zip_info .external_attr |= stat .S_IFDIR << 16
42+ zip_info .external_attr |= stat .FILE_ATTRIBUTE_DIRECTORY
43+ path .zip_file .writestr (zip_info , '' )
3544
3645 def create_symlink (self , path , target ):
3746 zip_info = zipfile .ZipInfo (str (path ))
@@ -80,7 +89,7 @@ def islink(self, p):
8089 return stat .S_ISLNK (info .external_attr >> 16 )
8190
8291
83- class MissingZipPathInfo :
92+ class MissingZipPathInfo ( PathInfo ) :
8493 """
8594 PathInfo implementation that is used when a zip file member is missing.
8695 """
@@ -105,7 +114,7 @@ def resolve(self):
105114missing_zip_path_info = MissingZipPathInfo ()
106115
107116
108- class ZipPathInfo :
117+ class ZipPathInfo ( PathInfo ) :
109118 """
110119 PathInfo implementation for an existing zip file member.
111120 """
@@ -216,7 +225,7 @@ def append(self, item):
216225 self .tree .resolve (item .filename , create = True ).zip_info = item
217226
218227
219- class ReadableZipPath (pathlib . types . _ReadablePath ):
228+ class ReadableZipPath (_ReadablePath ):
220229 """
221230 Simple implementation of a ReadablePath class for .zip files.
222231 """
@@ -279,7 +288,7 @@ def readlink(self):
279288 return self .with_segments (self .zip_file .read (info .zip_info ).decode ())
280289
281290
282- class WritableZipPath (pathlib . types . _WritablePath ):
291+ class WritableZipPath (_WritablePath ):
283292 """
284293 Simple implementation of a WritablePath class for .zip files.
285294 """
@@ -314,10 +323,13 @@ def __open_wb__(self, buffering=-1):
314323 return self .zip_file .open (str (self ), 'w' )
315324
316325 def mkdir (self , mode = 0o777 ):
317- self .zip_file .mkdir (str (self ), mode )
326+ zinfo = zipfile .ZipInfo (str (self ) + '/' )
327+ zinfo .external_attr |= stat .S_IFDIR << 16
328+ zinfo .external_attr |= stat .FILE_ATTRIBUTE_DIRECTORY
329+ self .zip_file .writestr (zinfo , '' )
318330
319331 def symlink_to (self , target , target_is_directory = False ):
320- zinfo = zipfile .ZipInfo (str (self )). _for_archive ( self . zip_file )
332+ zinfo = zipfile .ZipInfo (str (self ))
321333 zinfo .external_attr = stat .S_IFLNK << 16
322334 if target_is_directory :
323335 zinfo .external_attr |= 0x10
0 commit comments