o g" @sdZddlZddlZddlZddlZddlZddlZddlmZm Z m Z ddlm Z ddl m Z ddlmZmZmZmZddlmZeeZeeZz ddlZee7ZWneycedYnwz ddlZee7ZWney|ed Ynwd efd d Zd ed e efddZ deed e!fddZ"deded e!fddZ#d ed dfddZ$de d e!fddZ%d'dedede!d dfd d!Z&deded dfd"d#Z' d(deded$e ed dfd%d&Z(dS))zUtilities related archives. N)IterableListOptional)ZipInfo)InstallationError)BZ2_EXTENSIONSTAR_EXTENSIONS XZ_EXTENSIONSZIP_EXTENSIONS) ensure_dirzbz2 module is not availablezlzma module is not availablereturncCstd}t||S)zBGet the current umask which involves having to set it temporarily.r)osumask)maskr?/usr/lib/python3/dist-packages/pip/_internal/utils/unpacking.py current_umask+s  rpathcCsd|dd}d|vr$d|vr|d|dksd|vr$|ddSd|vr.|ddS|dgS)N/\)lstripfindsplitrrrrsplit_leading_dir2s$  rpathscCsDd}|D]}t|\}}|sdS|dur|}q||krdSqdS)zyReturns true if all the paths have the same leading path name (i.e., everything is in one subdirectory in an archive)NFT)r)r common_prefixrprefixrestrrrhas_leading_dir>s r! directorytargetcCs0tj|}tj|}tj||g}||kS)zL Return true if the absolute path of target is within the directory )r rabspath commonprefix)r"r# abs_directory abs_targetrrrris_within_directoryMs  r(cCst|dt@dBdS)zx Make file present at path have execute for user/group/world (chmod +x) is no-op on windows per python docs iIN)r chmodrrrrr2set_extracted_file_to_default_mode_plus_executableXsr+infocCs$|jd?}t|ot|o|d@S)Nr)) external_attrboolstatS_ISREG)r,moderrrzip_item_is_executable`s r3Tfilenamelocationflattenc CsJt|t|d}ztj|dd}t|o|}|D]{}|j}|}|r,t|d}t j ||}t j |} t ||sId} t| ||||dsS|drXt|qt| ||} z)t|d} t| | Wd n1sxwYW| t|rt|q| t|rt|wwW|d S|w) a Unzip the file (with path `filename`) to the destination `location`. All files are written based on system defaults and umask (i.e. permissions are not preserved), except that regular file members with any execute permissions (user, group, or world) have "chmod +x" applied after being written. Note that for windows, any execute changes using os.chmod are no-ops per the python docs. rbT) allowZip64rzQThe zip file ({}) has a file ({}) trying to install outside target directory ({})rrwbN)r openzipfileZipFiler!namelistinfolistr4rr rjoindirnamer(rformatendswithshutil copyfileobjcloser3r+) r4r5r6zipfpzipleadingr,namefndirmessagefpdestfprrr unzip_filegsF         rOc Cs.t||ds|drd}n&|trd}n|tr)d}n|dr3d}ntd|d }tj||d d }zt d d | D}| D]}|j }|r`t |d}t j||}t||swd}t|||||rt|qS|rz|||WqSty} ztd||j | WYd} ~ qSd} ~ wwz||} Wnttfy} ztd||j | WYd} ~ qSd} ~ wwtt j|| dusJt|d} t| | Wdn1swY| ||||jd@r t |qSW|dS|w)a Untar the file (with path `filename`) to the destination `location`. All files are written based on system defaults and umask (i.e. permissions are not preserved), except that regular file members with any execute permissions (user, group, or world) have "chmod +x" applied after being written. Note that for windows, any execute changes using os.chmod are no-ops per the python docs. z.gzz.tgzzr:gzzr:bz2zr:xzz.tarrz-Cannot determine compression type for file %szr:*zutf-8)encodingcSsg|]}|jqSr)rI).0memberrrr szuntar_file..rzQThe tar file ({}) has a file ({}) trying to install outside target directory ({})z/In the tar file %s the member %s is invalid: %sNr9r))!r lowerrBrr loggerwarningtarfiler:r! getmembersrIrr rr?r(rrAisdirissym_extract_member Exception extractfileKeyErrorAttributeErrorr@rCrDrEutimer2r+) r4r5r2tarrHrSrJrrLexcrMrNrrr untar_files            3rd content_typecCstj|}|dks|tst|r#t|||d ddS|dks7t |s7|t t t r>t||dStd|||td|)Nzapplication/zipz.whl)r6zapplication/x-gzipzZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz#Cannot determine archive format of )r rrealpathrUrBr r; is_zipfilerOrX is_tarfilerrr rdrVcriticalr)r4r5rerrr unpack_files(  rj)T)N))__doc__loggingr rCr0rXr;typingrrrrpip._internal.exceptionsrpip._internal.utils.filetypesrrr r pip._internal.utils.miscr getLogger__name__rVSUPPORTED_EXTENSIONSbz2 ImportErrordebuglzmaintrstrrr/r!r(r+r3rOrdrjrrrrsX          .T