ž 7’Re2dc-@sƒdZddlZddlZddlZddlmZddlZddlZddlZddl m Z yddl Z dcZ Wnek ržddZ YnXyddlmZWnek rÍdZYnXyddlmZWnek rüdZYnXdd d d d d dddddddddddddddgZGdd„deƒZGdd„deƒZGdd„deƒZGd d!„d!eƒZGd"d#„d#eƒZyeWnek rÒdZYnXded&d„Zd'd(„Z d)d „Z!d*d „Z"d+d „Z#d,d „Z$d-d „Z%d.d„Z&ddde%ddd/d„Z'dddd0d„Z(d1d2„Z)d3d„Z*d4d5„Z+d6d7„Z,d8d9„Z-d:dddddd;d<„Z.ddddd=d>„Z/dddd?d@„Z0ie.dfgdBfdC6e.dggdEfdF6e.dhgdGfdH6e0gdIfdJ6Z1e rOe.digdEfe1dFdddbd„Z?dS(ju—Utility functions for copying and archiving files and directory trees. XXX The functions here don't copy the resource fork or other metadata on Mac. iN(uabspathi(utarfile(ugetpwnam(ugetgrnamu copyfileobjucopyfileucopymodeucopystatucopyucopy2ucopytreeumoveurmtreeuErroruSpecialFileErroru ExecErroru make_archiveuget_archive_formatsuregister_archive_formatuunregister_archive_formatuget_unpack_formatsuregister_unpack_formatuunregister_unpack_formatuunpack_archiveuignore_patternscBs|EeZdZdS(uErrorN(u__name__u __module__u __qualname__(u __locals__((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyuError,scBs|EeZdZdZdS(uSpecialFileErroru|Raised when trying to do a kind of operation (e.g. copying) which is not supported on a special file (e.g. a named pipe)N(u__name__u __module__u __qualname__u__doc__(u __locals__((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyuSpecialFileError/scBs|EeZdZdZdS(u ExecErroru+Raised when a command could not be executedN(u__name__u __module__u __qualname__u__doc__(u __locals__((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu ExecError3scBs|EeZdZdZdS(u ReadErroru%Raised when an archive cannot be readN(u__name__u __module__u __qualname__u__doc__(u __locals__((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu ReadError6su ReadErrorcBs|EeZdZdZdS(u RegistryErroruXRaised when a registery operation with the archiving and unpacking registeries failsN(u__name__u __module__u __qualname__u__doc__(u __locals__((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu RegistryError9su RegistryErroriicCs0x)|j|ƒ}|sPn|j|ƒqdS(u=copy data from file-like object fsrc to file-like object fdstN(ureaduwrite(ufsrcufdstulengthubuf((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu copyfileobjCs c CsttjdƒrEytjj||ƒSWqEtk rAdSYqEXntjjtjj|ƒƒtjjtjj|ƒƒkS(NusamefileF(uhasattruosupathusamefileuOSErroruFalseunormcaseuabspath(usrcudst((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu _samefileKs  u _samefilecCsÍt||ƒr(td||fƒ‚nxa||gD]S}ytj|ƒ}Wntk rbYq5Xtj|jƒr5td|ƒ‚q5q5Wt|dƒ,}t|dƒ}t ||ƒWdQXWdQXdS(uCopy data from src to dstu`%s` and `%s` are the same fileu`%s` is a named pipeurbuwbN( u _samefileuErroruosustatuOSErroruS_ISFIFOust_modeuSpecialFileErroruopenu copyfileobj(usrcudstufnustufsrcufdst((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyucopyfileWs cCsGttdƒrCtj|ƒ}tj|jƒ}tj||ƒndS(uCopy mode bits from src to dstuchmodN(uhasattruosustatuS_IMODEust_modeuchmod(usrcudstustumode((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyucopymodekscCsýtj|ƒ}tj|jƒ}ttdƒrOtj||j|jfƒnttdƒrqtj||ƒnttdƒrùt|dƒrùytj ||j ƒWqùt k rõ}z-tt dƒ sÝ|j t j krã‚nWYdd}~XqùXndS(uCCopy all stat info (mode bits, atime, mtime, flags) from src to dstuutimeuchmoduchflagsust_flagsu EOPNOTSUPPN(uosustatuS_IMODEust_modeuhasattruutimeust_atimeust_mtimeuchmoduchflagsust_flagsuOSErroruerrnou EOPNOTSUPP(usrcudstustumodeuwhy((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyucopystatrscCsTtjj|ƒr6tjj|tjj|ƒƒ}nt||ƒt||ƒdS(uVCopy data and mode bits ("cp src dst"). The destination may be a directory. N(uosupathuisdirujoinubasenameucopyfileucopymode(usrcudst((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyucopy‚s$ cCsTtjj|ƒr6tjj|tjj|ƒƒ}nt||ƒt||ƒdS(u]Copy data and all stat info ("cp -p src dst"). The destination may be a directory. N(uosupathuisdirujoinubasenameucopyfileucopystat(usrcudst((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyucopy2s$ cs‡fdd†}|S(uFunction that can be used as copytree() ignore parameter. Patterns is a sequence of glob-style patterns that are used to exclude filescs:g}x'ˆD]}|jtj||ƒƒq Wt|ƒS(N(uextendufnmatchufilteruset(upathunamesu ignored_namesupattern(upatterns(u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu_ignore_patternss u)ignore_patterns.._ignore_patterns((upatternsu_ignore_patterns((upatternsu=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyuignore_patterns˜scCsCtj|ƒ}|dk r-|||ƒ}n tƒ}tj|ƒg}xk|D]c} | |krhqPntjj|| ƒ} tjj|| ƒ} y¥tjj| ƒrþtj| ƒ} |rÏtj | | ƒq6tjj | ƒ rî|rîwPn|| | ƒn8tjj | ƒr)t | | |||ƒn || | ƒWqPt k rr} z|j| jdƒWYdd} ~ XqPtk r²}z!|j| | t|ƒfƒWYdd}~XqPXqPWyt||ƒWn_tk r)}z?tdk rût|tƒrûn|j||t|ƒfƒWYdd}~XnX|r?t |ƒ‚ndS(uüRecursively copy a directory tree. 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. If the file pointed by the symlink doesn't exist, an exception will be added in the list of errors raised in an Error exception at the end of the copy process. You can set the optional ignore_dangling_symlinks flag to true if you want to silence this exception. Notice that this has no effect on platforms that don't support os.symlink. 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. The optional copy_function argument is a callable that will be used to copy each file. It will be called with the source path and the destination path as arguments. By default, copy2() is used, but any function that supports the same signature (like copy()) can be used. iN(uosulistdiruNoneusetumakedirsupathujoinuislinkureadlinkusymlinkuexistsuisdirucopytreeuErroruextenduargsuEnvironmentErroruappendustrucopystatuOSErroru WindowsErroru isinstance(usrcudstusymlinksuignoreu copy_functionuignore_dangling_symlinksunamesu ignored_namesuerrorsunameusrcnameudstnameulinktouerruwhy((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyucopytree¤sD$     &3/c$CsØ|rdd„}n|dkr0dd„}ny%tjj|ƒrTtdƒ‚nWn2tk r‰|tjj|tjƒƒdSYnXg}ytj|ƒ}Wn.tjk rÓ|tj|tjƒƒYnXx»|D]³}tjj ||ƒ}ytj |ƒj }Wntjk r)d}YnXt j |ƒrLt|||ƒqÛytj|ƒWqÛtjk r|tj|tjƒƒYqÛXqÛWytj|ƒWn.tjk rÓ|tj|tjƒƒYnXdS(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. cWsdS(N((uargs((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyuonerrorsurmtree..onerrorcWs‚dS(N((uargs((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyuonerrorsu%Cannot call rmtree on a symbolic linkNi(uNoneuosupathuislinkuOSErrorusysuexc_infoulistdiruerrorujoinulstatust_modeustatuS_ISDIRurmtreeuremoveurmdir(upathu ignore_errorsuonerrorunamesunameufullnameumode((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyurmtreeös>      "cCstjj|jtjjƒƒS(N(uosupathubasenameurstripusep(upath((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu _basename'su _basenamec Cs|}tjj|ƒr~t||ƒr;tj||ƒdStjj|t|ƒƒ}tjj|ƒr~td|ƒ‚q~nytj||ƒWn†t k rtjj|ƒrüt ||ƒrÜtd||fƒ‚nt ||ddƒt |ƒnt||ƒtj|ƒYnXdS(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. Nu$Destination path '%s' already existsu.Cannot move a directory '%s' into itself '%s'.usymlinksT(uosupathuisdiru _samefileurenameujoinu _basenameuexistsuErroruOSErroru _destinsrcucopytreeuTrueurmtreeucopy2uunlink(usrcudstureal_dst((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyumove,s$   cCsut|ƒ}t|ƒ}|jtjjƒs@|tjj7}n|jtjjƒsh|tjj7}n|j|ƒS(N(uabspathuendswithuosupathusepu startswith(usrcudst((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu _destinsrcTs  u _destinsrcc Cs_tdks|dkrdSyt|ƒ}Wntk rFd}YnX|dk r[|dSdS(u"Returns a gid, given a group name.iN(ugetgrnamuNoneuKeyError(unameuresult((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu_get_gid]s   u_get_gidc Cs_tdks|dkrdSyt|ƒ}Wntk rFd}YnX|dk r[|dSdS(u"Returns an uid, given a user name.iN(ugetpwnamuNoneuKeyError(unameuresult((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu_get_uidis   u_get_uidugzipc sidd6dd6}idd6} tr>d|d._set_uid_giduw|%sufilterN(uNoneu_BZ2_SUPPORTEDu ValueErroruformatugetuosupathudirnameuexistsuinfoumakedirsu_get_uidu_get_gidutarfileuopenuadduclose(u base_nameubase_dirucompressuverboseudry_runuownerugroupuloggerutar_compressionu compress_extu archive_nameu archive_diru _set_uid_gidutar((ugidugroupuowneruuidu=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu _make_tarballus4         u _make_tarballc Cs~|rd}nd}ddlm}ddlm}y |d|||gd|ƒWn"|k rytdƒ|‚YnXdS( Nu-ru-rqi(uDistutilsExecError(uspawnuzipudry_runukunable to create zip file '%s': could neither import the 'zipfile' module nor find a standalone zip utility(udistutils.errorsuDistutilsExecErrorudistutils.spawnuspawnu ExecError(ubase_diru zip_filenameuverboseudry_runu zipoptionsuDistutilsExecErroruspawn((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu_call_external_zip³s    u_call_external_zipcCs |d}tjj|ƒ}tjj|ƒsf|dk rM|jd|ƒn|sftj|ƒqfnyddl}Wntk rd}YnX|dkr³t ||||ƒné|dk rÕ|jd||ƒn|sœ|j |dd|j ƒ}x–tj |ƒD]…\} } } xs| D]k} tjj tjj| | ƒƒ} tjj| ƒr|j| | ƒ|dk r‡|jd| ƒq‡qqWqW|jƒn|S( umCreate a zip file from all the files under 'base_dir'. The output zip file will be named 'base_name' + ".zip". Uses either the "zipfile" Python module (if available) or the InfoZIP "zip" utility (if installed and found on the default search path). If neither tool is available, raises ExecError. Returns the name of the output zip file. u.zipu creating %siNu#creating '%s' and adding '%s' to ituwu compressionu adding '%s'(uosupathudirnameuexistsuNoneuinfoumakedirsuzipfileu ImportErroru_call_external_zipuZipFileu ZIP_DEFLATEDuwalkunormpathujoinuisfileuwriteuclose(u base_nameubase_diruverboseudry_runuloggeru zip_filenameu archive_diruzipfileuzipudirpathudirnamesu filenamesunameupath((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu _make_zipfileÄs8          !  u _make_zipfileucompressugzip'ed tar-fileugztarubzip2ubzip2'ed tar-fileubztaruuncompressed tar fileutaruZIP fileuzipcCs'dd„tjƒDƒ}|jƒ|S(u‘Returns a list of supported formats for archiving and unarchiving. Each element of the returned sequence is a tuple (name, description) cSs&g|]\}}||df‘qS(i((u.0unameuregistry((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyu s u'get_archive_formats..(u_ARCHIVE_FORMATSuitemsusort(uformats((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyuget_archive_formatsþs  ucCs½|dkrg}nt|tjƒs:td|ƒ‚nt|ttfƒs^tdƒ‚nxE|D]=}t|ttfƒ s“t|ƒdkretdƒ‚qeqeW|||ft|]s u&get_unpack_formats..(u_UNPACK_FORMATSuitemsusort(uformats((u=/tmp/pip-zej_zi-build/pip/_vendor/distlib/_backport/shutil.pyuget_unpack_formatsWs  c Cs§i}x9tjƒD]+\}}x|dD]}||| s¬                     Q1  ( =/    6    %