Ñò
mÈKc           @   s,  d  Z  d d k Z d d k Z d d k Z d d k l Z d d k Z d d d d d d	 d
 d d d g
 Z d e f d „  ƒ  YZ	 y e
 Wn e j
 o d Z
 n Xd d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d d „ Z e d d „ Z d „  Z d „  Z d „  Z d S(   s‰   Utility functions for copying files and directory trees.

XXX The functions here don't copy the resource fork or other metadata on Mac.

iÿÿÿÿN(   t   abspatht   copyfileobjt   copyfilet   copymodet   copystatt   copyt   copy2t   copytreet   movet   rmtreet   Errorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.6/shutil.pyR
      s   i   i   c         C   s2   x+ |  i  | ƒ } | p Pn | i | ƒ q d S(   s=   copy data from file-like object fsrc to file-like object fdstN(   t   readt   write(   t   fsrct   fdstt   lengtht   buf(    (    s   /usr/lib/python2.6/shutil.pyR      s
    c         C   s   t  t i d ƒ o2 y t i i |  | ƒ SWqE t j
 o t SXn t i i t i i |  ƒ ƒ t i i t i i | ƒ ƒ j S(   Nt   samefile(   t   hasattrt   ost   pathR   t   OSErrort   Falset   normcaseR    (   t   srct   dst(    (    s   /usr/lib/python2.6/shutil.pyt	   _samefile    s    
c         C   s”   t  |  | ƒ o t d |  | f ‚ n d } d } z/ t |  d ƒ } t | d ƒ } t | | ƒ Wd | o | i ƒ  n | o | i ƒ  n Xd S(   s   Copy data from src to dsts   `%s` and `%s` are the same filet   rbt   wbN(   R   R
   t   Nonet   openR   t   close(   R   R   R   R   (    (    s   /usr/lib/python2.6/shutil.pyR   ,   s    c         C   sI   t  t d ƒ o5 t i |  ƒ } t i | i ƒ } t i | | ƒ n d S(   s   Copy mode bits from src to dstt   chmodN(   R   R   t   statt   S_IMODEt   st_modeR"   (   R   R   t   stt   mode(    (    s   /usr/lib/python2.6/shutil.pyR   =   s    c         C   s°   t  i |  ƒ } t i | i ƒ } t t  d ƒ o  t  i | | i | i f ƒ n t t  d ƒ o t  i | | ƒ n t t  d ƒ o' t | d ƒ o t  i	 | | i
 ƒ n d S(   sC   Copy all stat info (mode bits, atime, mtime, flags) from src to dstt   utimeR"   t   chflagst   st_flagsN(   R   R#   R$   R%   R   R(   t   st_atimet   st_mtimeR"   R)   R*   (   R   R   R&   R'   (    (    s   /usr/lib/python2.6/shutil.pyR   D   s      c         C   sV   t  i i | ƒ o% t  i i | t  i i |  ƒ ƒ } n t |  | ƒ t |  | ƒ d S(   sV   Copy data and mode bits ("cp src dst").

    The destination may be a directory.

    N(   R   R   t   isdirt   joint   basenameR   R   (   R   R   (    (    s   /usr/lib/python2.6/shutil.pyR   P   s    %c         C   sV   t  i i | ƒ o% t  i i | t  i i |  ƒ ƒ } n t |  | ƒ t |  | ƒ d S(   s]   Copy data and all stat info ("cp -p src dst").

    The destination may be a directory.

    N(   R   R   R-   R.   R/   R   R   (   R   R   (    (    s   /usr/lib/python2.6/shutil.pyR   [   s    %c             s   ‡  f d †  } | S(   s   Function that can be used as copytree() ignore parameter.

    Patterns is a sequence of glob-style patterns
    that are used to exclude filesc            s:   g  } x' ˆ  D] } | i  t i | | ƒ ƒ q Wt | ƒ S(   N(   t   extendt   fnmatcht   filtert   set(   R   t   namest   ignored_namest   pattern(   t   patterns(    s   /usr/lib/python2.6/shutil.pyt   _ignore_patternsk   s
     (    (   R7   R8   (    (   R7   s   /usr/lib/python2.6/shutil.pyt   ignore_patternsf   s    c      	   C   sõ  t  i |  ƒ } | d j	 o | |  | ƒ } n
 t ƒ  } t  i | ƒ g  } x)| D]!} | | j o qR n t  i i |  | ƒ } t  i i | | ƒ }	 yx | o6 t  i i | ƒ o# t  i | ƒ }
 t  i	 |
 |	 ƒ n8 t  i i
 | ƒ o t | |	 | | ƒ n t | |	 ƒ WqR t t  i f j
 o% } | i | |	 t | ƒ f ƒ qR t j
 o } | i | i d ƒ qR XqR Wy t |  | ƒ WnR t j
 oF } t d j	 o t | t ƒ o qÝ| i |  | t | ƒ f ƒ n X| o t | ‚ n d S(   sÇ  Recursively copy a directory tree using copy2().

    The destination directory must not already exist.
    If exception(s) occur, an Error is raised with a list of reasons.

    If the optional symlinks flag is true, symbolic links in the
    source tree result in symbolic links in the destination tree; if
    it is false, the contents of the files pointed to by symbolic
    links are copied.

    The optional ignore argument is a callable. If given, it
    is called with the `src` parameter, which is the directory
    being visited by copytree(), and `names` which is the list of
    `src` contents, as returned by os.listdir():

        callable(src, names) -> ignored_names

    Since copytree() is called recursively, the callable will be
    called once for each directory that is copied. It returns a
    list of names relative to the `src` directory that should
    not be copied.

    XXX Consider this example code rather than the ultimate tool.

    i    N(   R   t   listdirR   R3   t   makedirsR   R.   t   islinkt   readlinkt   symlinkR-   R   R   t   IOErrort   errort   appendt   strR
   R0   t   argsR   R   t   WindowsErrort
   isinstance(   R   R   t   symlinkst   ignoreR4   R5   t   errorst   namet   srcnamet   dstnamet   linktot   whyt   err(    (    s   /usr/lib/python2.6/shutil.pyR   r   s>    	  !c         C   sà  | o d „  } n | d j o d „  } n y' t i i |  ƒ o t d ƒ ‚ n Wn0 t j
 o$ | t i i |  t i ƒ  ƒ d SXg  } y t i |  ƒ } Wn1 t i j
 o" } | t i |  t i ƒ  ƒ n XxÁ | D]¹ } t i i	 |  | ƒ } y t i
 | ƒ i } Wn t i j
 o d } n Xt i | ƒ o t | | | ƒ qÜ y t i | ƒ WqÜ t i j
 o" } | t i | t i ƒ  ƒ qÜ XqÜ Wy t i |  ƒ Wn/ t i j
 o  | t i |  t i ƒ  ƒ n Xd S(   sÁ  Recursively delete a directory tree.

    If ignore_errors is set, errors are ignored; otherwise, if onerror
    is set, it is called to handle the error with arguments (func,
    path, exc_info) where func is os.listdir, os.remove, or os.rmdir;
    path is the argument to that function that caused it to fail; and
    exc_info is a tuple returned by sys.exc_info().  If ignore_errors
    is false and onerror is None, an exception is raised.

    c          W   s   d  S(   N(    (   RC   (    (    s   /usr/lib/python2.6/shutil.pyt   onerror¿   s    c          W   s   ‚  d  S(   N(    (   RC   (    (    s   /usr/lib/python2.6/shutil.pyRO   Â   s    s%   Cannot call rmtree on a symbolic linkNi    (   R   R   R   R<   R   t   syst   exc_infoR:   R@   R.   t   lstatR%   R#   t   S_ISDIRR	   t   removet   rmdir(   R   t   ignore_errorsRO   R4   RN   RI   t   fullnameR'   (    (    s   /usr/lib/python2.6/shutil.pyR	   ³   s@     "c         C   s   t  i i |  i t  i i ƒ ƒ S(   N(   R   R   R/   t   rstript   sep(   R   (    (    s   /usr/lib/python2.6/shutil.pyt	   _basenameä   s    c         C   sÿ   | } t  i i | ƒ oC t  i i | t |  ƒ ƒ } t  i i | ƒ o t d | ‚ q\ n y t  i |  | ƒ Wnˆ t j
 o| t  i i |  ƒ oH t	 |  | ƒ o t d |  | f ‚ n t
 |  | d t ƒt |  ƒ qû t |  | ƒ t  i |  ƒ n Xd S(   s“  Recursively move a file or directory to another location. This is
    similar to the Unix "mv" command.

    If the destination is a directory or a symlink to a directory, the source
    is moved inside the directory. The destination path must not already
    exist.

    If the destination already exists but is not a directory, it may be
    overwritten depending on os.rename() semantics.

    If the destination is on our current filesystem, then rename() is used.
    Otherwise, src is copied to the destination and then removed.
    A lot more could be done here...  A look at a mv.c shows a lot of
    the issues this implementation glosses over.

    s$   Destination path '%s' already existss.   Cannot move a directory '%s' into itself '%s'.RF   N(   R   R   R-   R.   RZ   t   existsR
   t   renameR   t	   destinsrcR   t   TrueR	   R   t   unlink(   R   R   t   real_dst(    (    s   /usr/lib/python2.6/shutil.pyR   é   s    c         C   sy   t  |  ƒ }  t  | ƒ } |  i t i i ƒ p |  t i i 7}  n | i t i i ƒ p | t i i 7} n | i |  ƒ S(   N(   R    t   endswithR   R   RY   t
   startswith(   R   R   (    (    s   /usr/lib/python2.6/shutil.pyR]     s    i @  (   t   __doc__R   RP   R#   t   os.pathR    R1   t   __all__t   EnvironmentErrorR
   RD   t	   NameErrorR   R   R   R   R   R   R   R   R9   R   R   R	   RZ   R   R]   (    (    (    s   /usr/lib/python2.6/shutil.pyt   <module>   s2   							A1		"