U  W[$@sdZddlmZmZddlZddlZddlZddlmZddl m Z m Z ddl m Z mZmZddl mZddl mZdd lmZd Ze ee Gd d d eZGd ddeZdd gZdS)zt This module contains implementations of L{IFilePath} for zip files. See the constructor of L{ZipArchive} for use. )absolute_importdivisionN)ZipFile) comparablecmp) IFilePathFilePathAbstractFilePath)_coerceToFilesystemEncoding)UnlistableError) implementer/c@seZdZdZddZddZddZedd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZddZddZddZd.d!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-S)/ZipPathzF I represent a file or directory contained within a zip file. cCsD||_||_t|t}t||jj}tjj|f|j ||_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)selfrrsepZarchiveFilenamer8/usr/lib/python3/dist-packages/twisted/python/zippath.py__init__%s   zZipPath.__init__cCs(t|tstSt|j|jf|j|jfSN) isinstancerNotImplementedrrr)rotherrrr__cmp__9s    zZipPath.__cmp__cCsLt|jtj|jjg}||j|jt|jtj}d| |fS)Nz ZipPath(%r)) r rrrabspathrextendrrr)rpartsZosseprrr__repr__@szZipPath.__repr__cCs t|jtS)z Return a zip directory separator. @return: The zip directory separator. @returntype: The same type as C{self.path}. )r rrrrrrrHsz ZipPath.sepcCs<|j|j}t|dkr |jSt|j|j|ddS)N)rrrlenrrr)rZsplituprrrparentSs 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 rrrrr)rrZjoinerrrrrchildZs  z ZipPath.childcCs||Sr)r*r+rrrrrsiblingkszZipPath.siblingcCs|p|Sr)isdirisfiler&rrrexistsoszZipPath.existscCs|j|jjkSr)rrchildmapr&rrrr.ssz ZipPath.isdircCs|j|jjjkSr)rrr NameToInfor&rrrr/wszZipPath.isfilecCsdS)NFrr&rrrislink{szZipPath.islinkcCsL|r8|r&t|jj|jSttt j dnttt j ddS)NzLeaf zip entry listedzNon-existent zip entry listed) r0r.listrr1rkeysr OSErrorerrnoZENOTDIRZENOENTr&rrrlistdirs  zZipPath.listdircCstj|jS)zQ Return a value similar to that returned by C{os.path.splitext}. )rrsplitextr&rrrr9szZipPath.splitextcCs|j|jdS)Nr()rrrr&rrrbasenameszZipPath.basenamecCs |jSr)r*rr&rrrdirnameszZipPath.dirnamercCstd|j}|jjj||dS)N)mode)r rrropen)rr>rrrrr?s z ZipPath.opencCsdSrrr&rrrchangedszZipPath.changedcCstd|j}|jjj|jS)zR Retrieve this file's size. @return: file size, in bytes r=)r rrrr2 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&rrrrDszZipPath.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. r=)rrr)r rtimemktimerrr2Z date_timerBrrrgetModificationTimes  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. )rGr&rrrgetStatusChangeTimeszZipPath.getStatusChangeTimeN)r<)__name__ __module__ __qualname____doc__rr!r%propertyrr*r+r-r0r.r/r3r8r9r:r;r?r@rCrDrGrHrrrrrs.       rc@sTeZdZdZeddZddZddZdd Zd d Z d d Z ddZ ddZ 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&rrrzZipArchive.cCs||_ttd||_t|d|_i|_|jD]v}t|j||j}t t |D]F}|| }|j |d| }||jkri|j|<d|j||<qVt|d}q2dS)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. r=Nr') rrr rrr1Znamelistrrranger)r)rZarchivePathnamenamexr+r*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). )rr,rrrr+szZipArchive.childcCst|jjS)zC Returns C{True} if the underlying archive exists. )rrrr0r&rrrr0szZipArchive.existscCst|jjS)z= Return the archive file's last access time. )rrrrDr&rrrrDszZipArchive.getAccessTimecCst|jjS)z> Return the archive file's modification time. )rrrrGr&rrrrGszZipArchive.getModificationTimecCst|jjS)z? Return the archive file's status change time. )rrrrHr&rrrrHszZipArchive.getStatusChangeTimecCsdtj|jfS)NzZipArchive(%r))rrr"r&rrrr%#szZipArchive.__repr__N) rIrJrKrLrMrrr+r0rDrGrHr%rrrrrNs  rN)rLZ __future__rrrrEr7rrZtwisted.python.compatrrZtwisted.python.filepathrrr r r Zzope.interfacer rrrN__all__rrrrs"    5S