Ñò
#8Zc           @   s8  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 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 t |  d ƒ i i ƒ  } zF | ~ } t | d ƒ i i ƒ  } z | ~ } t | | ƒ Wd QXWd QXd S(   s   Copy data from src to dsts   `%s` and `%s` are the same filet   rbt   wbN(   R   R
   t   opent   __exit__t	   __enter__R   (   R   R   t   _[1]R   t   _[2]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   6   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 ƒ on t | d ƒ o^ y t  i	 | | i
 ƒ Wqó t j
 o4 } t t d ƒ p | i t i j o ‚  qï qó Xn d S(   sC   Copy all stat info (mode bits, atime, mtime, flags) from src to dstt   utimeR$   t   chflagst   st_flagst
   EOPNOTSUPPN(   R   R%   R&   R'   R   R*   t   st_atimet   st_mtimeR$   R+   R,   R   t   errnoR-   (   R   R   R(   R)   t   why(    (    s   /usr/lib/python2.6/shutil.pyR   =   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   L   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   R2   R3   R4   R   R   (   R   R   (    (    s   /usr/lib/python2.6/shutil.pyR   W   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_patternsg   s
     (    (   R<   R=   (    (   R<   s   /usr/lib/python2.6/shutil.pyt   ignore_patternsb   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   listdirt   NoneR8   t   makedirsR   R3   t   islinkt   readlinkt   symlinkR2   R   R   t   IOErrort   errort   appendt   strR
   R5   t   argsR   R   t   WindowsErrort
   isinstance(   R   R   t   symlinkst   ignoreR9   R:   t   errorst   namet   srcnamet   dstnamet   linktoR1   t   err(    (    s   /usr/lib/python2.6/shutil.pyR   n   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(    (   RI   (    (    s   /usr/lib/python2.6/shutil.pyt   onerror»   s    c          W   s   ‚  d  S(   N(    (   RI   (    (    s   /usr/lib/python2.6/shutil.pyRT   ¾   s    s%   Cannot call rmtree on a symbolic linkNi    (   R@   R   R   RB   R   t   syst   exc_infoR?   RF   R3   t   lstatR'   R%   t   S_ISDIRR	   t   removet   rmdir(   R   t   ignore_errorsRT   R9   RS   RO   t   fullnameR)   (    (    s   /usr/lib/python2.6/shutil.pyR	   ¯   s@     "c         C   s   t  i i |  i t  i i ƒ ƒ S(   N(   R   R   R4   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'.RL   N(   R   R   R2   R3   R_   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   R^   t
   startswith(   R   R   (    (    s   /usr/lib/python2.6/shutil.pyRb     s    i @  (   t   __doc__R   RU   R%   t   os.pathR    R6   R0   t   __all__t   EnvironmentErrorR
   RJ   t	   NameErrorR@   R   R   R   R   R   R   R   R>   R   R   R	   R_   R   Rb   (    (    (    s   /usr/lib/python2.6/shutil.pyt   <module>   s4   								A1		"