o Ec" @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)maskrP/opt/alt/python310/lib/python3.10/site-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)rZ 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"Z abs_directoryZ 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&)Z external_attrboolstatS_ISREG)r)moderrrzip_item_is_executable`s r/Tfilenamelocationflattenc 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)Z allowZip64rzQThe zip file ({}) has a file ({}) trying to install outside target directory ({})rrwbN)r openzipfileZZipFiler ZnamelistZinfolistr0rr rjoindirnamer%rformatendswithshutil copyfileobjcloser/r() r0r1r2Zzipfpzipleadingr)namefndirmessagefpdestfprrr unzip_filegsF         rFc 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|t|d} t| | Wdn1swY| ||||jd@rt |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)r@).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: %sNr4r&)!r lowerr:rr loggerZwarningtarfiler5r Z getmembersr@rr rr7r%rr9isdirZissymZ_extract_member ExceptionZ extractfileKeyErrorAttributeErrorr8r;r<r=utimer.r() r0r1r.Ztarr?rJrArrCexcrDrErrr untar_files           3rU content_typecCstj|}|dks|tst|r#t|||d ddS|dks7t |s7|t t t r>t||dStd|||td|)Nzapplication/zipz.whl)r2zapplication/x-gzipzZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz#Cannot determine archive format of )r rrealpathrLr:r r6Z is_zipfilerFrNZ is_tarfilerrr rUrMZcriticalr)r0r1rVrrr unpack_files,  rX)T)N))__doc__Zloggingr r;r,rNr6typingrrrrZpip._internal.exceptionsrZpip._internal.utils.filetypesrrr r Zpip._internal.utils.miscr Z getLogger__name__rMZSUPPORTED_EXTENSIONSbz2 ImportErrordebugZlzmaintrstrrr+r r%r(r/rFrUrXrrrrsX          .T