a
    0fk                     @   s  d 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 ddlmZmZmZ ddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!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/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7m8Z8 ddl9m:Z:m;Z; ddl<m=Z=m>Z> ddl?m@Z@mAZA ddlBmCZCmDZDmEZEmFZF ddlGmHZHmIZImJZJmKZK ddlLmMZM erG dd de"ZNeOePZQe deRZSe%eSeRe&eTeRf f ZUdPeReTe%eReRf dddZVeReeRef dddZWeReXddd ZYeeXd!d"d#ZZe6e%eeReRf eeReRf f d$d%d&Z[e#eR e!eR d'd(d)Z\eeU ee%eReReRf  d*d+d,Z]eSeReRd-d.d/Z^eReReSd0d1d2Z_eeeR  eeSeSf e$eS eeR eReeU d3d4d5Z`eeReRf eeR d6d7d8ZaG d9d: d:ZbG d;d< d<ZcG d=d> d>e2ZdeRdd?d@dAZeG dBdC dCe,ZfdQeRe)eRe>eXeXe!e; eXddF	dGdHZgejheRedI dJdKdLZidReReRe>eReXeXe!e; eXddM	dNdOZjdS )SzGSupport for installing and building the "wheel" binary package format.
    N)urlsafe_b64encode)Message)chainfilterfalsestarmap)IOTYPE_CHECKINGAnyBinaryIOCallableDict	GeneratorIterableIteratorListNewTypeOptionalProtocolSequenceSetTupleUnioncast)ZipFileZipInfo)ScriptMaker)get_export_entry)canonicalize_name)InstallationError)get_major_minor_version)BaseDistributionFilesystemWheelget_wheel_distribution)DIRECT_URL_METADATA_NAME	DirectUrl)SCHEME_KEYSScheme)adjacent_tmp_filereplace)StreamWrapper
ensure_dir	hash_file	partition)current_umaskis_within_directory2set_extracted_file_to_default_mode_plus_executablezip_item_is_executable)parse_wheelc                   @   s4   e Zd ZU ded< eed< eed< ddddZdS )	File
RecordPathsrc_record_path	dest_pathchangedNreturnc                 C   s   d S N selfr:   r:   _/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.pysaveF   s    z	File.save)__name__
__module____qualname____annotations__strboolr>   r:   r:   r:   r=   r2   A   s   
r2   r3      )path	blocksizer8   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rstriprC   )rF   rG   hlengthrJ   r:   r:   r=   rehashP   s    rO   )moder8   c                 C   s   | dddS )zPReturn keyword arguments to properly open a CSV file
    in the given mode.
     utf-8)rP   newlineencodingr:   )rP   r:   r:   r=   csv_io_kwargsW   s    rU   rF   r8   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)osrF   isfileopenreadline
startswithsys
executableencodegetfilesystemencodinglinesepreadwrite)rF   script	firstlineexenamerestr:   r:   r=   
fix_script^   s    
&
(rj   )metadatar8   c                 C   s   |  dd dkS )NzRoot-Is-PurelibrQ   true)getlower)rk   r:   r:   r=   wheel_root_is_purelibr   s    ro   )distr8   c                 C   sL   i }i }|   D ]2}|jdkr,|j||j< q|jdkr|j||j< q||fS )Nconsole_scriptsgui_scripts)iter_entry_pointsgroupvaluename)rp   rq   rr   entry_pointr:   r:   r=   get_entrypointsv   s    

rx   )scriptsr8   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tj  fdd| D }|sdS g }| D ]j\}}t|}t|dkrd	|d
  d}	n$dd|dd d |d  }	|d|	 d| d qd}
t|dkr@||
d n||
d tdd tj	dd
tjD }|rd}|| 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|t jqS r:   )rZ   rF   normcasenormpathrL   sep.0ir:   r:   r=   
<listcomp>   s   z5message_about_scripts_not_on_PATH.<locals>.<listcomp>PATHrQ   c                    s.   i | ]&\}}t jt j| vr||qS r:   )rZ   rF   rz   r{   )r~   
parent_dirry   not_warn_dirsr:   r=   
<dictcomp>   s   z5message_about_scripts_not_on_PATH.<locals>.<dictcomp>   zscript r   z iszscripts {} are, z and zThe z installed in 'z' 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=   	<genexpr>   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setrZ   rF   dirnamebasenameaddenvironrm   splitpathsepappendrz   r{   r_   r`   itemssortedlenformatjoinany)ry   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   )outrowsr8   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 |fV  qd S r9   )rC   )r~   record_pathhash_sizer:   r:   r=   r      s   z&_normalized_outrows.<locals>.<genexpr>)r   )r   r:   r:   r=   _normalized_outrows   s    r   )r   lib_dirr8   c                 C   s   t j|| S r9   )rZ   rF   r   )r   r   r:   r:   r=   _record_to_fs_path   s    r   )rF   r   r8   c                 C   sP   t j| d  t j|d  kr6t j| |} | t jjd} td| S )Nr   /r3   )rZ   rF   
splitdrivern   relpathr(   r|   r   )rF   r   r:   r:   r=   _fs_to_record_path   s    (r   )old_csv_rows	installedr6   	generatedr   r8   c                 C   s   g }| D ]}t |dkr$td| td|d }|||}||v rZtt||\}	}
n0t |dkrn|d nd}	t |dkr|d nd}
|||	|
f q|D ]*}t||}t|\}	}
|||	|
f q|dd	 |	 D  S )
z_
    :param installed: A map from archive RECORD path to installation RECORD
        path.
       z,RECORD line has more than three elements: %sr3   r   r   rQ      c                 S   s   g | ]}|d d fqS )rQ   r:   )r~   installed_record_pathr:   r:   r=   r     s   z.get_csv_rows_for_installed.<locals>.<listcomp>)
r   loggerwarningr   poprO   r   r   r   values)r   r   r6   r   r   installed_rowsrowold_record_pathnew_record_pathrJ   rN   frF   r:   r:   r=   get_csv_rows_for_installed   s$    
r   )consoler8   c                 C   s  |   } g }| dd}|rdtjvr4|d|  tjdddkrb|dtjd  d|  |dt  d|  d	d
 | D }|D ]
}| |= q| dd}|rdtjvr|d|  |dt  d|  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 = rQ   
altinstallr   z = c                 S   s   g | ]}t d |r|qS )zpip(\d+(\.\d+)?)?$rematchr~   kr:   r:   r=   r   D      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   P  s   {} = {})copyr   rZ   r   r   rm   r_   version_infor   extendr   r   r   )r   scripts_to_generate
pip_scriptpip_epr   easy_install_scripteasy_install_epr:   r:   r=   get_console_script_specs  s4    !

r   c                   @   s<   e Zd ZeeeddddZedddZdddd	Z	dS )
ZipBackedFileN)r4   r5   zip_filer8   c                 C   s   || _ || _|| _d| _d S NF)r4   r5   	_zip_filer6   )r<   r4   r5   r   r:   r:   r=   __init__]  s    zZipBackedFile.__init__r7   c                 C   s   | j | jS r9   )r   getinfor4   r;   r:   r:   r=   _getinfoe  s    zZipBackedFile._getinfoc              	   C   s   t j| jrt | j |  }t| jd`}|jdkr| j|*}t	|jd}t
||| W d    n1 sv0    Y  W d    n1 s0    Y  t|rt| j d S )NrY   r   rE   )rZ   rF   existsr5   unlinkr   r\   	file_sizer   minshutilcopyfileobjr0   r/   )r<   zipinfodestr   rG   r:   r:   r=   r>   h  s    	
JzZipBackedFile.save)
r?   r@   rA   r3   rC   r   r   r   r   r>   r:   r:   r:   r=   r   \  s
   r   c                   @   s*   e Zd ZdddddZddddZdS )	
ScriptFiler2   Nfiler8   c                 C   s$   || _ | j j| _| j j| _d| _d S r   )_filer4   r5   r6   )r<   r   r:   r:   r=   r     s    

zScriptFile.__init__r7   c                 C   s   | j   t| j| _d S r9   )r   r>   rj   r5   r6   r;   r:   r:   r=   r>     s    
zScriptFile.save)r?   r@   rA   r   r>   r:   r:   r:   r=   r     s   r   c                       s$   e Zd Zedd fddZ  ZS )MissingCallableSuffixN)rw   r8   c                    s   t  d| d d S )NzInvalid script entry point: z - A callable suffix is required. Cf https://packaging.python.org/specifications/entry-points/#use-for-scripts for more information.)superr   )r<   rw   	__class__r:   r=   r     s    
zMissingCallableSuffix.__init__)r?   r@   rA   rC   r   __classcell__r:   r:   r   r=   r     s   r   )specificationr8   c                 C   s*   t | }|d ur&|jd u r&tt|d S r9   )r   suffixr   rC   )r   entryr:   r:   r=   _raise_for_invalid_entrypoint  s    r   c                       s8   e Zd Zdeeeeef  ee d fddZ  Z	S )PipScriptMakerN)r   optionsr8   c                    s   t | t ||S r9   )r   r   make)r<   r   r   r   r:   r=   r     s    zPipScriptMaker.make)N)
r?   r@   rA   rC   r   r   r	   r   r   r   r:   r:   r   r=   r     s
    r   TF)	rv   	wheel_zip
wheel_pathscheme	pycompilewarn_script_location
direct_url	requestedr8   c           :   	      sN  t || \}}	t|	r|jn|ji t g }
d4tttddfdd}ttddd}ttdd	fd
d ttt	tgdf d fdd}tt
t	tgdf d fdd}ttddd}ttt | }t||}t||\}}||}t||}ttddd}t||\}}|||}t||}t||}ttt| }t|\dtdfdd}t||}t||}tt|}t||}t }|D ]J}tj|j} | |vrt|  ||  |  ||j|j|j qt tddf dfdd}!ttddd}"|rt!"t#$t%j&}#t'( x t')d |! D ]V}$t*j+|$d d d!}%|%rV|"|$}&tj,|&sJ td"|&-tjj.d#}'||'|& qVW d   n1 s0    Y  W d   n1 s0    Y  t/0|#1  t2d|j3}(d |(_4d$h|(_5d |(_6t7})t8t9d%j:; }*|(<|)}+|
=|+ |
=|(<|*d&d i |rt>|+},|,durt/?|, d't@  @ t!jAttBt tCddf d(fd)d*}-tjD|}.tjD|.d+}/|-|/}0|0Ed, W d   n1 s0    Y  |
F|/ |durptjD|.tG}1|-|1$}2|2E|H Id- W d   n1 s\0    Y  |
F|1 |rtjD|.d.}3tJ|3d/ W d   n1 s0    Y  |
F|3 |Kd0}4t8tLM|4N }5tO|5|
d1}6tjD|.d0}7|-|7fi tPd2.}8tLQtd3|8}9|9RtS|6 W d   n1 s@0    Y  dS )5a  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
    FN)srcfiler   modifiedr8   c                    s$   t |}|| < |r  | dS )z6Map archive RECORD paths to installation RECORD paths.N)r   r   )r   r   r   newpath)r6   r   r   r:   r=   record_installed  s    
z(_install_wheel.<locals>.record_installedrV   c                 S   s
   |  dS )Nr   )endswithrF   r:   r:   r=   is_dir_path  s    z#_install_wheel.<locals>.is_dir_path)dest_dir_pathtarget_pathr8   c                    s$   t | |s d}t| || d S )NzRThe wheel {!r} has a file {!r} trying to install outside the target directory {!r})r.   r   r   )r  r  message)r   r:   r=   assert_no_path_traversal  s    
z0_install_wheel.<locals>.assert_no_path_traversalr2   )r   r   r8   c                    s   t dd fdd}|S )Nr2   r   r8   c                    s0   t j| }t j|} | t| |S r9   )rZ   rF   r{   r   r   )r   normed_pathr5   )r  r   r   r:   r=   make_root_scheme_file  s    
zM_install_wheel.<locals>.root_scheme_file_maker.<locals>.make_root_scheme_file)r3   )r   r   r  )r  )r   r   r=   root_scheme_file_maker  s    z._install_wheel.<locals>.root_scheme_file_maker)r   r   r8   c                    s0    fddt D tddfdd}|S )Nc                    s   i | ]}|t  |qS r:   )getattr)r~   key)r   r:   r=   r     r   zB_install_wheel.<locals>.data_scheme_file_maker.<locals>.<dictcomp>r2   r	  c           	         s   t j| }z|t jjd\}}}W n, tyR   d d| d}t|Y n0 z| }W nF ty   dt	}d d| d| d| d		}t|Y n0 t j||} || t
| |S )
Nr   zUnexpected file in z: zG. .data directory contents should be named like: '<scheme key>/<path>'.r   zUnknown scheme key used in z (for file zW). .data directory contents should be in subdirectories named with a valid scheme key ())rZ   rF   r{   r   r|   
ValueErrorr   KeyErrorr   r   r   )	r   r
  _
scheme_keydest_subpathr  scheme_pathvalid_scheme_keysr5   )r  scheme_pathsr   r   r:   r=   make_data_scheme_file  s*    
zM_install_wheel.<locals>.data_scheme_file_maker.<locals>.make_data_scheme_file)r%   r3   )r   r   r  )r  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   r   r   .data)r   r  r  r:   r:   r=   is_data_scheme_path  s    z+_install_wheel.<locals>.is_data_scheme_pathc                 S   s2   |  dd}t|dko0|d do0|d dkS )Nr   r   r   r  r   ry   )r   r   r  )rF   partsr:   r:   r=   is_script_scheme_path  s    z-_install_wheel.<locals>.is_script_scheme_pathr   c                    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)r5   rZ   rF   r   rn   r  )r   rF   rv   	matchname)r   guir:   r=   is_entrypoint_wrapper.  s    z-_install_wheel.<locals>.is_entrypoint_wrapperr7   c                  3   sH   t t  D ]2} tj| }tj|s0q|ds<q|V  qd S )Nz.py)r   r   r   rZ   rF   r   r[   r  )installed_pathfull_installed_path)r   r   r:   r=   pyc_source_file_pathsQ  s    
z-_install_wheel.<locals>.pyc_source_file_pathsc                 S   s   t j| S )z8Return the path the pyc file would have been written to.)	importlibutilcache_from_sourcer  r:   r:   r=   pyc_output_path^  s    z'_install_wheel.<locals>.pyc_output_pathignoreT)forcequietr3   r   rQ   r   r   i  )rF   kwargsr8   c                 ;   sT   t | fi |}|V  W d    n1 s,0    Y  t|j  t|j|  d S r9   )r'   rZ   chmodrv   r(   )rF   r,  r   )generated_file_moder:   r=   _generate_file  s    $z&_install_wheel.<locals>._generate_file	INSTALLERs   pip
rR   	REQUESTEDrY   RECORD)r   r6   r   r   wzIO[str])F)Tr1   ro   purelibplatlibr   r3   rC   rD   r   r   r&   r   r   namelistr   r,   mapr   r"   r!   r   rx   r   rZ   rF   r   r5   r*   r   r>   r4   r6   r   
contextlibredirect_stdoutr)   from_streamr_   stdoutwarningscatch_warningsfilterwarnings
compileallcompile_filer   r(   r|   r   debuggetvaluer   ry   clobbervariantsset_moder   listr   r   r   make_multipler   r   r   r-   contextmanagerr	   r
   r   re   r   r#   to_jsonra   r\   	read_textcsvreader
splitlinesr   rU   writer	writerowsr   ):rv   r   r   r   r   r   r   r   info_dirrk   r   r  r  r  r  r  paths
file_pathsroot_scheme_pathsdata_scheme_pathsr  filesr  other_scheme_pathsscript_scheme_pathsr  other_scheme_filesdistributionr!  script_scheme_filesZexisting_parentsr   r   r$  r(  r;  rF   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_filerN  r:   )r  r6   r   r.  r   r   r   r   r=   _install_wheel  s     	"














N



"
*


4
 

	rl  )NNN)req_descriptionr8   c              
   c   sT   z
d V  W nD t yN } z,d|  d|jd  }t ||W Y d }~n
d }~0 0 d S )Nz	For req: z. r   )r   args)rm  er  r:   r:   r=   req_error_context  s
    
rp  )	rv   r   r   rm  r   r   r   r   r8   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)rv   r   r   r   r   r   r   r   )r   rp  rl  )	rv   r   r   rm  r   r   r   r   zr:   r:   r=   install_wheel  s    

rs  )rE   )TTNF)TTNF)k__doc__r   r?  r8  rK  r%  loggingos.pathrZ   r   r   r_   r<  base64r   email.messager   	itertoolsr   r   r   typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   zipfiler   r   pip._vendor.distlib.scriptsr   Zpip._vendor.distlib.utilr   Zpip._vendor.packaging.utilsr   pip._internal.exceptionsr   pip._internal.locationsr   pip._internal.metadatar    r!   r"   pip._internal.models.direct_urlr#   r$   pip._internal.models.schemer%   r&   pip._internal.utils.filesystemr'   r(   pip._internal.utils.miscr)   r*   r+   r,   pip._internal.utils.unpackingr-   r.   r/   r0   pip._internal.utils.wheelr1   r2   	getLoggerr?   r   rC   r3   intInstalledCSVRowrO   rU   rD   rj   ro   rx   r   r   r   r   r   r   r   r   r   r   r   rl  rH  rp  rs  r:   r:   r:   r=   <module>   s   P	

(I

 K&
      #    