U
    cUhG                     @   s  d 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	m
Z
mZmZmZm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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$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z,m-Z- dddgZ.e/e0Z1ej23 Z4e5ee5ee5 f dddZ6ee5 ee5 dddZ7eee5 edddZ8e5eee5 e5ee5 f dd dZ9e5dd!d"d#Z:e5e5d$d%d&Z;ed'd(G d)d* d*Z<e5e<dd+d,Z=dLdd-ddd-d-d-dd.e5eee"e5f  ee> e>ee
e5  ee	e5e
e5 f  e>e>e>ee	e5ee5e
e5 f f  e"d/d0dZ?e5e>d1d2d3Z@e5e5ee5 d4d5d6ZAe5ee5 e<d7d8d9ZBdMdd-ddd-dd-dd:e5eee5e"f  ee> e>ee
e5  ee	e5e
e5 f  e>ee5 e>ee	e5ee5e
e5 f f  e"d;d<dZCdNe5ee" e>ee> e>e"d=d>d?ZDdOe e>ee> e>ee	e5ee5e
e5 f f  e"d@dAdBZEee"e"dCdDdEZFe"e"dFdGdHZGe"ee5 e"dIdJdKZHdS )Pa~  Backing implementation for InstallRequirement's various constructors

The idea here is that these formed a major chunk of InstallRequirement's size
so, moving them and support code dedicated to them outside of that class
helps creates for better understandability for the rest of the code.

These are meant to be used elsewhere within pip to create instances of
InstallRequirement.
    N)	dataclass)
CollectionDictListOptionalSetTupleUnion)Marker)InvalidRequirementRequirement)	Specifier)InstallationError)PyPITestPyPI)Link)Wheel)ParsedRequirement)InstallRequirement)is_archive_file)is_installable_dir)get_requirement)path_to_url)is_urlvcsinstall_req_from_editableinstall_req_from_lineparse_editable)pathreturnc                 C   s6   t d| }d }|r*|d}|d}n| }||fS )Nz^(.+)(\[[^\]]+\])$      )rematchgroup)r   mextrasZpath_no_extras r'   ^/opt/bot/vods_filmes/script/venv/lib/python3.8/site-packages/pip/_internal/req/constructors.py_strip_extras,   s    
r)   )r&   r   c                 C   s   | s
t  S td|   jS )Nplaceholder)setr   lowerr&   )r&   r'   r'   r(   convert_extras8   s    r-   )req
new_extrasr   c                 C   s   t jdt| t jd}|dk	s.td|  d|d}|d}|dk	rR|dk	sbtd|  dd	|rxd
t|nd}t	| | | S )z
    Returns a new requirement based on the given one, with the supplied extras. If the
    given requirement already has extras those are replaced (or dropped if no new extras
    are given).
    z([\w\t .-]+)(\[[^\]]*\])?(.*))flagsNzregex match on requirement z! failed, this should never happenr       z&regex group selection for requirement z[{}], )
r"   	fullmatchstrASCIIAssertionErrorr$   formatjoinsortedr   )r.   r/   r#   prepostr&   r'   r'   r(   _set_requirement_extras>   s&    



r=   )editable_reqr   c                 C   s   | }t |\}}tj|r$t|}| drdt|j}|rX||t	d|  j
fS ||t fS tD ]*}| | drh| d| } qqht|}|jsdtj}t|  d| d|j}|std|  d	||t fS )
a   Parses an editable requirement into:
        - a requirement name
        - an URL
        - extras
        - editable options
    Accepted requirements:
        svn+http://blahblah@rev#egg=Foobar[baz]&subdirectory=version_subdir
        .[some_extra]
    zfile:r*   :+z, zq is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with z).z'Could not detect requirement name for 'z1', please specify one with #egg=your_package_name)r)   osr   isdirr   r,   
startswithr   egg_fragmentr   r&   r+   r   is_vcsr9   all_schemesr   )r>   urlZurl_no_extrasr&   package_nameZversion_controllinkbackendsr'   r'   r(   r   W   s8    

)filenamer   c              	   C   s   t | ddd|}dd dd |D D }|D ]X}d|krJ|d|d }|d	rn|dd
  t|d }t|  W 5 Q R  dS W 5 Q R X dS )a   Check if file is parsable as a requirements file.

    This is heavily based on ``pkg_resources.parse_requirements``, but
    simplified to just check the first meaningful line.

    :raises InvalidRequirement: If the first meaningful line cannot be parsed
        as an requirement.
    zutf-8ignore)encodingerrorsc                 s   s    | ]}|r| d s|V  qdS )#N)rC   .0liner'   r'   r(   	<genexpr>   s    
z2check_first_requirement_in_file.<locals>.<genexpr>c                 s   s   | ]}|  V  qd S N)striprP   r'   r'   r(   rS      s     z #N\r3   )openfindendswithrU   nextr   )rK   flinesrR   r'   r'   r(   check_first_requirement_in_file   s    	
r^   )r.   r   c                 C   s^   t j| sd|  dS d}zt|  W n  tk
rH   td|  Y nX |d|  d7 }|S )zReturns helpful msg in case requirements file does not exist,
    or cannot be parsed.

    :params req: Requirements file path
    z File 'z' does not exist.z The path does exist. z&Cannot parse '%s' as requirements filezThe argument you provided (zx) appears to be a requirements file. If that is the case, use the '-r' flag to install the packages specified within it.)rA   r   existsr^   r   loggerdebug)r.   msgr'   r'   r(   deduce_helpful_msg   s    
rc   T)frozenc                   @   s>   e Zd ZU ee ed< ee ed< ee ed< ee	 ed< dS )RequirementPartsrequirementrI   markersr&   N)
__name__
__module____qualname__r   r   __annotations__r   r
   r   r5   r'   r'   r'   r(   re      s   
re   c              
   C   sv   t | \}}}|d k	r\zt|}W q` tk
rX } ztd|d| W 5 d }~X Y q`X nd }t|}t||d |S )NInvalid requirement: : )r   r   r   r   r   re   )r>   namerG   Zextras_overrider.   excrI   r'   r'   r(   parse_req_from_editable   s    (rp   F)
use_pep517isolatedglobal_optionshash_options
constraintuser_suppliedpermit_editable_wheelsconfig_settings)r>   
comes_fromrq   rr   rs   rt   ru   rv   rw   rx   r   c                C   s0   t | }
t|
j||d||
j||||||	|
jdS )NT)ry   rv   editablerw   rI   ru   rq   rr   rs   rt   rx   r&   )rp   r   rf   rI   r&   )r>   ry   rq   rr   rs   rt   ru   rv   rw   rx   partsr'   r'   r(   r      s     )rn   r   c                 C   s>   t jj| krdS t jjdk	r,t jj| kr,dS | dr:dS dS )ak  Checks whether the string "looks like" a path on the filesystem.

    This does not check whether the target actually exists, only judge from the
    appearance.

    Returns true if any of the following conditions is true:
    * a path separator is found (either os.path.sep or os.path.altsep);
    * a dot is found (which represents the current directory).
    TN.F)rA   r   sepaltseprC   )rn   r'   r'   r(   _looks_like_path   s    

r   )r   rn   r   c                 C   s   t |r4tj| r4t| r$t| S td|dt| s@dS tj| rTt| S |	dd}t
|dkr|t |d s|dS td| t| S )	aK  
    First, it checks whether a provided path is an installable directory. If it
    is, returns the path.

    If false, check if the path is an archive file (such as a .whl).
    The function checks if the path is a file. If false, if the path has
    an @, it will treat it as a PEP 440 URL requirement and return the path.
    z
Directory zC is not installable. Neither 'setup.py' nor 'pyproject.toml' found.N@r    r!   r   zARequirement %r looks like a filename, but the file does not exist)r   rA   r   rB   r   r   r   r   isfilesplitlenr`   warning)r   rn   Zurlreq_partsr'   r'   r(   _get_url_from_path  s$    	
r   )rn   line_sourcer   c                    sn  t | rd}nd}|| krF| |d\} }| }|s<d }qJt|}nd }|  } d }tjtj| }d }d }t | rt| }n&t	|\}	}t
|	| }
|
d k	rt|
}|r|jdkrtd|jrtttjtj|j}|jrt|j}|j d|j }n|j}n| }t|}ttd fdd	ttd
fdd}|d k	r\||}nd }t||||S )Nz; ;r    filez\.\./z==)textr   c                    s    s| S |  d  dS )Nz (from )r'   )r   )r   r'   r(   with_sourcec  s    z(parse_req_from_line.<locals>.with_source)req_as_stringr   c              
      s   z
t  W S  tk
r } zxtjj kr:d}|t 7 }n(d kr^t fddtD s^d}nd}d d| }|r|d	| 7 }t|W 5 d }~X Y nX d S )
NzIt looks like a path.=c                 3   s   | ]}| kV  qd S rT   r'   )rQ   opr   r'   r(   rS   o  s    zAparse_req_from_line.<locals>._parse_req_string.<locals>.<genexpr>z,= is not a valid operator. Did you mean == ?r3   rl   rm   z
Hint: )	r   r   rA   r   r}   rc   any	operatorsr   )r   ro   Zadd_msgrb   )r   r   r(   _parse_req_stringh  s    
z.parse_req_from_line.<locals>._parse_req_string)r   r   rU   r
   rA   r   normpathabspathr   r)   r   schemer"   searchrG   r   is_wheelr   rK   rn   versionrD   r-   r5   r   re   )rn   r   Z
marker_sepZmarkers_as_stringrg   r   r   rI   Zextras_as_stringprG   wheelr&   r   r.   r'   )r   r   r(   parse_req_from_line3  sH    





r   )rq   rr   rs   rt   ru   r   rv   rx   )rn   ry   rq   rr   rs   rt   ru   r   rv   rx   r   c                C   s2   t | |}
t|
j||
j|
j|||||	||
j|dS )a  Creates an InstallRequirement from a name, which might be a
    requirement, directory containing 'setup.py', filename, or URL.

    :param line_source: An optional string describing where the line is from,
        for logging purposes in case of an error.
    )
rI   rg   rq   rr   rs   rt   rx   ru   r&   rv   )r   r   rf   rI   rg   r&   )rn   ry   rq   rr   rs   rt   ru   r   rv   rx   r{   r'   r'   r(   r     s    
)
req_stringry   rr   rq   rv   r   c              
   C   s   zt | }W n6 tk
rB } ztd| d| W 5 d }~X Y nX tjtjg}|jr|r|jr|jj|krtd|j	 d| dt
|||||dS )Nrl   rm   zZPackages installed from PyPI cannot depend on packages which are not also hosted on PyPI.
z depends on  )rr   rq   rv   )r   r   r   r   file_storage_domainr   rG   rI   netlocrn   r   )r   ry   rr   rq   rv   r.   ro   Zdomains_not_allowedr'   r'   r(   install_req_from_req_string  s2    &
r   )
parsed_reqrr   rq   rv   rx   r   c                 C   st   | j r$t| j| j|| j|||d}nLt| j| j||| jrF| jdg ng | jr\| jdi ni | j| j||d
}|S )N)ry   rq   ru   rr   rv   rx   rs   hashes)	ry   rq   rr   rs   rt   ru   r   rv   rx   )	is_editabler   rf   ry   ru   r   optionsgetr   )r   rr   rq   rv   rx   r.   r'   r'   r(   #install_req_from_parsed_requirement  s2    r   )rI   ireqr   c                 C   s2   t |j|j|j| |j|j|j|j|j|j	|j
dS )N)r.   ry   rz   rI   rg   rq   rr   rs   rt   rx   rv   )r   r.   ry   rz   rg   rq   rr   rs   rt   rx   rv   )rI   r   r'   r'   r(   install_req_from_link_and_ireq  s    r   )r   r   c                 C   sR   t | jdk	rt| jt nd| | j| j| j| j| j| j	| j
| jg | j| j| jdS )z
    Creates a new InstallationRequirement using the given template but without
    any extras. Sets the original requirement as the new one's parent
    (comes_from).
    N)r.   ry   rz   rI   rg   rq   rr   rs   rt   ru   r&   rx   rv   rw   )r   r.   r=   r+   rz   rI   rg   rq   rr   rs   rt   ru   rx   rv   rw   )r   r'   r'   r(   install_req_drop_extras  s     r   )r   r&   r   c                 C   s8   t  | }| j||_| jdk	r.t| j|jnd|_|S )z
    Returns a copy of an installation requirement with some additional extras.
    Makes a shallow copy of the ireq object.
    N)copyr&   r.   r=   )r   r&   resultr'   r'   r(   install_req_extend_extras!  s    
r   )N)N)NFNF)FNFN)I__doc__r   loggingrA   r"   dataclassesr   typingr   r   r   r   r   r   r	   Zpip._vendor.packaging.markersr
   "pip._vendor.packaging.requirementsr   r   Z pip._vendor.packaging.specifiersr   pip._internal.exceptionsr   pip._internal.models.indexr   r   pip._internal.models.linkr   pip._internal.models.wheelr   pip._internal.req.req_filer   pip._internal.req.req_installr   pip._internal.utils.filetypesr   pip._internal.utils.miscr   pip._internal.utils.packagingr   pip._internal.utils.urlsr   pip._internal.vcsr   r   __all__	getLoggerrh   r`   
_operatorskeysr   r5   r)   r-   r=   r   r^   rc   re   rp   boolr   r   r   r   r   r   r   r   r   r   r'   r'   r'   r(   <module>   s   
$

"7 
 "Q 
'    (    ) 