a [f#@sdZddlZddlZddlZddlZddlZddlZddlmZm Z m Z ddlm Z ddl m Z ddlmZmZmZmZddlmZeeZeeZzddlZee7ZWneyedYn0zddlZee7ZWneyed Yn0ed d d Zee ed ddZ eee!dddZ"eee!dddZ#edd ddZ$e e!dddZ%d%eee!ddddZ&eeddd d!Z'd&eee edd"d#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 available)returncCstd}t||S)zBGet the current umask which involves having to set it temporarily.r)osumask)maskrA/usr/lib/python3.9/site-packages/pip/_internal/utils/unpacking.py current_umask+s  r)pathr cCsh|dd}d|vrHd|vr4|d|dkss r ) directorytargetr cCs0tj|}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()infor cCs$|jd?}t|o t|o |d@S)Nr&)Z external_attrboolstatS_ISREG)r)moderrrzip_item_is_executable`s r/T)filenamelocationflattenr c CsRt|t|d}z.tj|dd}t|o2|}|D]}|j}|}|rZt|d}t j ||}t j |} t ||sd} t| ||||ds|drt|qd}n8|trRd}n$|drfd}ntd|d }tj||d d }zt d d | D}| D]}|j }|rt |d}t j||}t||sd}t||||zt|j|d|Wntjy Yn0|r6t|q|rz|||WnDty} z*td||j | WYd} ~ qWYd} ~ n d} ~ 00qz||} WnHttfy} z*td||j | WYd} ~ qWYd} ~ n d} ~ 00tt j|| dusJt|d} t| | Wdn1s<0Y| |!|||j"d@rt#|qW| n | 0dS)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|] }|jqSrrB).0memberrrr zuntar_file..rzQThe tar file ({}) has a file ({}) trying to install outside target directory ({})rKz/In the tar file %s the member %s is invalid: %sNr4r&)$r lowerr<rr loggerZwarningtarfiler5r Z getmembersrBrr rr9r%rr;Z data_filterreplaceZLinkOutsideDestinationErrorisdirZissymZ_extract_member ExceptionZ extractfileKeyErrorAttributeErrorr:r=r>r?utimer.r() r0r1r.tarrArMrCrrEexcrFrGrrr untar_files|      $" ,   r[)r0r1 content_typer cCstj|}|dks,|ts,t|rDt|||d dnR|dkslt |sl|t t t rxt||ntd|||td|dS)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 rrealpathrPr<r r6 is_zipfilerHrRZ is_tarfilerrr r[rQZcriticalr)r0r1r\rrr unpack_files,   r_)T)N))__doc__Zloggingr r=r,rRr6typingrrrrZpip._internal.exceptionsrZpip._internal.utils.filetypesrrr r Zpip._internal.utils.miscr Z getLogger__name__rQZSUPPORTED_EXTENSIONSbz2 ImportErrordebuglzmaintrstrrr+r r%r(r/rHr[r_rrrrsL          .[