ó
ē~Mc           @   sÖ   d  Z  e Z d d l Z d d l Z d d l Z d d l Z e j d  d k rh e Z	 d d l
 m Z n e Z	 d d l m Z d d l m Z m Z d Z d	 e f d
     YZ d e f d     YZ d d	 g Z d S(   sä   
This module contains partial re-implementations of FilePath, pending some
specification of formal interfaces it is a duck-typing attempt to emulate them
for certain restricted uses.

See the constructor for ZipArchive for use.
i’’’’Ni   i   (   t   ZipFile(   t   ChunkingZipFile(   t   FilePatht   _PathHelpert   /t   ZipPathc           B   s¹   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sF   
    I represent a file or directory contained within a zip file.
    c         C   s@   | |  _  | |  _ t j j | j j |  j j t   |  _ d S(   s·   
        Don't construct me directly.  Use ZipArchive.child().

        @param archive: a ZipArchive instance.

        @param pathInArchive: a ZIP_PATH_SEP-separated string.
        N(	   t   archivet   pathInArchivet   ost   patht   joint   zipfilet   filenamet   splitt   ZIP_PATH_SEP(   t   selfR   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   __init__+   s    		c         C   s8   t  | t  s t St |  j |  j f | j | j f  S(   N(   t
   isinstanceR   t   NotImplementedt   cmpR   R   (   R   t   other(    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   __cmp__:   s    c         C   sZ   t  j j |  j j  g } | j |  j j t   t  j j	 |  } d | j
 d  f S(   Ns   ZipPath('%s')s   string-escape(   R   R	   t   abspathR   t   extendR   R   R   t   sepR
   t   encode(   R   t   partsR	   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   __repr__A   s    c         C   sH   |  j  j t  } t |  d k r+ |  j St |  j t j | d    S(   Ni   i’’’’(   R   R   R   t   lenR   R   R
   (   R   t   splitup(    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   parentH   s    c         C   s"   t  |  j t j |  j | g   S(   s&  
        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   R   R   R
   R   (   R   R	   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   childO   s    c         C   s   |  j    j |  S(   N(   R   R   (   R   R	   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   sibling^   s    c         C   s   |  j    p |  j   S(   N(   t   isdirt   isfile(   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   existsc   s    c         C   s   |  j  |  j j k S(   N(   R   R   t   childmap(   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR!   f   s    c         C   s   |  j  |  j j j k S(   N(   R   R   R   t
   NameToInfo(   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR"   i   s    c         C   s   t  S(   N(   t   False(   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   islinkl   s    c         C   sZ   |  j    rD |  j   r/ |  j j |  j j   St t j d   n t t j	 d   d  S(   Ns   Leaf zip entry listeds   Non-existent zip entry listed(
   R#   R!   R   R$   R   t   keyst   OSErrort   errnot   ENOTDIRt   ENOENT(   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   listdiro   s
    c         C   s   t  j j |  j  S(   sN   
        Return a value similar to that returned by os.path.splitext.
        (   R   R	   t   splitext(   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR.   y   s    c         C   s   |  j  j t  d S(   Ni’’’’(   R   R   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   basename   s    c         C   s   |  j    j S(   N(   R   R	   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   dirname   s    c         C   s6   t  r |  j j j |  j  S|  j j j |  j  Sd  S(   N(   t   _USE_ZIPFILER   R   t   openR   t   readfile(   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR2      s    c         C   s   d  S(   N(    (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   restat   s    c         C   s   |  j  j   S(   s±   
        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   t   getAccessTime(   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR5      s    c         C   s$   t  j |  j j j |  j j d  S(   sø   
        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.
        i    (   i    i    i    (   t   timet   mktimeR   R   R%   R   t	   date_time(   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   getModificationTime   s    c         C   s
   |  j    S(   sĻ   
        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.
        (   R9   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   getStatusChangeTime«   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R    R#   R!   R"   R'   R-   R.   R/   R0   R2   R4   R5   R9   R:   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR   '   s(   											
	
					
	t
   ZipArchivec           B   s\   e  Z d  Z e d    Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z RS(	   s]    I am a FilePath-like object which can wrap a zip archive as if it were a
    directory.
    c         C   s   |  S(   N(    (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   <lambda>ŗ   s    c         C   sį   t  r t |  |  _ n t |  |  _ | |  _ d |  _ i  |  _ x |  j j   D] } | j t	  } xi t
 t |   D]U } | | } t	 j | |   } | |  j k r¾ i  |  j | <n  d |  j | | <qz Wd } qR Wd S(   s   Create a ZipArchive, treating the archive at archivePathname as a zip file.

        @param archivePathname: a str, naming a path in the filesystem.
        t    i   N(   R1   R    R   R   R	   R   R$   t   namelistR   R   t   rangeR   R
   (   R   t   archivePathnamet   namet   xR   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR   »   s    			c         C   s   t  |  |  S(   sČ   
        Create a ZipPath pointing at a path within the archive.

        @param path: a str with no path separators in it, either '/' or the
        system path separator, if it's different.
        (   R   (   R   R	   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR   Ō   s    c         C   s   t  |  j j  j   S(   s@   
        Returns true if the underlying archive exists.
        (   R   R   R   R#   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR#   Ż   s    c         C   s   t  |  j j  j   S(   s=   
        Return the archive file's last access time.
        (   R   R   R   R5   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR5   ä   s    c         C   s   t  |  j j  j   S(   s>   
        Return the archive file's modification time.
        (   R   R   R   R9   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR9   ė   s    c         C   s   t  |  j j  j   S(   s?   
        Return the archive file's status change time.
        (   R   R   R   R:   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR:   ņ   s    c         C   s   d t  j j |  j  f S(   Ns   ZipArchive(%r)(   R   R	   R   (   R   (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR   ł   s    (   R;   R<   R=   t   propertyR   R   R   R#   R5   R9   R:   R   (    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyR>   ¶   s   							(   i   i   (   R=   t   typet   __metaclass__R   R6   R*   t   syst   version_infot   TrueR1   R   R    R&   t   twisted.python.zipstreamR   t   twisted.python.filepathR   R   R   R   R>   t   __all__(    (    (    s:   /usr/lib/python2.7/dist-packages/twisted/python/zippath.pyt   <module>   s   G