
[XMc           @   s1  d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z m Z m Z m	 Z	 m
 Z
 d d l m Z m Z d d l m Z d d l m Z d d l m Z m Z m Z d d l m Z m Z d d	 l m Z d d
 l m Z d d l m Z m Z d d l m Z m Z m Z d d l m  Z  e j! e j" Be j# Be BZ$ d   Z% d   Z& d   Z' e( e j) d e%  Z* e( e d e&  Z+ e( e d e'  Z, d e- f d     YZ. d e- f d     YZ/ d e0 f d     YZ1 d e1 e  f d     YZ2 d   Z3 d f  d     YZ4 d e4 f d      YZ5 e5 e5 _6 d S(!   s1   
Object-oriented filesystem path representation.
iN(   t   isabst   existst   normpatht   abspatht   splitext(   t   basenamet   dirname(   t   join(   t   sep(   t   listdirt   utimet   stat(   t   S_ISREGt   S_ISDIR(   t   platform(   t   sha1(   t   ERROR_FILE_NOT_FOUNDt   ERROR_PATH_NOT_FOUND(   t   ERROR_INVALID_NAMEt   ERROR_DIRECTORYt   O_BINARY(   t   WindowsErrorc         C   s   t  S(   s   
    Always return 'false' if the operating system does not support symlinks.

    @param path: a path string.
    @type path: L{str}
    @return: false
    (   t   False(   t   path(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   _stub_islink'   s    c         C   s>   g  t  |   D] }  t j d  ^ q } d j t t |   S(   s  
    Provide random data in versions of Python prior to 2.4.  This is an
    effectively compatible replacement for 'os.urandom'.

    @type n: L{int}
    @param n: the number of bytes of data to return
    @return: C{n} bytes of random data.
    @rtype: str
    i   t    (   t   xranget   randomt	   randrangeR   t   mapt   chr(   t   nt
   randomData(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   _stub_urandom2   s    
(c         C   s   |  j  d  S(   s   
    ASCII-armor for random data.  This uses a hex encoding, although we will
    prefer url-safe base64 encoding for features in this module if it is
    available.
    t   hex(   t   encode(   t   s(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   _stub_armor@   s    t   islinkt   urandomt   urlsafe_b64encodet   InsecurePathc           B   s   e  Z d  Z RS(   sM   
    Error that is raised when the path provided to FilePath is invalid.
    (   t   __name__t
   __module__t   __doc__(    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR)   L   s   t	   LinkErrorc           B   s   e  Z d  Z RS(   s   
    An error with symlinks - either that there are cyclical symlinks or that
    symlink are not supported on this platform.
    (   R*   R+   R,   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR-   S   s   t   UnlistableErrorc           B   s   e  Z d  Z d   Z RS(   s  
    An exception which is used to distinguish between errors which mean 'this
    is not a directory you can list' and other, more catastrophic errors.

    This error will try to look as much like the original error as possible,
    while still being catchable as an independent type.

    @ivar originalException: the actual original exception instance, either an
    L{OSError} or a L{WindowsError}.
    c         C   s    |  j  j | j   | |  _ d S(   sq   
        Create an UnlistableError exception.

        @param originalException: an instance of OSError.
        N(   t   __dict__t   updatet   originalException(   t   selfR1   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   __init__f   s    (   R*   R+   R,   R3   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR.   [   s   
t   _WindowsUnlistableErrorc           B   s   e  Z d  Z RS(   s*  
    This exception is raised on Windows, for compatibility with previous
    releases of FilePath where unportable programs may have done "except
    WindowsError:" around a call to children().

    It is private because all application code may portably catch
    L{UnlistableError} instead.
    (   R*   R+   R,   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR4   q   s   c           C   s    t  t t d   j    d  S(   sQ   
    Create a pseudorandom, 16-character string for use in secure filenames.
    i@   i   (   t   armorR   t   randomBytest   digest(    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   _secureEnoughString}   s    t   _PathHelperc           B   st   e  Z d  Z d   Z d   Z d   Z d d  Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z RS(   s]   
    Abstract helper class also used by ZipPath; implements certain utility
    methods.
    c         C   s,   |  j    } z | j   SWd  | j   Xd  S(   N(   t   opent   readt   close(   R2   t   fp(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt
   getContent   s    c         c   s@   |  } | j    } x' | | k r; | V| } | j    } q Wd S(   s   
        @return: an iterator of all the ancestors of this path, from the most
        recent (its immediate parent) to the root of its filesystem.
        N(   t   parent(   R2   R   R?   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   parents   s    c         C   s   y |  j    } Wn t k
 rd } t | d | j  } | t t t t f k rU   n  t |   n@ t	 k
 r } | j t j
 t j f k r   n  t |   n Xt |  j |  S(   s  
        List the children of this path object.

        @raise OSError: If an error occurs while listing the directory.  If the
        error is 'serious', meaning that the operation failed due to an access
        violation, exhaustion of some kind of resource (file descriptors or
        memory), OSError or a platform-specific variant will be raised.

        @raise UnlistableError: If the inability to list the directory is due
        to this path not existing or not being a directory, the more specific
        OSError subclass L{UnlistableError} is raised instead.

        @return: an iterable of all currently-existing children of this object
        accessible with L{_PathHelper.child}.
        t   winerror(   R	   R   t   getattrt   errnoR   R   R   R   R4   t   OSErrort   ENOENTt   ENOTDIRR.   R   t   child(   R2   t   subnamest	   winErrObjRA   t   ose(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   children   s    c         c   s   |  V|  j    r x |  j   D] } | d k s< | |  r x` | j |  D]G } t j j |  j  j t j j | j   r t d   n  | VqL Wq | Vq Wn  d S(   s  
        Yield myself, then each of my children, and each of those children's
        children in turn.  The optional argument C{descend} is a predicate that
        takes a FilePath, and determines whether or not that FilePath is
        traversed/descended into.  It will be called with each path for which
        C{isdir} returns C{True}.  If C{descend} is not specified, all
        directories will be traversed (including symbolic links which refer to
        directories).

        @param descend: A one-argument callable that will return True for
            FilePaths that should be traversed, False otherwise.

        @return: a generator yielding FilePath-like objects.
        s   Cycle in file graph.N(	   t   isdirRK   t   Nonet   walkt   osR   t   realpatht
   startswithR-   (   R2   t   descendt   ct   subc(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyRN      s    c         C   s   |  j    j |  S(   N(   R?   RG   (   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   sibling   s    c         C   s*   |  } x | D] } | j  |  } q W| S(   sM  
        Retrieve a child or child's child of this path.

        @param segments: A sequence of path segments as C{str} instances.

        @return: A L{FilePath} constructed by looking up the C{segments[0]}
            child of this path, the C{segments[1]} child of that path, and so
            on.

        @since: 10.2
        (   RG   (   R2   t   segmentsR   t   name(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt
   descendant   s    c         C   s   |  } | j    } g  } xD | | k r^ | | k r^ | j   g | d d +| } | j    } q W| | k ru | ru | St d | |  f   d S(   s  
        Return a list of segments between a child and its ancestor.

        For example, in the case of a path X representing /a/b/c/d and a path Y
        representing /a/b, C{Y.segmentsFrom(X)} will return C{['c',
        'd']}.

        @param ancestor: an instance of the same class as self, ostensibly an
        ancestor of self.

        @raise: ValueError if the 'ancestor' parameter is not actually an
        ancestor, i.e. a path for /x/y/z is passed as an ancestor for /a/b/c/d.

        @return: a list of strs
        i    s   %r not parent of %rN(   R?   R   t
   ValueError(   R2   t   ancestort   ft   pRV   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   segmentsFrom  s    c         C   s   t  |  j |  j f  S(   sO   
        Hash the same as another FilePath with the same path as mine.
        (   t   hasht	   __class__R   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   __hash__.  s    c         C   s   t  |  j    S(   s?   
        Deprecated.  Use getModificationTime instead.
        (   t   intt   getModificationTime(   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   getmtime6  s    c         C   s   t  |  j    S(   s9   
        Deprecated.  Use getAccessTime instead.
        (   Ra   t   getAccessTime(   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   getatime=  s    c         C   s   t  |  j    S(   s?   
        Deprecated.  Use getStatusChangeTime instead.
        (   Ra   t   getStatusChangeTime(   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   getctimeD  s    N(   R*   R+   R,   R>   R@   RK   RM   RN   RU   RX   R]   R`   Rc   Re   Rg   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR9      s   			9			 			t   FilePathc           B   s  e  Z d  Z d3 Z d3 Z e d  Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d   Z d	   Z d
 d  Z e 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% d    Z& d!   Z' d"   Z( d#   Z) d$   Z* d%   Z+ d&   Z, d' d(  Z- d)   Z. d*   Z/ d+ d,  Z0 d-   Z1 d. d/  Z2 d0 d0 d4 Z3 e d1  Z4 e d2  Z5 RS(5   s  
    I am a path on the filesystem that only permits 'downwards' access.

    Instantiate me with a pathname (for example,
    FilePath('/home/myuser/public_html')) and I will attempt to only provide
    access to files which reside inside that path.  I may be a path to a file,
    a directory, or a file which does not exist.

    The correct way to use me is to instantiate me, and then do ALL filesystem
    access through me.  In other words, do not import the 'os' module; if you
    need to open a file, call my 'open' method.  If you need to list a
    directory, call my 'path' method.

    Even if you pass me a relative path, I will convert that to an absolute
    path internally.

    Note: although time-related methods do return floating-point results, they
    may still be only second resolution depending on the platform and the last
    value passed to L{os.stat_float_times}.  If you want greater-than-second
    precision, call C{os.stat_float_times(True)}, or use Python 2.5.
    Greater-than-second precision is only available in Windows on Python2.5 and
    later.

    @type alwaysCreate: C{bool}
    @ivar alwaysCreate: When opening this file, only succeed if the file does
        not already exist.

    @type path: C{str}
    @ivar path: The path from which 'downward' traversal is permitted.

    @ivar statinfo: The currently cached status information about the file on
        the filesystem that this L{FilePath} points to.  This attribute is
        C{None} if the file is in an indeterminate state (either this
        L{FilePath} has not yet had cause to call C{stat()} yet or
        L{FilePath.changed} indicated that new information is required), 0 if
        C{stat()} was called and returned an error (i.e. the path did not exist
        when C{stat()} was called), or a C{stat_result} object that describes
        the last known status of the underlying file (or directory, as the case
        may be).  Trust me when I tell you that you do not want to use this
        attribute.  Instead, use the methods on L{FilePath} which give you
        information about it, like C{getsize()}, C{isdir()},
        C{getModificationTime()}, and so on.
    @type statinfo: C{int} or L{types.NoneType} or L{os.stat_result}
    c         C   s   t  |  |  _ | |  _ d  S(   N(   R   R   t   alwaysCreate(   R2   R   Ri   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR3   }  s    c         C   s,   |  j  j   } | j d  r( | d =n  | S(   Nt   statinfo(   R/   t   copyt   has_key(   R2   t   d(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   __getstate__  s    
c         C   s   t  j   r1 | j d  r1 t d | f   n  t |  } t | k r_ t d | f   n  t t |  j |   } | j	 |  j  s t d | |  j f   n  |  j
 |  S(   Nt   :s   %r contains a colon.s,   %r contains one or more directory separatorss   %r is not a child of %s(   R   t	   isWindowst   countR)   R   t   slashR   t   joinpathR   RQ   t	   clonePath(   R2   R   t   normt   newpath(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyRG     s    c         C   sY   t  t |  j t |    } | j |  j  sL t d | |  j f   n  |  j |  S(   s   
        Use me if `path' might have slashes in it, but you know they're safe.

        (NOT slashes at the beginning. It still needs to be a _child_).
        s   %s is not a child of %s(   R   Rs   R   R   RQ   R)   Rt   (   R2   R   Rv   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   preauthChild  s    c         G   sF   |  j  } x6 | D]. } t | |  } t |  r |  j |  Sq Wd S(   s<  Return my first existing child with a name in 'paths'.

        paths is expected to be a list of *pre-secured* path fragments; in most
        cases this will be specified by a system administrator and not an
        arbitrary user.

        If no appropriately-named children exist, this will return None.
        N(   R   Rs   R   Rt   (   R2   t   pathsR\   RG   t   jp(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   childSearchPreauth  s
    		c         G   s   |  j  } x | D] } | r- |  j   r- |  S| d k r t |  d } xH t t |   D]1 } | j |  r\ |  j t t |  |   Sq\ Wn  | | } t |  r |  j |  Sq Wd S(   s  Attempt to return a path with my name, given multiple possible
        extensions.

        Each extension in exts will be tested and the first path which exists
        will be returned.  If no path exists, None will be returned.  If '' is
        in exts, then if the file referred to by this path exists, 'self' will
        be returned.

        The extension '*' has a magic meaning, which means "any path that
        begins with self.path+'.' is acceptable".
        t   *t   .N(   R   R   R   R	   R   RQ   Rt   Rs   (   R2   t   extsR\   t   extt   basedott   fnt   p2(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   siblingExtensionSearch  s    	#
c         C   sP   |  j    rL t j j |  j  } | |  j k r? t d   n  |  j |  S|  S(   s  
        Returns the absolute target as a FilePath if self is a link, self
        otherwise.  The absolute link is the ultimate file or directory the
        link refers to (for instance, if the link refers to another link, and
        another...).  If the filesystem does not support symlinks, or
        if the link is cyclical, raises a LinkError.

        Behaves like L{os.path.realpath} in that it does not resolve link
        names in the middle (ex. /x/y/z, y is a link to w - realpath on z
        will return /x/y/z, not /x/w/z).

        @return: FilePath of the target path
        @raises LinkError: if links are not supported or links are cyclical.
        s!   Cyclical link - will loop forever(   R&   RO   R   RP   R-   Rt   (   R2   t   result(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyRP     s    c         C   s   |  j  |  j |  S(   N(   Rt   R   (   R2   R~   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   siblingExtension  s    c         C   s   t  j |  j | j  d S(   s  
        Creates a symlink to self to at the path in the L{FilePath}
        C{linkFilePath}.  Only works on posix systems due to its dependence on
        C{os.symlink}.  Propagates C{OSError}s up from C{os.symlink} if
        C{linkFilePath.parent()} does not exist, or C{linkFilePath} already
        exists.

        @param linkFilePath: a FilePath representing the link to be created
        @type linkFilePath: L{FilePath}
        N(   RO   t   symlinkR   (   R2   t   linkFilePath(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   linkTo  s    t   rc         C   sN   |  j  r( d | k s t d  |  j   S| j d d  } t |  j | d  S(   s  
        Open this file using C{mode} or for writing if C{alwaysCreate} is
        C{True}.

        In all cases the file is opened in binary mode, so it is not necessary
        to include C{b} in C{mode}.

        @param mode: The mode to open the file in.  Default is C{r}.
        @type mode: C{str}
        @raises AssertionError: If C{a} is included in the mode and
            C{alwaysCreate} is C{True}.
        @rtype: C{file}
        @return: An open C{file} object.
        t   as1   Appending not supported when alwaysCreate == Truet   bR   (   Ri   t   AssertionErrort   createt   replaceR:   R   (   R2   t   mode(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR:     s
    	
c         C   sC   y t  |  j  |  _ Wn& t k
 r> d |  _ | r?   q? n Xd S(   s]  
        Re-calculate cached effects of 'stat'.  To refresh information on this path
        after you know the filesystem may have changed, call this method.

        @param reraise: a boolean.  If true, re-raise exceptions from
        L{os.stat}; otherwise, mark this path as not existing, and remove any
        cached stat information.
        i    N(   R   R   Rj   RD   (   R2   t   reraise(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   restat  s    		c         C   s   d |  _ d S(   sl   
        Clear any cached information about the state of this path on disk.

        @since: 10.1.0
        N(   RM   Rj   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   changed  s    c         C   s   t  j |  j |  d S(   s   
        Changes the permissions on self, if possible.  Propagates errors from
        C{os.chmod} up.

        @param mode: integer representing the new permissions desired (same as
            the command line chmod)
        @type mode: C{int}
        N(   RO   t   chmodR   (   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR   %  s    	c         C   s,   |  j  } | s% |  j   |  j  } n  | j S(   N(   Rj   R   t   st_size(   R2   t   st(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   getsize1  s
    	
c         C   s2   |  j  } | s% |  j   |  j  } n  t | j  S(   s   
        Retrieve the time of last access from this file.

        @return: a number of seconds from the epoch.
        @rtype: float
        (   Rj   R   t   floatt   st_mtime(   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyRb   9  s
    	
c         C   s2   |  j  } | s% |  j   |  j  } n  t | j  S(   s   
        Retrieve the time of the last status change for this file.

        @return: a number of seconds from the epoch.
        @rtype: float
        (   Rj   R   R   t   st_ctime(   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyRf   G  s
    	
c         C   s2   |  j  } | s% |  j   |  j  } n  t | j  S(   s   
        Retrieve the time that this file was last accessed.

        @return: a number of seconds from the epoch.
        @rtype: float
        (   Rj   R   R   t   st_atime(   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyRd   U  s
    	
c         C   sG   t  j   r t  n  |  j } | s: |  j   |  j } n  t | j  S(   s  
        Retrieve the file serial number, also called inode number, which 
        distinguishes this file from all other files on the same device.

        @raise: NotImplementedError if the platform is Windows, since the
                inode number would be a dummy value for all files in Windows
        @return: a number representing the file serial number
        @rtype: C{long}
        @since: 11.0
        (   R   Rp   t   NotImplementedErrorRj   R   t   longt   st_ino(   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   getInodeNumberc  s    		
c         C   sG   t  j   r t  n  |  j } | s: |  j   |  j } n  t | j  S(   s  
        Retrieves the device containing the file.  The inode number and device
        number together uniquely identify the file, but the device number is
        not necessarily consistent across reboots or system crashes.

        @raise: NotImplementedError if the platform is Windows, since the
                device number would be 0 for all partitions on a Windows
                platform
        @return: a number representing the device
        @rtype: C{long}
        @since: 11.0
        (   R   Rp   R   Rj   R   R   t   st_dev(   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt	   getDevicex  s    		
c         C   sG   t  j   r t  n  |  j } | s: |  j   |  j } n  t | j  S(   s  
        Retrieves the number of hard links to the file.  This count keeps
        track of how many directories have entries for this file.  If the
        count is ever decremented to zero then the file itself is discarded
        as soon as no process still holds it open.  Symbolic links are not
        counted in the total.

        @raise: NotImplementedError if the platform is Windows, since Windows
                doesn't maintain a link count for directories, and os.stat
                does not set st_nlink on Windows anyway.
        @return: the number of hard links to the file
        @rtype: C{int}
        @since: 11.0
        (   R   Rp   R   Rj   R   Ra   t   st_nlink(   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   getNumberOfHardLinks  s    		
c         C   sG   t  j   r t  n  |  j } | s: |  j   |  j } n  t | j  S(   s  
        Returns the user ID of the file's owner.

        @raise: NotImplementedError if the platform is Windows, since the UID
                is always 0 on Windows
        @return: the user ID of the file's owner
        @rtype: C{int}
        @since: 11.0
        (   R   Rp   R   Rj   R   Ra   t   st_uid(   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt	   getUserID  s    
		
c         C   sG   t  j   r t  n  |  j } | s: |  j   |  j } n  t | j  S(   s   
        Returns the group ID of the file.

        @raise: NotImplementedError if the platform is Windows, since the GID
                is always 0 on windows
        @return: the group ID of the file
        @rtype: C{int}
        @since: 11.0
        (   R   Rp   R   Rj   R   Ra   t   st_gid(   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt
   getGroupID  s    
		
c         C   s/   |  j  r t S|  j t  |  j  r' t St Sd S(   s   
        Check if the C{path} exists.

        @return: C{True} if the stats of C{path} can be retrieved successfully,
            C{False} in the other cases.
        @rtype: C{bool}
        N(   Rj   t   TrueR   R   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR     s    		c         C   s?   |  j  } | s2 |  j t  |  j  } | s2 t Sn  t | j  S(   N(   Rj   R   R   R   t   st_mode(   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyRL     s    		c         C   s?   |  j  } | s2 |  j t  |  j  } | s2 t Sn  t | j  S(   N(   Rj   R   R   R   R   (   R2   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   isfile  s    		c         C   s   t  |  j  S(   N(   R&   R   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR&     s    c         C   s   t  |  j  S(   N(   R    R   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR      s    c         C   s   t  |  j  S(   N(   R	   R   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR	     s    c         C   s   t  |  j  S(   N(   R   R   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR     s    c         C   s   d |  j  f S(   Ns   FilePath(%r)(   R   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   __repr__  s    c         C   s?   y |  j  d  j   Wn t k
 r* n Xt |  j d   d  S(   NR   (   R:   R<   t   IOErrorR
   R   RM   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   touch  s
    c         C   sk   |  j    rM |  j   rM x |  j   D] } | j   q& Wt j |  j  n t j |  j  |  j   d S(   s   
        Removes the file or directory that is represented by self.  If
        C{self.path} is a directory, recursively remove all its children
        before removing the directory.  If it's a file or link, just delete
        it.
        N(   RL   R&   RK   t   removeRO   t   rmdirR   R   (   R2   RG   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR     s    c         C   s   t  j |  j  S(   sl   
        Create all directories not yet existing in C{path} segments, using
        C{os.makedirs}.
        (   RO   t   makedirsR   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR     s    c         C   s]   d d l  } |  j d d k r, |  j | pA t j |  j | g  } t |  j | j  |   S(   s   
        Assuming I am representing a directory, return a list of
        FilePaths representing my children that match the given
        pattern.
        iNt   /(   t   globR   Rr   R   R   Rt   (   R2   t   patternR   R   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   globChildren&  s    8c         C   s   t  |  j  S(   N(   R   R   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR   0  s    c         C   s   t  |  j  S(   N(   R   R   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR   3  s    c         C   s   |  j  |  j    S(   N(   Rt   R   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR?   6  s    s   .newc         C   s   |  j  |  } | j d  } z | j |  Wd | j   Xt j   rk t |  j  rk t j	 |  j  n  t j
 | j |  j  d S(   s  
        Replace the file at this path with a new file that contains the given
        bytes, trying to avoid data-loss in the meanwhile.

        On UNIX-like platforms, this method does its best to ensure that by the
        time this method returns, either the old contents I{or} the new contents
        of the file will be present at this path for subsequent readers
        regardless of premature device removal, program crash, or power loss,
        making the following assumptions:

            - your filesystem is journaled (i.e. your filesystem will not
              I{itself} lose data due to power loss)

            - your filesystem's C{rename()} is atomic

            - your filesystem will not discard new data while preserving new
              metadata (see U{http://mjg59.livejournal.com/108257.html} for more
              detail)

        On most versions of Windows there is no atomic C{rename()} (see
        U{http://bit.ly/win32-overwrite} for more information), so this method
        is slightly less helpful.  There is a small window where the file at
        this path may be deleted before the new file is moved to replace it:
        however, the new file will be fully written and flushed beforehand so in
        the unlikely event that there is a crash at that point, it should be
        possible for the user to manually recover the new version of their data.
        In the future, Twisted will support atomic file moves on those versions
        of Windows which I{do} support them: see U{Twisted ticket
        3004<http://twistedmatrix.com/trac/ticket/3004>}.

        This method should be safe for use by multiple concurrent processes, but
        note that it is not easy to predict which process's contents will
        ultimately end up on disk if they invoke this method at close to the
        same time.

        @param content: The desired contents of the file at this path.

        @type content: L{str}

        @param ext: An extension to append to the temporary filename used to
            store the bytes while they are being written.  This can be used to
            make sure that temporary files can be identified by their suffix,
            for cleanup in case of crashes.

        @type ext: C{str}
        t   wN(   t   temporarySiblingR:   t   writeR<   R   Rp   R   R   RO   t   unlinkt   rename(   R2   t   contentR~   t   sibR[   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt
   setContent:  s    /c         C   s&   t  | t  s t St |  j | j  S(   N(   t
   isinstanceRh   t   NotImplementedt   cmpR   (   R2   t   other(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   __cmp__v  s    c         C   s   t  j |  j  d  S(   N(   RO   t   mkdirR   (   R2   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   createDirectory{  s    i   c         C   s   | |  _  d  S(   N(   Ri   (   R2   t   val(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   requireCreate~  s    c         C   s%   t  j |  j t  } t  j | d  S(   sO   Exclusively create a file, only if this file previously did not exist.
        s   w+b(   RO   R:   R   t   _CREATE_FLAGSt   fdopen(   R2   t   fdint(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR     s    R   c         C   s.   |  j  t   |  j   |  } | j   | S(   s  
        Construct a path referring to a sibling of this path.

        The resulting path will be unpredictable, so that other subprocesses
        should neither accidentally attempt to refer to the same path before it
        is created, nor they should other processes be able to guess its name in
        advance.

        @param extension: A suffix to append to the created filename.  (Note
            that if you want an extension with a '.' you must include the '.'
            yourself.)

        @type extension: C{str}

        @return: a path object with the given extension suffix, C{alwaysCreate}
            set to True.

        @rtype: L{FilePath}
        (   RU   R8   R   R   (   R2   t	   extensionR   (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR     s     
i   c         C   s6  |  j    r6 | r6 t j t j |  j  | j  d S|  j   r | j   s[ | j   n  x |  j   D]+ } | j	 | j
    } | j | |  qh Wn |  j   r&| j d  } z` |  j   } zB x; | j |  j  } | j |  t |  |  j k  r Pq q Wd | j   XWd | j   Xn t d   d S(   s  
        Copies self to destination.

        If self is a directory, this method copies its children (but not
        itself) recursively to destination - if destination does not exist as a
        directory, this method creates it.  If destination is a file, an
        IOError will be raised.

        If self is a file, this method copies it to destination.  If
        destination is a file, this method overwrites it.  If destination is a
        directory, an IOError will be raised.

        If self is a link (and followLinks is False), self will be copied
        over as a new symlink with the same target as returned by os.readlink.
        That means that if it is absolute, both the old and new symlink will
        link to the same thing.  If it's relative, then perhaps not (and
        it's also possible that this relative link will be broken).

        File/directory permissions and ownership will NOT be copied over.

        If followLinks is True, symlinks are followed so that they're treated
        as their targets.  In other words, if self is a link, the link's target
        will be copied.  If destination is a link, self will be copied to the
        destination's target (the actual destination will be destination's
        target).  Symlinks under self (if self is a directory) will be
        followed and its target's children be copied recursively.

        If followLinks is False, symlinks will be copied over as symlinks.

        @param destination: the destination (a FilePath) to which self
            should be copied
        @param followLinks: whether symlinks in self should be treated as links
            or as their targets
        NR   s/   Only copying of files and directories supported(   R&   RO   R   t   readlinkR   RL   R   R   RK   RG   R   t   copyToR   R:   R;   t
   _chunkSizeR   t   lenR<   R   (   R2   t   destinationt   followLinksRG   t	   destChildt	   writefilet   readfilet   chunk(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR     s.    #c         C   s   y t  j |  j | j  Wn} t k
 r } | j t j k r | j   } |  j | |  | j | |  |  j   } |  j | |  | j	   q   n X|  j
   | j
   d S(   s  
        Move self to destination - basically renaming self to whatever
        destination is named.  If destination is an already-existing directory,
        moves all children to destination if destination is empty.  If
        destination is a non-empty directory, or destination is a file, an
        OSError will be raised.

        If moving between filesystems, self needs to be copied, and everything
        that applies to copyTo applies to moveTo.

        @param destination: the destination (a FilePath) to which self
            should be copied
        @param followLinks: whether symlinks in self should be treated as links
            or as their targets (only applicable when moving between
            filesystems)
        N(   RO   R   R   RD   RC   t   EXDEVR   R   t   moveToR   R   (   R2   R   R   RJ   t   secsibt   mysecsib(    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyR     s    	
Ni   (6   R*   R+   R,   RM   Rj   R   R   R3   Rn   RG   Rw   Rz   R   RP   R   R   R:   R   R   R   R   R   Rb   Rf   Rd   R   R   R   R   R   R   RL   R   R&   R    R	   R   R   R   R   R   R   R   R   R?   R   R   R   R   R   R   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyRh   L  sb   ,																																		
			<			L(7   R,   RO   RC   R   t   base64t   os.pathR    R   R   R   R   R   R   R   Rs   R   Rr   R	   R
   R   R   R   t   twisted.python.runtimeR   t   twisted.python.hashlibR   t   twisted.python.win32R   R   R   R   R   R   t   O_EXCLt   O_CREATt   O_RDWRR   R   R!   R%   RB   R   R&   R6   R5   t	   ExceptionR)   R-   RD   R.   R4   R8   R9   Rh   Rt   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/python/filepath.pyt   <module>   sB   (				  