;
Κβ"Ic               @   s*  d  Z  d d l Z d d l Z d d l Z d d l m Z d d l Z d d d d d d	 d
 d d d g
 Z Gd   d e  Z	 y e
 Wn e k
 o d Z
 Yn Xd d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d d  Z d d d  Z d   Z d   Z d   Z d S(    u   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(   u   abspathu   copyfileobju   copyfileu   copymodeu   copystatu   copyu   copy2u   copytreeu   moveu   rmtreeu   Errorc             B   s   |  Ee  Z d  S(   N(   u   __name__u
   __module__(   u
   __locals__(    (    u#   /mit/python/lib/python3.0/shutil.pyu   Error   s   
i   i   c             C   s2   x+ |  j  |  } | p Pn | j |  q d S(   u=   copy data from file-like object fsrc to file-like object fdstN(   u   readu   write(   u   fsrcu   fdstu   lengthu   buf(    (    u#   /mit/python/lib/python3.0/shutil.pyu   copyfileobj   s
    c          
   C   s   t  t j d  o6 y t j j |  |  SWqI t k
 o d SYqI Xn t j j t j j |    t j j t j j |   k S(   Nu   samefileF(   u   hasattru   osu   pathu   samefileu   OSErroru   Falseu   normcaseu   abspath(   u   srcu   dst(    (    u#   /mit/python/lib/python3.0/shutil.pyu	   _samefile    s    c          	   C   s   t  |  |  o t d |  | f   n d } d } z/ t |  d  } t | d  } t | |  Wd | o | j   n | o | j   n Xd S(   u   Copy data from src to dstu   `%s` and `%s` are the same fileu   rbu   wbN(   u	   _samefileu   Erroru   Noneu   openu   copyfileobju   close(   u   srcu   dstu   fsrcu   fdst(    (    u#   /mit/python/lib/python3.0/shutil.pyu   copyfile,   s    c             C   sI   t  t d  o5 t j |   } t j | j  } t j | |  n d S(   u   Copy mode bits from src to dstu   chmodN(   u   hasattru   osu   statu   S_IMODEu   st_modeu   chmod(   u   srcu   dstu   stu   mode(    (    u#   /mit/python/lib/python3.0/shutil.pyu   copymode=   s    c             C   s°   t  j |   } t j | j  } t t  d  o  t  j | | j | j f  n t t  d  o t  j | |  n t t  d  o' t | d  o t  j	 | | j
  n d S(   uC   Copy all stat info (mode bits, atime, mtime, flags) from src to dstu   utimeu   chmodu   chflagsu   st_flagsN(   u   osu   statu   S_IMODEu   st_modeu   hasattru   utimeu   st_atimeu   st_mtimeu   chmodu   chflagsu   st_flags(   u   srcu   dstu   stu   mode(    (    u#   /mit/python/lib/python3.0/shutil.pyu   copystatD   s      c             C   sV   t  j j |  o% t  j j | t  j j |    } n t |  |  t |  |  d S(   uV   Copy data and mode bits ("cp src dst").

    The destination may be a directory.

    N(   u   osu   pathu   isdiru   joinu   basenameu   copyfileu   copymode(   u   srcu   dst(    (    u#   /mit/python/lib/python3.0/shutil.pyu   copyP   s    %c             C   sV   t  j j |  o% t  j j | t  j j |    } n t |  |  t |  |  d S(   u]   Copy data and all stat info ("cp -p src dst").

    The destination may be a directory.

    N(   u   osu   pathu   isdiru   joinu   basenameu   copyfileu   copystat(   u   srcu   dst(    (    u#   /mit/python/lib/python3.0/shutil.pyu   copy2[   s    %c                 s     f d   } | S(   u   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] } | j  t j | |   q Wt |  S(   N(   u   extendu   fnmatchu   filteru   set(   u   pathu   namesu   ignored_namesu   pattern(   u   patterns(    u#   /mit/python/lib/python3.0/shutil.pyu   _ignore_patternsk   s
     (    (   u   patternsu   _ignore_patterns(    (   u   patternsu#   /mit/python/lib/python3.0/shutil.pyu   ignore_patternsf   s    c             C   s.  t  j |   } | d k	 o | |  |  } n
 t   } t  j |  g  } xM| D]E} | | k o qR n t  j j |  |  } t  j j | |  }	 yx | o6 t  j j |  o# t  j |  }
 t  j	 |
 |	  n8 t  j j
 |  o t | |	 | |  n t | |	  WqR t t  j f k
 o7 } z! | j | |	 t |  f  WYd d } ~ XqR t k
 o/ } z | j | j d  WYd d } ~ XqR XqR Wy t |  |  Wnd t k
 oX } zB t d k	 o t | t  o n | j |  | t |  f  WYd d } ~ Xn X| o t |   n d S(   uΗ  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.

    Ni    (   u   osu   listdiru   Noneu   setu   makedirsu   pathu   joinu   islinku   readlinku   symlinku   isdiru   copytreeu   copy2u   IOErroru   erroru   appendu   stru   Erroru   extendu   argsu   copystatu   OSErroru   WindowsErroru
   isinstance(   u   srcu   dstu   symlinksu   ignoreu   namesu   ignored_namesu   errorsu   nameu   srcnameu   dstnameu   linktou   whyu   err(    (    u#   /mit/python/lib/python3.0/shutil.pyu   copytreer   s>    	 /,0c          #   C   s
  | o d   } n | d k o d   } n y' t j j |   o t d   n Wn4 t k
 o( | t j j |  t j    d SYn Xg  } y t j |   } WnC t j k
 o4 } z | t j |  t j    WYd d } ~ Xn XxΤ | D]Μ } t j j	 |  |  } y t j
 |  j } Wn t j k
 o d } Yn Xt j |  o t | | |  qς y t j |  Wqς t j k
 o4 } z | t j | t j    WYd d } ~ Xqς Xqς Wy t j |   Wn0 t j k
 o! | t j |  t j    Yn Xd S(   uΑ  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(    (   u   args(    (    u#   /mit/python/lib/python3.0/shutil.pyu   onerrorΏ   s    c              W   s     d  S(   N(    (   u   args(    (    u#   /mit/python/lib/python3.0/shutil.pyu   onerrorΒ   s    u%   Cannot call rmtree on a symbolic linkNi    (   u   Noneu   osu   pathu   islinku   OSErroru   sysu   exc_infou   listdiru   erroru   joinu   lstatu   st_modeu   statu   S_ISDIRu   rmtreeu   removeu   rmdir(   u   pathu   ignore_errorsu   onerroru   namesu   erru   nameu   fullnameu   mode(    (    u#   /mit/python/lib/python3.0/shutil.pyu   rmtree³   s@    
- 1c             C   s   t  j j |  j t  j j   S(   N(   u   osu   pathu   basenameu   rstripu   sep(   u   path(    (    u#   /mit/python/lib/python3.0/shutil.pyu	   _basenameδ   s    c          	   C   s  | } t  j j |  oF t  j j | t |    } t  j j |  o t d |   q_ n y t  j |  |  Wn t k
 o t  j j |   oK t	 |  |  o t d |  | f   n t
 |  | d d t |   n t |  |  t  j |   Yn Xd S(   u  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.

    u$   Destination path '%s' already existsu.   Cannot move a directory '%s' into itself '%s'.u   symlinksNT(   u   osu   pathu   isdiru   joinu	   _basenameu   existsu   Erroru   renameu   OSErroru	   destinsrcu   copytreeu   Trueu   rmtreeu   copy2u   unlink(   u   srcu   dstu   real_dst(    (    u#   /mit/python/lib/python3.0/shutil.pyu   moveι   s    c             C   s   t  |  j t  |    S(   N(   u   abspathu
   startswith(   u   srcu   dst(    (    u#   /mit/python/lib/python3.0/shutil.pyu	   destinsrc  s    i @  F(   u   __doc__u   osu   sysu   statu   os.pathu   abspathu   fnmatchu   __all__u   EnvironmentErroru   Erroru   WindowsErroru	   NameErroru   Noneu   copyfileobju	   _samefileu   copyfileu   copymodeu   copystatu   copyu   copy2u   ignore_patternsu   Falseu   copytreeu   rmtreeu	   _basenameu   moveu	   destinsrc(    (    (    u#   /mit/python/lib/python3.0/shutil.pyu   <module>   s2   							A1		"