3 ig"@sdZddlZddlZddlZddlZddlZddlZddlmZm Z m Z ddlm Z ddl m Z ddlmZmZmZmZddlmZejeZeeZyddlZee7ZWnek rejdYnXyddlZee7ZWnek rejd YnXed 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)returncCstjd}tj||S)zBGet the current umask which involves having to set it temporarily.r)osumask)maskrs  r ) directorytargetr cCs0tjj|}tjj|}tjj||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%cCstj|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 chmodr)rrrr2set_extracted_file_to_default_mode_plus_executableXsr()infor cCs$|jd?}t|o tj|o |d@S)Nr&) external_attrboolstatS_ISREG)r)moderrrzip_item_is_executable`s r0T)filenamelocationflattenr c Cst|t|d}ztj|dd}t|jo0|}x|jD]}|j}|}|rZt|d}t j j ||}t j j |} t ||sd} t| j||||jds|jdrt|qd}n8|jjtrRd}n$|jjdrfd}ntjd|d }tj||d d }zt d d |j D}xr|j D]d}|j }|rt |d}t jj||}t||sd}t|j||||jr t|q|jr`y|j||Wn8tk r\} ztjd||j | wWYdd} ~ XnXqy|j|} Wn<ttfk r} ztjd||j | wWYdd} ~ XnXtt jj|| dk stt|d} tj| | WdQRX| j|j|||j d@rt!|qWWd|jXdS)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)rF).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: %sNr6r&)"r lowerr?rr loggerwarningtarfiler7r getmembersrFrr rr<r%rr>isdirissym_extract_member Exception extractfileKeyErrorAttributeErrorr=AssertionErrorr@rArButimer/r() r1r2r/tarrErPrGrrIexcrJrKrrr untar_filesl         rb)r1r2 content_typer cCstjj|}|dks,|jjts,tj|rDt|||jd dnR|dkslt j |sl|jjt t t rxt||ntjd|||td|dS)Nzapplication/zipz.whl)r3zapplication/x-gzipzZCannot unpack file %s (downloaded from %s, content-type: %s); cannot detect archive formatz#Cannot determine archive format of )r rrealpathrRr?r r8 is_zipfilerLrU is_tarfilerrr rbrScriticalr)r1r2rcrrr unpack_files    rh)T)N))__doc__loggingr r@r-rUr8ZtypingrrrrZpip._internal.exceptionsrZpip._internal.utils.filetypesrrr r Zpip._internal.utils.miscr getLogger__name__rSSUPPORTED_EXTENSIONSbz2 ImportErrordebuglzmaintrstrrr,r r%r(r0rLrbrhrrrrsB        .T