a
    e0hz                     @   s  d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z
ddlZddlZddlZddlZddlmZ ddlmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZmZm Z m!Z!m"Z" ddl#m$Z$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+m,Z, ddl-m.Z. ddl/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z;m<Z<m=Z= ddl>m?Z?m@Z@ e8sddl7mAZA nddlBmCZC ddlDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmAZA ddlmSZS ddlTmUZU ddl-mVZV ddl/mWZW eLde"ZXeQeXeYeReZeYf f Z[G dd deNZ\e]e^Z_dJd d!Z`d"d# Zad$d% Zbd&d' Zcd(d) Zdd*d+ Zed,d- Zfd.d/ ZgdKd0d1Zhd2d3 Zid4d5 Zjd6d7 ZkG d8d9 d9elZmG d:d; d;elZnG d<d= d=e'Zod>d? ZpG d@dA dAeZqdLdDdEZrejsdFdG ZtdMdHdIZudS )NzGSupport for installing and building the "wheel" binary package format.
    )absolute_importN)urlsafe_b64encode)chainstarmap)ZipFile)pkg_resources)ScriptMaker)get_export_entry)PY2
ensure_strensure_text
itervaluesreraise	text_type)filterfalsemap)InstallationError)get_major_minor_version)DIRECT_URL_METADATA_NAME	DirectUrl)SCHEME_KEYS)adjacent_tmp_filereplace)captured_stdout
ensure_dir	hash_file	partition)MYPY_CHECK_RUNNING)current_umaskis_within_directory2set_extracted_file_to_default_mode_plus_executablezip_item_is_executable)parse_wheel$pkg_resources_distribution_for_wheel)cast)Message)IOAnyCallableDictIterableIteratorListNewTypeOptionalProtocolSequenceSetTupleUnionr$   )ZipInfo)Distribution)Scheme)NamedTemporaryFileResult
RecordPathc                   @   s    e Zd ZdZdZdZdd ZdS )FileNc                 C   s   d S N selfr;   r;   T/var/www/auris/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.pysaveQ   s    z	File.save)__name__
__module____qualname__src_record_path	dest_pathchangedr?   r;   r;   r;   r>   r9   L   s   r9      c                 C   s6   t | |\}}dt| dd }|t|fS )z?Return (encoded_digest, length) for path using hashlib.sha256()zsha256=latin1=)r   r   digestdecoderstripstr)path	blocksizehlengthrI   r;   r;   r>   rehashY   s    rQ   c                 C   s"   t rdd| iS | dddS dS )zPReturn keyword arguments to properly open a CSV file
    in the given mode.
    modez{}b utf-8)rR   newlineencodingN)r
   format)rR   r;   r;   r>   csv_io_kwargsd   s    rX   c                 C   s   t j| sJ t| d^}| }|ds>W d   dS tjt	 }d| t j
d }| }W d   n1 s~0    Y  t| d$}|| || W d   n1 s0    Y  dS )	zQReplace #!python with #!/path/to/python
    Return True if file was changed.
    rbs   #!pythonNFs   #!asciiwbT)osrM   isfileopenreadline
startswithsys
executableencodegetfilesystemencodinglinesepreadwrite)rM   script	firstlineexenamerestr;   r;   r>   
fix_scripto   s    
&
(rl   c                 C   s   |  dd dkS )NzRoot-Is-PurelibrS   true)getlower)metadatar;   r;   r>   wheel_root_is_purelib   s    rq   c                    sx   z|  d}|  d}W n ty2   i i f Y S 0 dd  t fdd| D }t fdd| D }||fS )Nconsole_scriptsgui_scriptsc                 S   s&   t | ddd}|d |d fS )z[get the string representation of EntryPoint,
        remove space and split on '='
         rS   rH   r      )rL   r   split)ssplit_partsr;   r;   r>   	_split_ep   s    z"get_entrypoints.<locals>._split_epc                 3   s   | ]} |V  qd S r:   r;   .0vry   r;   r>   	<genexpr>       z"get_entrypoints.<locals>.<genexpr>c                 3   s   | ]} |V  qd S r:   r;   rz   r}   r;   r>   r~      r   )get_entry_mapKeyErrordictvalues)distributionconsoleguir;   r}   r>   get_entrypoints   s    
	r   c                    s  | sdS t t}| D ]*}tj|}tj|}|| | qdd tj	dd
tjD   tjtjtj  fdd| D }|sdS g }| D ]b\}}t|}t|dkrd	|d
 }	n$dd|dd d |d  }	|d|	| qd}
t|dkr0||
d n||
d tdd tj	dd
tjD }|rxd}|| d|S )zDetermine if any scripts are not on PATH and format a warning.
    Returns a warning message if one or more scripts are not on PATH,
    otherwise None.
    Nc                 S   s    g | ]}t j|t jqS r;   )r\   rM   normcaserK   sepr{   ir;   r;   r>   
<listcomp>   s   z5message_about_scripts_not_on_PATH.<locals>.<listcomp>PATHrS   c                    s&   i | ]\}}t j| vr||qS r;   )r\   rM   r   )r{   
parent_dirscriptsnot_warn_dirsr;   r>   
<dictcomp>   s   z5message_about_scripts_not_on_PATH.<locals>.<dictcomp>ru   zscript {} isr   zscripts {} are, z and z.The {} installed in '{}' which is not on PATH.zeConsider adding {} to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.zthis directoryzthese directoriesc                 s   s   | ]}|r|d  dkV  qdS )r   ~Nr;   r   r;   r;   r>   r~      s   z4message_about_scripts_not_on_PATH.<locals>.<genexpr>ziNOTE: The current PATH contains path(s) starting with `~`, which may not be expanded by all applications.
)collectionsdefaultdictsetr\   rM   dirnamebasenameaddenvironrn   rv   pathsepappendr   ra   rb   itemssortedlenrW   joinany)r   grouped_by_dirdestfiler   script_namewarn_for	msg_linesdir_scriptssorted_scripts
start_textlast_line_fmtwarn_for_tildetilde_warning_msgr;   r   r>   !message_about_scripts_not_on_PATH   sT    


r   c                 C   s   t dd | D S )a  Normalize the given rows of a RECORD file.

    Items in each row are converted into str. Rows are then sorted to make
    the value more predictable for tests.

    Each row is a 3-tuple (path, hash, size) and corresponds to a record of
    a RECORD file (see PEP 376 and PEP 427 for details).  For the rows
    passed to this function, the size can be an integer as an int or string,
    or the empty string.
    c                 s   s*   | ]"\}}}t |d d|t|fV  qdS )rT   rV   N)r   rL   )r{   record_pathhash_sizer;   r;   r>   r~      s   z&_normalized_outrows.<locals>.<genexpr>)r   )outrowsr;   r;   r>   _normalized_outrows   s    r   c                 C   s   | S r:   r;   )r   r;   r;   r>   _record_to_fs_path  s    r   c                 C   sX   |d ur>t j| d  t j|d  kr>t j| |} | t jjd} td| S )Nr   /r8   )r\   rM   
splitdrivero   relpathr   r   r$   )rM   relative_tor;   r;   r>   _fs_to_record_path  s    r   c                 C   s   t | dd}td|S )NrT   r   r8   )r   r$   )record_columnpr;   r;   r>   _parse_record_path  s    r   c                 C   s   g }| D ]}t |dkr$td| t|d }|||}||v rVtt|\}	}
n0t |dkrj|d nd}	t |dkr|d nd}
|||	|
f q|D ]*}t||}t|\}	}
|||	|
f qt	|D ]}||ddf q|S )z_
    :param installed: A map from archive RECORD path to installation RECORD
        path.
       z,RECORD line has more than three elements: %sr   ru   rS      )
r   loggerwarningr   poprQ   r   r   r   r   )old_csv_rows	installedrE   	generatedlib_dirinstalled_rowsrowold_record_pathnew_record_pathrI   rP   frM   installed_record_pathr;   r;   r>   get_csv_rows_for_installed  s$    
r   c                 C   s  |   } g }| dd}|rdtjvr4|d|  tjdddkr^|dtjd | |dt	 | d	d
 | D }|D ]
}| |= q| dd}|rdtjvr|d|  |dt	 | dd
 | D }|D ]
}| |= q|
tdj|   |S )zk
    Given the mapping from entrypoint name to callable, return the relevant
    console script specs.
    pipNENSUREPIP_OPTIONSzpip = rS   
altinstallz
pip{} = {}r   c                 S   s   g | ]}t d |r|qS )zpip(\d(\.\d)?)?$rematchr{   kr;   r;   r>   r   u  r   z,get_console_script_specs.<locals>.<listcomp>easy_installzeasy_install = zeasy_install-{} = {}c                 S   s   g | ]}t d |r|qS )zeasy_install(-\d\.\d)?$r   r   r;   r;   r>   r     s   {} = {})copyr   r\   r   r   rn   rW   ra   version_infor   extendr   r   )r   scripts_to_generate
pip_scriptpip_epr   easy_install_scripteasy_install_epr;   r;   r>   get_console_script_specs;  sD    #

r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )ZipBackedFilec                 C   s   || _ || _|| _d| _d S NF)rC   rD   	_zip_filerE   )r=   rC   rD   zip_filer;   r;   r>   __init__  s    zZipBackedFile.__init__c                 C   s&   t s| j| jS | j| jdS )NrT   )r
   r   getinforC   rc   r<   r;   r;   r>   _getinfo  s    zZipBackedFile._getinfoc              	   C   s   t j| j}t| t j| jr0t | j |  }| j	|H}t	| jd}t
|| W d    n1 st0    Y  W d    n1 s0    Y  t|rt| j d S )Nr[   )r\   rM   r   rD   r   existsunlinkr   r   r^   shutilcopyfileobjr!   r    )r=   r   zipinfor   destr;   r;   r>   r?     s    
HzZipBackedFile.saveN)r@   rA   rB   r   r   r?   r;   r;   r;   r>   r     s   	r   c                   @   s   e Zd Zdd Zdd ZdS )
ScriptFilec                 C   s$   || _ | j j| _| j j| _d| _d S r   )_filerC   rD   rE   )r=   filer;   r;   r>   r     s    

zScriptFile.__init__c                 C   s   | j   t| j| _d S r:   )r   r?   rl   rD   rE   r<   r;   r;   r>   r?     s    
zScriptFile.saveN)r@   rA   rB   r   r?   r;   r;   r;   r>   r     s   r   c                       s   e Zd Z fddZ  ZS )MissingCallableSuffixc                    s   t t| d| d S )NzInvalid script entry point: {} - A callable suffix is required. Cf https://packaging.python.org/specifications/entry-points/#use-for-scripts for more information.)superr   r   rW   )r=   entry_point	__class__r;   r>   r     s
    
zMissingCallableSuffix.__init__)r@   rA   rB   r   __classcell__r;   r;   r   r>   r     s   r   c                 C   s*   t | }|d ur&|jd u r&tt|d S r:   )r	   suffixr   rL   )specificationentryr;   r;   r>   _raise_for_invalid_entrypoint  s    r   c                       s   e Zd Zd fdd	Z  ZS )PipScriptMakerNc                    s   t | tt| ||S r:   )r   r   r   make)r=   r   optionsr   r;   r>   r     s    zPipScriptMaker.make)N)r@   rA   rB   r   r   r;   r;   r   r>   r     s   r   TFc           :   	      s  t | \}}	t|	r|jn|ji t g }
d-fdd	}fdd}dd }fdd	  fd
d} fdd}dd }| }t||}t||\}}|tt	 d}t
||}dd }t||\}}||}t
||}t||}t| }t|\fdd}t
||}t||}t
t|}t||}|D ] }|  ||j|j|j qJfdd} dd }!|r`t }"t  td |  D ]f}#t|#t	 d}$tj|$ddd}%|%r|!|#}&tj|&sJ td|&tjjd}'||'|& qW d   n1 s(0    Y  W d   n1 sH0    Y  t !|""  t#d|j$}(d|(_%dh|(_&d|(_'t(})t)t*d j+, }*|(-|)}+|
.|+ |
.|(-|*d!di |rt/|+},|,durt 0|, d"t1  @ t2j3fd#d$}-tj4|}.tj4|.d%}/|-|/}0|05d& W d   n1 sL0    Y  |
6|/ |durtj4|.t7}1|-|1$}2|25|8 9d' W d   n1 s0    Y  |
6|1 |r
tj4|.d(}3t:|3d) W d   n1 s0    Y  |
6|3 |;d*}4t)t<=|4> }5t?|5|
d+}6tj4|.d*}7|-|7fi t@d).}8t<Atd,|8}9|9BtC|6 W d   n1 s0    Y  dS ).a  Install a wheel.

    :param name: Name of the project to install
    :param wheel_zip: open ZipFile for wheel being installed
    :param scheme: Distutils scheme dictating the install directories
    :param req_description: String used in place of the requirement, for
        logging
    :param pycompile: Whether to byte-compile installed Python files
    :param warn_script_location: Whether to check that scripts are installed
        into a directory on PATH
    :raises UnsupportedWheel:
        * when the directory holds an unpacked wheel with incompatible
          Wheel-Version
        * when the .dist-info dir does not match the wheel
    Fc                    s(   t |}|| < |r$ t | dS )z6Map archive RECORD paths to installation RECORD paths.N)r   r   )srcfiler   modifiednewpath)rE   r   r   r;   r>   record_installed  s    
z(_install_wheel.<locals>.record_installedc                  3   s,      } tt| }|D ]}td|V  qd S )Nr8   )namelistr   r   r$   )namesdecoded_namesname)	wheel_zipr;   r>   	all_paths  s    
z!_install_wheel.<locals>.all_pathsc                 S   s
   |  dS )Nr   )endswithrM   r;   r;   r>   is_dir_path   s    z#_install_wheel.<locals>.is_dir_pathc                    s$   t | |s d}t| || d S )NzRThe wheel {!r} has a file {!r} trying to install outside the target directory {!r})r   r   rW   )dest_dir_pathtarget_pathmessage)
wheel_pathr;   r>   assert_no_path_traversal$  s    
z0_install_wheel.<locals>.assert_no_path_traversalc                    s    fdd}|S )Nc                    s0   t j| }t j|} | t| |S r:   )r\   rM   normpathr   r   )r   normed_pathrD   )r  r   r   r;   r>   make_root_scheme_file1  s    
zM_install_wheel.<locals>.root_scheme_file_maker.<locals>.make_root_scheme_filer;   )r   r   r  )r  )r   r   r>   root_scheme_file_maker/  s    z._install_wheel.<locals>.root_scheme_file_makerc                    sF   i  t D ]&}t|}tt||t d |< q fdd}|S )Nr   c           	   	      s   t j| }z|t jjd\}}}W n& tyL   d| }t|Y n0 z| }W n8 ty   d	t
}d|| |}t|Y n0 t j	||} || t| |S )Nr   zbUnexpected file in {}: {!r}. .data directory contents should be named like: '<scheme key>/<path>'.r   zUnknown scheme key used in {}: {} (for file {!r}). .data directory contents should be in subdirectories named with a valid scheme key ({}))r\   rM   r  rv   r   
ValueErrorrW   r   r   r   r   r   )	r   r  _
scheme_keydest_subpathr  scheme_pathvalid_scheme_keysrD   )r  scheme_pathsr  r   r;   r>   make_data_scheme_fileC  s*    
zM_install_wheel.<locals>.data_scheme_file_maker.<locals>.make_data_scheme_file)r   r   getattrra   rd   )r   schemekeyencoded_keyr  )r  r  )r  r   r>   data_scheme_file_maker:  s    z._install_wheel.<locals>.data_scheme_file_makerc                 S   s   |  ddd dS )Nr   ru   r   .data)rv   r
  r  r;   r;   r>   is_data_scheme_pathb  s    z+_install_wheel.<locals>.is_data_scheme_pathr   c                 S   s2   |  dd}t|dko0|d do0|d dkS )Nr   r   r   r#  ru   r   )rv   r   r
  )rM   partsr;   r;   r>   is_script_scheme_pathr  s    
z-_install_wheel.<locals>.is_script_scheme_pathc                    sz   | j }tj|}| dr.|d d }n<| drJ|d d }n | drf|d d }n|}| v px|v S )Nz.exez
-script.pyiz.pya)rD   r\   rM   r   ro   r
  )r   rM   r  	matchname)r   r   r;   r>   is_entrypoint_wrapper  s    z-_install_wheel.<locals>.is_entrypoint_wrapperc                  3   sH   t t  D ]2} tj| }tj|s0q|ds<q|V  qd S )Nz.py)r   r   r   r\   rM   r   r]   r
  )installed_pathfull_installed_path)r   r   r;   r>   pyc_source_file_paths  s    
z-_install_wheel.<locals>.pyc_source_file_pathsc                 S   s.   t rtjjr| d S | d S ntj| S dS )zAReturn the path the pyc file would have been written to.
        ocN)r
   ra   flagsoptimize	importlibutilcache_from_sourcer  r;   r;   r>   pyc_output_path  s
    
z'_install_wheel.<locals>.pyc_output_pathignoreT)forcequietr8   r   NrS   r   r   i  c                 ;   sT   t | fi |}|V  W d    n1 s,0    Y  t|j  t|j|  d S r:   )r   r\   chmodr  r   )rM   kwargsr   )generated_file_moder;   r>   _generate_file  s    $z&_install_wheel.<locals>._generate_file	INSTALLERs   pip
rT   	REQUESTEDwRECORD)r   rE   r   r   zIO[str])F)Dr"   rq   purelibplatlibr   r   r   r   ra   rd   r   r   r#   r   r   r?   rC   rD   rE   r   warningscatch_warningsfilterwarningsr   
compileallcompile_filer\   rM   r   r$   r   r   r   debuggetvaluer   r   clobbervariantsset_moder   listr   rW   r   make_multipler   r   r   r   
contextlibcontextmanagerr   rg   r   r   to_jsonrc   r^   get_metadatacsvreader
splitlinesr   rX   writer	writerowsr   ):r  r  r  r  	pycompilewarn_script_location
direct_url	requestedinfo_dirrp   r   r  r	  r  r  r"  r$  paths
file_pathsroot_scheme_pathsdata_scheme_pathsr  filesr&  other_scheme_pathsscript_scheme_pathsr  other_scheme_filesr   r)  script_scheme_filesr   r,  r4  stdoutrM   path_argsuccesspyc_pathpyc_record_pathmakerr   gui_scripts_to_generategenerated_console_scriptsmsgr;  dest_info_dirinstaller_pathinstaller_filedirect_url_pathdirect_url_filerequested_pathrecord_textrecord_rowsrowsr   record_filerU  r;   )	r  rE   r   r:  r   r   r   r  r  r>   _install_wheel  s    	(

	








N




*


4
 

rx  c              
   c   s^   z
d V  W nN t yX } z6d| |jd }tt t |t d  W Y d }~n
d }~0 0 d S )NzFor req: {}. {}r   r   )r   rW   argsr   ra   exc_info)req_descriptioner  r;   r;   r>   req_error_context,  s    
r}  c           	      C   sp   t |ddP}t|( t| |||||||d W d    n1 sD0    Y  W d    n1 sb0    Y  d S )NT)
allowZip64)r  r  r  r  rW  rX  rY  rZ  )r   r}  rx  )	r  r  r  r{  rW  rX  rY  rZ  zr;   r;   r>   install_wheel8  s    
r  )rF   )N)TTNF)TTNF)v__doc__
__future__r   r   rE  rN  rR  r1  loggingos.pathr\   r   r   ra   rB  base64r   	itertoolsr   r   zipfiler   pip._vendorr   pip._vendor.distlib.scriptsr   Zpip._vendor.distlib.utilr	   Zpip._vendor.sixr
   r   r   r   r   r   Zpip._vendor.six.movesr   r   pip._internal.exceptionsr   pip._internal.locationsr   pip._internal.models.direct_urlr   r   pip._internal.models.schemer   pip._internal.utils.filesystemr   r   pip._internal.utils.miscr   r   r   r   pip._internal.utils.typingr   pip._internal.utils.unpackingr   r   r    r!   pip._internal.utils.wheelr"   r#   r$   email.messager%   typingr&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   Zpip._vendor.pkg_resourcesr5   r6   r7   r8   rL   intZInstalledCSVRowr9   	getLoggerr@   r   rQ   rX   rl   rq   r   r   r   r   r   r   r   r   objectr   r   r   r   r   rx  rO  r}  r  r;   r;   r;   r>   <module>   s    D



G
!V.    
  H
    