a
    0fE                     @   s<  U 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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 ddlmZ ddlmZmZ ddlmZ ddlmZ e
rdd	lmZ dd
lm Z  dgZ!eee"e#f  Z$ee#gee#ef f Z%e&dej'Z(e&dZ)e&dZ*ej+ej,ej-ej.ej/ej0ej1ej2ej3ej4ej5ej6ej7ej8gZ9eedej:f  e;d< ej<ej=ej>gZ?eedej:f  e;d< ej>gZ@eedej:f  e;d< dd e?D ZAdd e@D ZBeCeDZEG dd dZFG dd dZGdBe#ded eej eHeeFddf dddZIe#e$dd d!ZJdCeGeej eFd"d#d$ZKdDee#e"ed eej ed dd%d&d'ZLdEeGeej ed ed eeF d(d)d*ZMG d+d, d,ZNed e%d-d.d/ZOe#ee#e#f d0d1d2ZPG d3d4 d4eQZRejSd5d6d7ZTe$e$d8d9d:ZUe$e$d8d;d<ZVe$e$d8d=d>ZWe#dee#e#f d?d@dAZXdS )Fz
Requirements file parsing
    N)Values)
TYPE_CHECKINGAnyCallableDict	GeneratorIterableListNoReturnOptionalTuple)
cmdoptions)InstallationErrorRequirementsFileParseError)SearchScope)auto_decode)PackageFinder)
PipSessionparse_requirementsz^(http|https|file):z(^|\s+)#.*$z#(?P<var>\$\{(?P<name>[A-Z0-9_]+)\}).SUPPORTED_OPTIONSSUPPORTED_OPTIONS_REQSUPPORTED_OPTIONS_EDITABLE_REQc                 C   s   g | ]}t | jqS  strdest.0or   r   S/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_internal/req/req_file.py
<listcomp>O       r    c                 C   s   g | ]}t | jqS r   r   r   r   r   r   r    P   s   c                	   @   s8   e Zd Zdeeeeeeeef  ee ddddZdS )ParsedRequirementN)requirementis_editable
comes_from
constraintoptionsline_sourcereturnc                 C   s(   || _ || _|| _|| _|| _|| _d S N)r#   r$   r%   r'   r&   r(   )selfr#   r$   r%   r&   r'   r(   r   r   r   __init__X   s    	zParsedRequirement.__init__)NN)	__name__
__module____qualname__r   boolr   r   r   r,   r   r   r   r   r"   W   s     r"   c                   @   s$   e Zd ZeeeeeddddZdS )
ParsedLineN)filenamelinenoargsoptsr&   r)   c                 C   sZ   || _ || _|| _|| _|r0d| _d| _|| _n&|jrPd| _d| _|jd | _nd| _d S )NTFr   )r2   r3   r5   r&   is_requirementr$   r#   	editables)r+   r2   r3   r4   r5   r&   r   r   r   r,   j   s    zParsedLine.__init__)r-   r.   r/   r   intr   r0   r,   r   r   r   r   r1   i   s   r1   Fr   r   )r2   sessionfinderr'   r&   r)   c           	      c   sF   t |}t||}|| |D ]"}t||||d}|dur|V  qdS )aq  Parse a requirements file and yield ParsedRequirement instances.

    :param filename:    Path or url of requirements file.
    :param session:     PipSession instance.
    :param finder:      Instance of pip.index.PackageFinder.
    :param options:     cli options.
    :param constraint:  If true, parsing a constraint file rather than
        requirements file.
    )r'   r:   r9   N)get_line_parserRequirementsFileParserparsehandle_line)	r2   r9   r:   r'   r&   line_parserparserparsed_line
parsed_reqr   r   r   r      s    
)contentr)   c                 C   s,   t |  dd}t|}t|}t|}|S )zxSplit, filter, and join lines, and return a line iterator

    :param content: the content of the requirements file
       )start)	enumerate
splitlines
join_linesignore_commentsexpand_env_variables)rC   
lines_enumr   r   r   
preprocess   s
    rL   )liner'   r)   c                 C   s   d | jrdnd| j| j}| js&J | jr2t}nt}i }|D ],}|| jj	v r>| jj	| r>| jj	| ||< q>d| j d| j }t
| j| j|| j||dS )Nz{} {} (line {})z-cz-rline  of )r#   r$   r%   r&   r'   r(   )formatr&   r2   r3   r6   r$   #SUPPORTED_OPTIONS_EDITABLE_REQ_DESTSUPPORTED_OPTIONS_REQ_DESTr5   __dict__r"   r#   )rM   r'   line_comes_fromZsupported_destreq_optionsr   r(   r   r   r   handle_requirement_line   s,    
rV   )r5   r2   r3   r:   r'   r9   r)   c                    sf  | j rtd||  rH| jr&| j _| jrH j fdd| jD  |rb|j}|j}|jj	}| j	du rtd}g }| j
r|s| j
g}| jr|s|| j | jr| jd }	tjtj|}
tj|
|	}tj|r|}	||	 |r|| t|||d}||_| jr|  | jr*|  |rb| jp:g D ]$}d| d| }|j||d	 q<d S )
Nz>%s line %s has --hash but no requirement, and will be ignored.c                 3   s   | ]}| j vr|V  qd S r*   )features_enabled)r   fr'   r   r   	<genexpr>   s   z%handle_option_line.<locals>.<genexpr>Tr   )
find_links
index_urlsno_indexrN   rO   )source)hashesloggerwarningrequire_hashesrW   extendr[   r\   search_scoper]   	index_urlextra_index_urlsospathdirnameabspathjoinexistsappendupdate_index_urlsr   preset_allow_all_prereleasesprefer_binaryset_prefer_binarytrusted_hostsadd_trusted_host)r5   r2   r3   r:   r'   r9   r[   r\   r]   valuereq_dirrelative_to_reqs_filerd   hostr^   r   rY   r   handle_option_line   s^    





ry   )rM   r'   r:   r9   r)   c                 C   s4   | j rt| |}|S t| j| j| j||| dS dS )a  Handle a single parsed requirements line; This can result in
    creating/yielding requirements, or updating the finder.

    :param line:        The parsed line to be processed.
    :param options:     CLI options.
    :param finder:      The finder - updated by non-requirement lines.
    :param session:     The session - updated by non-requirement lines.

    Returns a ParsedRequirement object if the line is a requirement line,
    otherwise returns None.

    For lines that contain requirements, the only options that have an effect
    are from SUPPORTED_OPTIONS_REQ, and they are scoped to the
    requirement. Other options from SUPPORTED_OPTIONS may be present, but are
    ignored.

    For lines that do not contain requirements, the only options that have an
    effect are from SUPPORTED_OPTIONS. Options from SUPPORTED_OPTIONS_REQ may
    be present, but are ignored. These lines may contain multiple options
    (although our docs imply only one is supported), and all our parsed and
    affect the finder.
    N)r6   rV   ry   r5   r2   r3   )rM   r'   r:   r9   rB   r   r   r   r>     s    
r>   c                   @   sr   e Zd ZdeddddZeeeeddf dddZ	eeeeddf dd	d
Z
eeeeddf dddZdS )r<   r   N)r9   r?   r)   c                 C   s   || _ || _d S r*   )_session_line_parser)r+   r9   r?   r   r   r   r,   @  s    zRequirementsFileParser.__init__)r2   r&   r)   c                 c   s   |  ||E dH  dS )z*Parse a given file, yielding parsed lines.N)_parse_and_recurse)r+   r2   r&   r   r   r   r=   H  s    zRequirementsFileParser.parsec                 c   s   |  ||D ]}|js|jjs&|jjr|jjr@|jjd }d}n|jjd }d}t|rjtj	||}n t|st
jt
j||}| ||E d H  q|V  qd S )Nr   FT)_parse_filer6   r5   requirementsconstraints	SCHEME_REsearchurllibr=   urljoinrg   rh   rk   ri   r|   )r+   r2   r&   rM   req_pathnested_constraintr   r   r   r|   N  s(    


z)RequirementsFileParser._parse_and_recursec                 c   s   t || j\}}t|}|D ]l\}}z| |\}}	W n> tyt }
 z&d| d|
j }t|W Y d }
~
n
d }
~
0 0 t||||	|V  qd S )NzInvalid requirement: 
)get_file_contentrz   rL   r{   OptionParsingErrormsgr   r1   )r+   r2   r&   _rC   rK   line_numberrM   args_strr5   er   r   r   r   r}   m  s    z"RequirementsFileParser._parse_file)r-   r.   r/   
LineParserr,   r   r0   r   r1   r=   r|   r}   r   r   r   r   r<   ?  s   	 r<   )r:   r)   c                    s    t tt tf d fdd}|S )NrM   r)   c           	   
      s   t  }| }d |_ r  j|_t| \}}zt|}W n4 tyn } ztd| |W Y d }~n
d }~0 0 |	||\}}||fS )NzCould not split options: )
build_parserget_default_valuesre   format_controlbreak_args_optionsshlexsplit
ValueErrorr   
parse_args)	rM   r@   defaultsr   options_strr'   r   r5   r   r:   r   r   
parse_line  s    &z#get_line_parser.<locals>.parse_line)r   r   r   )r:   r   r   r   r   r;     s    r;   r   c                 C   sf   |  d}g }|dd }|D ]2}|ds6|dr< qRq|| |d qd|d|fS )zBreak up the line into an args and options string.  We only want to shlex
    (and then optparse) the options, not the args.  args can contain markers
    which are corrupted by shlex.
     N-z--r   )r   
startswithrm   poprk   )rM   tokensr4   r'   tokenr   r   r   r     s    

r   c                   @   s   e Zd ZeddddZdS )r   N)r   r)   c                 C   s
   || _ d S r*   )r   r+   r   r   r   r   r,     s    zOptionParsingError.__init__)r-   r.   r/   r   r,   r   r   r   r   r     s   r   )r)   c                  C   sJ   t jdd} tt }|D ]}| }| | qttdddd}|| _| S )z7
    Return a parser for parsing requirement lines
    F)add_help_optionr
   )r+   r   r)   c                 S   s   t |d S r*   )r   r   r   r   r   parser_exit  s    z!build_parser.<locals>.parser_exit)optparseOptionParserr   r   
add_optionr   r   exit)r@   option_factoriesoption_factoryoptionr   r   r   r   r     s    r   )rK   r)   c                 c   s   d}g }| D ]\}}| dr(t|rvt|r:d| }|rj|| |dusTJ |d|fV  g }q||fV  q|s~|}||d q|r|dusJ |d|fV  dS )zJoins a line ending in '' with the previous line (except when following
    comments).  The joined line takes on the index of the first line.
    N\r    )endswith
COMMENT_REmatchrm   rk   strip)rK   primary_line_numbernew_liner   rM   r   r   r   rH     s$    

rH   c                 c   s4   | D ]*\}}t d|}| }|r||fV  qdS )z1
    Strips comments and filter empty lines.
    r   N)r   subr   )rK   r   rM   r   r   r   rI     s
    rI   c                 c   sL   | D ]B\}}t |D ]$\}}t|}|s.q|||}q||fV  qdS )a  Replace all environment variables that can be retrieved via `os.getenv`.

    The only allowed format for environment variables defined in the
    requirement file is `${MY_VARIABLE_1}` to ensure two things:

    1. Strings that contain a `$` aren't accidentally (partially) expanded.
    2. Ensure consistency across platforms for requirement files.

    These points are the result of a discussion on the `github pull
    request #3514 <https://github.com/pypa/pip/pull/3514>`_.

    Valid characters in variable names follow the `POSIX standard
    <http://pubs.opengroup.org/onlinepubs/9699919799/>`_ and are limited
    to uppercase letter, digits and the `_` (underscore).
    N)
ENV_VAR_REfindallrg   getenvreplace)rK   r   rM   env_varvar_nameru   r   r   r   rJ     s    
rJ   )urlr9   r)   c              
   C   s   t j| j}|dv r@ddlm} || }|| |j|jfS z:t	| d}t
| }W d   n1 sn0    Y  W n2 ty } ztd| W Y d}~n
d}~0 0 | |fS )a  Gets the content of a file; it may be a filename, file: URL, or
    http: URL.  Returns (location, content).  Content is unicode.
    Respects # -*- coding: declarations on the retrieved files.

    :param url:         File path or url.
    :param session:     PipSession instance.
    )httphttpsfiler   )raise_for_statusrbNz"Could not open requirements file: )r   r=   urlsplitschemepip._internal.network.utilsr   getr   textopenr   readOSErrorr   )r   r9   r   r   resprX   rC   excr   r   r   r     s    
.$r   )NNF)N)NNN)NNN)Y__doc__loggingr   rg   rer   urllib.parser   r   typingr   r   r   r   r   r   r	   r
   r   r   pip._internal.clir   pip._internal.exceptionsr   r   !pip._internal.models.search_scoper   pip._internal.utils.encodingr   "pip._internal.index.package_finderr   pip._internal.network.sessionr   __all__r8   r   ReqFileLinesr   compileIr   r   r   re   extra_index_urlr]   r   r~   editabler[   	no_binaryonly_binaryrq   rb   ro   trusted_hostuse_new_featurer   Option__annotations__global_optionshashconfig_settingsr   r   rR   rQ   	getLoggerr-   r`   r"   r1   r0   r   rL   rV   ry   r>   r<   r;   r   	Exceptionr   r   r   rH   rI   rJ   r   r   r   r   r   <module>   s   0


    &   H   ,F