B
    =)H[Ø/  ã               @   sR  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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
gZe dej¡Ze d¡Ze d¡Zejejejejejej ej!ej"ej#ej$ej%ej&ej'ej(gZ)ej*ej+ej,gZ-dd„ e-D ƒZ.d"dd
„Z/dd„ Z0d#dd„Z1dd„ Z2dd„ Z3dd„ Z4dd„ Z5dd„ Z6d d!„ Z7dS )$z
Requirements file parsing
é    )Úabsolute_importN)Úfilterfalse)Úparse)Ú
cmdoptions)Úget_file_content)ÚRequirementsFileParseError)ÚInstallRequirementÚparse_requirementsz^(http|https|file):z(^|\s)+#.*$z#(?P<var>\$\{(?P<name>[A-Z0-9_]+)\})c             C   s   g | ]}|ƒ j ‘qS © )Údest)Ú.0Úor
   r
   ú[C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_internal\req\req_file.pyú
<listcomp>9   s    r   Fc             c   sp   |dkrt dƒ‚t| ||d�\}}t||ƒ}	x>|	D ]6\}
}t|| |
||||||d�	}x|D ]
}|V  qZW q2W dS )a÷  Parse a requirements file and yield InstallRequirement instances.

    :param filename:    Path or url of requirements file.
    :param finder:      Instance of pip.index.PackageFinder.
    :param comes_from:  Origin description of requirements.
    :param options:     cli options.
    :param session:     Instance of pip.download.PipSession.
    :param constraint:  If true, parsing a constraint file rather than
        requirements file.
    :param wheel_cache: Instance of pip.wheel.WheelCache
    NzCparse_requirements() missing 1 required keyword argument: 'session')Ú
comes_fromÚsession)Ú
constraint)Ú	TypeErrorr   Ú
preprocessÚprocess_line)ÚfilenameÚfinderr   Úoptionsr   r   Úwheel_cacheÚ_ÚcontentÚ
lines_enumÚline_numberÚlineÚreq_iterÚreqr
   r
   r   r	   <   s    


c             C   s6   t |  ¡ dd�}t|ƒ}t|ƒ}t||ƒ}t|ƒ}|S )z˜Split, filter, and join lines, and return a line iterator

    :param content: the content of the requirements file
    :param options: cli options
    é   )Ústart)Ú	enumerateÚ
splitlinesÚ
join_linesÚignore_commentsÚ
skip_regexÚexpand_env_variables)r   r   r   r
   r
   r   r   ]   s    
r   c	          	   c   sš  t | ƒ}	|	 ¡ }
d|
_|r"|j|
_t| ƒ\}}tjdk rB| d¡}|	 t	 
|¡|
¡\}}d|rbdnd||f }|rà|r||jnd}|r�t ||¡ i }x.tD ]&}||jkrš|j| rš|j| ||< qšW tj||||||d�V  �n¶|j�r|rò|jnd}tj|jd	 ||||d
�V  �n€|j�s&|j�r¶|j�r>|jd	 }d}n|jd	 }d}t |¡�rft ||¡}n"t |¡�sˆtj tj |¡|¡}t|||||||d�}	xö|	D ]}|V  �q¤W nà|j�rÈ|j|_nÎ|�r–|j�rà|jg|_ |j!dk�ròg |_ |j"�r|j  #|j"¡ |j$�rZ|j$d	 }tj tj %|¡¡}tj ||¡}tj &|¡�rN|}|j$ '|¡ |j(�rhd|_)|j*�rvd|_*|j+�r–|j, #dd„ |j+D ƒ¡ dS )a#  Process a single requirements line; This can result in creating/yielding
    requirements, or updating the finder.

    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.

    :param constraint: If True, parsing a constraints file.
    :param options: OptionParser options that we may update
    N)é   é   é   Úutf8z%s %s (line %s)z-cz-rF)r   Úisolatedr   r   r   )r   r   r-   r   T)r   r   c             s   s   | ]}d |d fV  qdS )Ú*Nr
   )r   Úhostr
   r
   r   ú	<genexpr>Û   s    zprocess_line.<locals>.<genexpr>)-Úbuild_parserÚget_default_valuesÚ	index_urlÚformat_controlÚbreak_args_optionsÚsysÚversion_infoÚencodeÚ
parse_argsÚshlexÚsplitÚisolated_moder   Úcheck_install_build_globalÚSUPPORTED_OPTIONS_REQ_DESTÚ__dict__r   Ú	from_lineÚ	editablesÚfrom_editableÚrequirementsÚconstraintsÚ	SCHEME_REÚsearchÚurllib_parseÚurljoinÚosÚpathÚjoinÚdirnamer	   Úrequire_hashesÚ
index_urlsÚno_indexÚextra_index_urlsÚextendÚ
find_linksÚabspathÚexistsÚappendÚpreÚallow_all_prereleasesÚprocess_dependency_linksÚtrusted_hostsÚsecure_origins)r   r   r   r   r   r   r   r   r   ÚparserÚdefaultsÚargs_strÚoptions_strÚoptsr   Úline_comes_fromr-   Úreq_optionsr   Úreq_pathÚnested_constraintr    ÚvalueÚreq_dirÚrelative_to_reqs_filer
   r
   r   r   k   s‚    











r   c             C   sh   |   d¡}g }|dd… }x8|D ]0}| d¡s8| d¡r<P q | |¡ | d¡ q W d |¡d |¡fS )z½Break 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;   Ú
startswithrU   ÚpoprK   )r   ÚtokensÚargsr   Útokenr
   r
   r   r5   Þ   s    


r5   c                sH   t jdd�}tt }x|D ]}|ƒ }| |¡ qW ‡ fdd„}||_|S )z7
    Return a parser for parsing requirement lines
    F)Úadd_help_optionc                s   dˆ |f }t |ƒ‚d S )NzInvalid requirement: %s
%s)r   )ÚselfÚmsg)r   r
   r   Úparser_exitü   s    z!build_parser.<locals>.parser_exit)ÚoptparseÚOptionParserÚSUPPORTED_OPTIONSÚSUPPORTED_OPTIONS_REQÚ
add_optionÚexit)r   r[   Úoption_factoriesÚoption_factoryÚoptionrq   r
   )r   r   r1   ï   s    
r1   c             c   s    d}g }x~| D ]v\}}|  d¡r*t |¡rlt |¡r<d| }|r`| |¡ |d |¡fV  g }q„||fV  q|st|}| | d¡¡ qW |rœ|d |¡fV  dS )z’Joins a line ending in '' with the previous line (except when following
    comments).  The joined line takes on the index of the first line.
    Nú\rg   Ú )ÚendswithÚ
COMMENT_REÚmatchrU   rK   Ústrip)r   Úprimary_line_numberÚnew_liner   r   r
   r
   r   r%     s     

r%   c             c   s8   x2| D ]*\}}t  d|¡}| ¡ }|r||fV  qW dS )z1
    Strips comments and filter empty lines.
    r|   N)r~   Úsubr€   )r   r   r   r
   r
   r   r&   "  s
    r&   c                s2   |r
|j nd}|r.t |¡‰ t‡ fdd„| ƒ} | S )zs
    Skip lines that match '--skip-requirements-regex' pattern

    Note: the regex pattern is only built once
    Nc                s   ˆ   | d ¡S )Nr!   )rF   )Úe)Úpatternr
   r   Ú<lambda>6  s    zskip_regex.<locals>.<lambda>)Úskip_requirements_regexÚreÚcompiler   )r   r   r'   r
   )r…   r   r'   -  s
    
r'   c             c   sT   xN| D ]F\}}x2t  |¡D ]$\}}t |¡}|s2q| ||¡}qW ||fV  qW 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 discusssion 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ÚfindallrI   ÚgetenvÚreplace)r   r   r   Úenv_varÚvar_namerd   r
   r
   r   r(   :  s    
r(   )NNNNFN)NNNNNF)8Ú__doc__Ú
__future__r   rr   rI   rˆ   r:   r6   Úpip._vendor.six.movesr   Zpip._vendor.six.moves.urllibr   rG   Úpip._internalr   Úpip._internal.downloadr   Úpip._internal.exceptionsr   Zpip._internal.req.req_installr   Ú__all__r‰   ÚIrE   r~   rŠ   rD   ÚeditablerC   rO   r3   rR   Úextra_index_urlÚalways_unzipÚ	no_binaryÚonly_binaryrV   rX   Útrusted_hostrM   rt   Úinstall_optionsÚglobal_optionsÚhashru   r>   r	   r   r   r5   r1   r%   r&   r'   r(   r
   r
   r
   r   Ú<module>   s\   

 
   
q