a  zeD@sUdZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z mZmZmZddlmZddlmZmZddlmZddlmZdd lmZdd lmZdd lmZe rdd lm Z dd l!m"Z"dgZ#e ee$e%fZ&e e%gee%effZ'e(dej)Z*e(dZ+e(dZ,ej-ej.ej/ej0ej1ej2ej3ej4ej5ej6ej7ej8ej9ej:gZ;ee dejej?ej@gZAee dejZTe%eee%e%fd?d@dAZUdS)Fz Requirements file parsing N)Values) TYPE_CHECKINGAnyCallableDictIteratorListOptionalTuple) cmdoptions)InstallationErrorRequirementsFileParseError) SearchScope) PipSession)raise_for_status) auto_decode)get_url_scheme)NoReturn) PackageFinderparse_requirementsz^(http|https|file):z (^|\s+)#.*$z#(?P\$\{(?P[A-Z0-9_]+)\}).SUPPORTED_OPTIONSSUPPORTED_OPTIONS_REQcCsg|]}t|jqS)strdest).0orr\/opt/bitninja-python-dojo/embedded/lib/python3.9/site-packages/pip/_internal/req/req_file.py Drc @s8eZdZdeeeeeeeefeeddddZdS)ParsedRequirementN) requirement is_editable comes_from constraintoptions line_sourcereturncCs(||_||_||_||_||_||_dSN)r!r"r#r%r$r&)selfr!r"r#r$r%r&rrr__init__Hs zParsedRequirement.__init__)NN) __name__ __module__ __qualname__rboolr rrr*rrrrr Gsr c@s$eZdZeeeeeddddZdS) ParsedLineN)filenamelinenoargsoptsr$r'cCsZ||_||_||_||_|r0d|_d|_||_n&|jrPd|_d|_|jd|_nd|_dS)NTFr)r0r1r3r$is_requirementr"r! editables)r)r0r1r2r3r$rrrr*ZszParsedLine.__init__)r+r,r-rintrr.r*rrrrr/Ysr/Fr)r0sessionfinderr%r$r'c csFt|}t||}|||D]"}t||||d}|dur|VqdS)aqParse 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%r8r7N)get_line_parserRequirementsFileParserparse handle_line) r0r7r8r%r$ line_parserparser parsed_line parsed_reqrrrrts )contentr'cCs,t|dd}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_linesignore_commentsexpand_env_variables)rA lines_enumrrr preprocesss rJ)liner%r'cCsd|jrdnd|j|j}|js&J|jrBt|j|j||jdS|rTt ||j i}t D],}||j j vr\|j j |r\|j j |||<q\d|jd|j}t|j|j||j||dSdS)Nz{} {} (line {})z-cz-r)r!r"r#r$line  of )r!r"r#r$r%r&) formatr$r0r1r4r"r r!r check_install_build_globalr3SUPPORTED_OPTIONS_REQ_DEST__dict__)rKr%line_comes_from req_optionsrr&rrrhandle_requirement_lines4 rT)r3r0r1r8r%r7r'cs8r4|jr|j_|jr4jfdd|jD|r4|j}|j}|jrT|jg}|jdurbg}|jrt||j|jr|jd}tj tj |} tj | |} tj | r| }|||r||t||d} | |_|jr||jr||r4|jp gD]$} d|d|} |j| | dqdS) Nc3s|]}|jvr|VqdSr()features_enabled)rfr%rr s z%handle_option_line..Tr) find_links index_urlsrLrM)source)require_hashesrUextendrYrZ index_urlno_indexextra_index_urlsospathdirnameabspathjoinexistsappendupdate_index_urlsr search_scopepreset_allow_all_prereleases prefer_binaryset_prefer_binary trusted_hostsadd_trusted_host)r3r0r1r8r%r7rYrZvaluereq_dirrelative_to_reqs_filerihostr[rrWrhandle_option_linesL       rt)rKr%r8r7r'cCs4|jrt||}|St|j|j|j|||dSdS)aHandle 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)r4rTrtr3r0r1)rKr%r8r7r@rrrr<s r<c@s`eZdZeeddddZeeee dddZ eeee ddd Z eeee dd d Z dS) r:N)r7r=r'cCs||_||_dSr()_session _line_parser)r)r7r=rrrr*4szRequirementsFileParser.__init__)r0r$r'ccs|||EdHdS)z3Parse a given file, yielding parsed lines. N)_parse_and_recurse)r)r0r$rrrr;<szRequirementsFileParser.parseccs|||D]}|js|jjs&|jjr|jjr@|jjd}d}n|jjd}d}t|rjtj ||}n t|st j t j ||}|||EdHq |Vq dS)NrFT) _parse_filer4r3 requirements constraints SCHEME_REsearchurllibr;urljoinrarbrercrw)r)r0r$rKreq_pathnested_constraintrrrrwAs(     z)RequirementsFileParser._parse_and_recursec cst||j\}}t|}|D]l\}}z||\}} Wn>tyt} z&d|d| j} t| WYd} ~ n d} ~ 00t|||| |VqdS)NzInvalid requirement:  )get_file_contentrurJrvOptionParsingErrormsgr r/) r)r0r$_rArI line_numberrKargs_strr3errrrrx`s z"RequirementsFileParser._parse_file) r+r,r-r LineParserr*rr.rr/r;rwrxrrrrr:3s  r:)r8r'cs ttttfdfdd }|S)NrKr'csJt}|}d|_r j|_t|\}}|t||\}}||fSr() build_parserget_default_valuesr^format_controlbreak_args_options parse_argsshlexsplit)rKr>defaultsr options_strr3rr8rr parse_linews z#get_line_parser..parse_line)rr r)r8rrrrr9vsr9rcCsf|d}g}|dd}|D]2}|ds6|dr<qRq|||dqd|d|fS)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 startswithrgpopre)rKtokensr2r%tokenrrrrs    rc@seZdZeddddZdS)rN)rr'cCs ||_dSr()rr)rrrrr*szOptionParsingError.__init__)r+r,r-rr*rrrrrsr)r'cCsJtjdd}tt}|D]}|}||qttdddd}||_|S)z7 Return a parser for parsing requirement lines F)add_help_optionr)r)rr'cSs t|dSr()rrrrr parser_exitsz!build_parser..parser_exit)optparse OptionParserrr add_optionrrexit)r>option_factoriesoption_factoryoptionrrrrrs  r)rIr'ccsd}g}|D]\}}|dr(t|rvt|r:d|}|rj|||dusTJ|d|fVg}q||fVq |s~|}||dq |r|dusJ|d|fVdS)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_REmatchrgrestrip)rIprimary_line_numbernew_linerrKrrrrFs$      rFccs4|D]*\}}td|}|}|r||fVqdS)z1 Strips comments and filter empty lines. rN)rsubr)rIrrKrrrrGs   rGccsL|D]B\}}t|D]$\}}t|}|s.q|||}q||fVqdS)aReplace 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 `_. Valid characters in variable names follow the `POSIX standard `_ and are limited to uppercase letter, digits and the `_` (underscore). N) ENV_VAR_REfindallragetenvreplace)rIrrKenv_varvar_namerprrrrHs  rH)urlr7r'c Cst|}|dvr.||}t||j|jfSz:t|d}t|}Wdn1s\0YWn2ty}zt d|WYd}~n d}~00||fS)aGets 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. )httphttpsfilerbNz"Could not open requirements file: ) rgetrrtextopenrreadOSErrorr )rr7schemeresprVrAexcrrrrs   .$r)NNF)N)NNN)NNN)V__doc__rrarer urllib.parser}rtypingrrrrrrr r Zpip._internal.clir pip._internal.exceptionsr r !pip._internal.models.search_scoperpip._internal.network.sessionrpip._internal.network.utilsrpip._internal.utils.encodingrpip._internal.utils.urlsrr"pip._internal.index.package_finderr__all__r6r ReqFileLinesrcompileIr{rrr^extra_index_urlr_rzryeditablerY no_binary only_binaryrlr\rj trusted_hostuse_new_featurerOption__annotations__install_optionsglobal_optionshashrrPr r/r.rrJrTrtr<r:r9r ExceptionrrrrFrGrHrrrrrs (            / @ ,C