o bD#@sdZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z ddl mZmZmZmZmZdZe e eGd d d eZGd d d eZd d gZdS) zt This module contains implementations of L{IFilePath} for zip files. See the constructor of L{ZipArchive} for use. N)Dict)ZipFile) implementer)cmp comparable)AbstractFilePathFilePath IFilePathUnlistableError_coerceToFilesystemEncoding/c@seZdZdZddZddZdefddZed d Z d d Z d dZ ddZ ddZ ddZddZddZddZddZddZdd Zd/d"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.S)0ZipPathzF I represent a file or directory contained within a zip file. cCsF||_||_t|t}t||jj}tjj|g|j |R|_dS)z Don't construct me directly. Use C{ZipArchive.child()}. @param archive: a L{ZipArchive} instance. @param pathInArchive: a ZIP_PATH_SEP-separated string. N) archive pathInArchiver ZIP_PATH_SEPzipfilefilenameospathjoinsplit)selfrrseparchiveFilenamer8/usr/lib/python3/dist-packages/twisted/python/zippath.py__init__(s "zZipPath.__init__cCs(t|tstSt|j|jf|j|jfSN) isinstancer NotImplementedrrr)rotherrrr__cmp__;s zZipPath.__cmp__returncCsNt|jtj|jjg}||j|jt|jtj}d| |dS)NzZipPath()) r rrrabspathrextendrrr)rpartsosseprrr__repr__Bs zZipPath.__repr__cCs t|jtS)z Return a zip directory separator. @return: The zip directory separator. @returntype: The same type as C{self.path}. )r rrrrrrrJs z ZipPath.sepcCs<|j|j}t|dkr|jSt|j|j|ddS)N)rrrlenrr r)rsplituprrrparentTs zZipPath.parentcCs,t|t}t||j}t|j|||gS)a& Return a new ZipPath representing a path in C{self.archive} which is a child of this path. @note: Requesting the C{".."} (or other special name) child will not cause L{InsecurePath} to be raised since these names do not have any special meaning inside a zip archive. Be particularly careful with the C{path} attribute (if you absolutely must use it) as this means it may include special names with special meaning outside of the context of a zip archive. )r rrr rr)rrjoinerrrrrchildZs z ZipPath.childcCs||Sr)r.r0rrrrrsiblingjzZipPath.siblingcCs|p|Sr)isdirisfiler)rrrexistsmzZipPath.existscCs|j|jjvSr)rrchildmapr)rrrr4pr3z ZipPath.isdircCs|j|jjjvSr)rrr NameToInfor)rrrr5sr7zZipPath.isfilecCsdS)NFrr)rrrislinkvzZipPath.islinkcCsF|r|rt|jj|jSttt j dttt j d)NzLeaf zip entry listedzNon-existent zip entry listed) r6r4listrr8rkeysr OSErrorerrnoENOTDIRENOENTr)rrrlistdirys zZipPath.listdircCstj|jS)zQ Return a value similar to that returned by C{os.path.splitext}. )rrsplitextr)rrrrCszZipPath.splitextcCs|j|jdS)Nr+)rrrr)rrrbasenameszZipPath.basenamecCs |jSr)r.rr)rrrdirnames zZipPath.dirnamercCstd|j}|jjj||dS)N)mode)r rrropen)rrHrrrrrIs z ZipPath.opencCsdSrrr)rrrchangedr;zZipPath.changedcCstd|j}|jjj|jS)zR Retrieve this file's size. @return: file size, in bytes rG)r rrrr9 file_sizerrrrrgetsizes zZipPath.getsizecCs |jS)z Retrieve this file's last access-time. This is the same as the last access time for the archive. @return: a number of seconds since the epoch )r getAccessTimer)rrrrN zZipPath.getAccessTimecCs&td|j}t|jjj|jdS)z Retrieve this file's last modification time. This is the time of modification recorded in the zipfile. @return: a number of seconds since the epoch. rG)rrr)r rtimemktimerrr9 date_timerLrrrgetModificationTimes zZipPath.getModificationTimecCs|S)z Retrieve this file's last modification time. This name is provided for compatibility, and returns the same value as getmtime. @return: a number of seconds since the epoch. )rSr)rrrgetStatusChangeTimeszZipPath.getStatusChangeTimeN)rF)__name__ __module__ __qualname____doc__rr!strr(propertyrr.r0r2r6r4r5r:rBrCrDrErIrJrMrNrSrTrrrrr !s0       r c@sZeZdZdZeddZddZddZdd Zd d Z d d Z ddZ de fddZ dS) ZipArchivea I am a L{FilePath}-like object which can wrap a zip archive as if it were a directory. It works similarly to L{FilePath} in L{bytes} and L{unicode} handling -- instantiating with a L{bytes} will return a "bytes mode" L{ZipArchive}, and instantiating with a L{unicode} will return a "text mode" L{ZipArchive}. Methods that return new L{ZipArchive} or L{ZipPath} instances will be in the mode of the argument to the creator method, converting if required. cCs|Srrr)rrrrszZipArchive.archivecCs||_ttd||_t|d|_i|_|jD];}t|j||j}t t |D]#}|| }|j |d| }||jvrGi|j|<d|j||<q+t|d}qdS)z Create a ZipArchive, treating the archive at archivePathname as a zip file. @param archivePathname: a L{bytes} or L{unicode}, naming a path in the filesystem. rGNr*) rrr rrr8namelistrrranger,r)rarchivePathnamenamexr0r.rrrrs     zZipArchive.__init__cCs t||S)z Create a ZipPath pointing at a path within the archive. @param path: a L{bytes} or L{unicode} with no path separators in it (either '/' or the system path separator, if it's different). )r r1rrrr0rOzZipArchive.childcCt|jjS)zC Returns C{True} if the underlying archive exists. )rrrr6r)rrrr6zZipArchive.existscCra)z= Return the archive file's last access time. )rrrrNr)rrrrNrbzZipArchive.getAccessTimecCra)z> Return the archive file's modification time. )rrrrSr)rrrrSrbzZipArchive.getModificationTimecCra)z? Return the archive file's status change time. )rrrrTr)rrrrT rbzZipArchive.getStatusChangeTimer"cCsdtj|jdS)Nz ZipArchive(r#)rrr$r)rrrr(szZipArchive.__repr__N)rUrVrWrXrZrrr0r6rNrSrTrYr(rrrrr[s  r[)rXr?rrPtypingrrrzope.interfacertwisted.python.compatrrtwisted.python.filepathrrr r r rr r[__all__rrrrs    " O