o |aoA@sddlZddlZddlmZddlZddlmZmZddlmZzddl m Z m Z m Z m Z mZmZmZWneyCdZ ddZ Ynwe rLdd lmZed Zed ejZed ejZed ejZGdddZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"Gd d!d!eZ#Gd"d#d#eZ$Gd$d%d%e#Z%Gd&d'd'e#Z&Gd(d)d)eZ'Gd*d+d+eZ(Gd,d-d-eZ)d.e ee*e+fd/e efd0d1Z,d2d3Z-e-d4d5Z.e-d6d7Z/dS)8N) ReferenceType) resolve_ref_strI)BufferingIterator)Optionalcast TYPE_CHECKINGIterableUnionDictCallableFcCs|SN)tvrr=/usr/lib/python3/dist-packages/debian/_deb822_repro/tokens.py sr) Deb822Elementz^\s+$a (?P\s*) # Consume any whitespace before the word # The space only occurs in practise if the line starts # with space. # Optionally consume a word (needed to handle the case # when there are no words left and someone applies this # pattern to the remaining text). This is mostly here as # a fail-safe. (?P\S+) # Consume the word (if present) (?P\s*) # Consume trailing whitespace a # This regex is slightly complicated by the fact that it should work with # finditer and comsume the entire value. # # To do this, we structure the regex so it always starts on a comma (except # for the first iteration, where we permit the absence of a comma) (?: # Optional space followed by a mandatory comma unless # it is the start of the "line" (in which case, we # allow the comma to be omitted) ^ | (?: (?P\s*) # This space only occurs in practise if the line # starts with space + comma. (?P ,) ) ) # From here it is "optional space, maybe a word and then optional space" again. One reason why # all of it is optional is to gracefully cope with trailing commas. (?P\s*) (?P [^,\s] (?: [^,]*[^,\s])? )? # "Words" can contain spaces for comma separated list. # But surrounding whitespace is ignored (?P\s*) a ^ # Start of line (?P # Capture group for the field name [\x21\x22\x24-\x2C\x2F-\x39\x3B-\x7F] # First character [\x21-\x39\x3B-\x7F]* # Subsequent characters (if any) ) (?P : ) (?P \s* ) (?: # Field values are not mandatory on the same line # as the field name. (?P \S(?:.*\S)? ) # Values must start and end on a "non-space" (?P \s* ) # We can have optional space after the value )? c@szeZdZdZdZddZddZddZed d Z ed d Z ed dZ ddZ eddZ e jddZ ddZdS) Deb822Tokena>A token is an atomic syntactical element from a deb822 file A file is parsed into a series of tokens. If these tokens are converted to text in exactly the same order, you get exactly the same file - bit-for-bit. Accordingly ever bit of text in a file must be assigned to exactly one Deb822Token. )_text_hash_parent_element __weakref__cCs.|dkrtd||_d|_d|_|dS)NzTokens must have content) ValueErrorrrr_verify_token_textselftextrrr__init__bs  zDeb822Token.__init__cCs.|jdkrdj|jj|jdddS|jjS)Nrz{clsname}('{text}') z\n)clsnamer)rformat __class____name__replacerrrr__repr__ks   zDeb822Token.__repr__cCsrd|jvr3d}|jst|trd}|s|jstd|jds$td|r5d|jddvr7tddSdSdS)Nr FTz>Only whitespace, error and comment tokens may contain newlinesz2Tokens containing whitespace must end on a newlinezNComments and error tokens must not contain embedded newlines (only end on one))r is_comment isinstanceDeb822ErrorToken is_whitespacerrendswith)ris_single_line_tokenrrrrss   zDeb822Token._verify_token_textcCdSNFrr&rrrr,zDeb822Token.is_whitespacecCr/r0rr&rrrr)r1zDeb822Token.is_commentcC|jSr rr&rrrrszDeb822Token.textcCr2r r3r&rrrconvert_to_textszDeb822Token.convert_to_textcCs t|jSr )rrr&rrrparent_elements zDeb822Token.parent_elementcCs"|dur t||_dSd|_dSr )weakrefrefr)r new_parentrrrr5s"cCs||jur d|_dSdSr )r5r)rparentrrrclear_parent_if_parents  z"Deb822Token.clear_parent_if_parentN)r$ __module__ __qualname____doc__ __slots__rr'rpropertyr,r)rr4r5setterr:rrrrrWs$       rc@s eZdZdZdZeddZdS)Deb822WhitespaceTokenaVThe token is a kind of whitespace. Some whitespace tokens are critical for the format (such as the Deb822ValueContinuationToken, spaces that separate words in list separated by spaces or newlines), while other whitespace tokens are truly insignificant (space before a newline, space after a comma in a comma list, etc.). rcCr/NTrr&rrrr,r1z#Deb822WhitespaceToken.is_whitespaceN)r$r;r<r=r>r?r,rrrrrAs rAc@eZdZdZdZdS)'Deb822SemanticallySignificantWhiteSpacezZWhitespace that (if removed) would change the meaning of the file (or cause syntax errors)rNr$r;r<r=r>rrrrrDrDcs$eZdZdZdZfddZZS)Deb822NewlineAfterValueTokenzyThe newline after a value token. If not followed by a continuation token, this also marks the end of the field. rctddSNr superrr&r#rrrsz%Deb822NewlineAfterValueToken.__init__r$r;r<r=r>r __classcell__rrrLrrGsrGc@rC)Deb822ValueContinuationTokenzWThe whitespace denoting a value spanning an additional line (the first space on a line)rNrErrrrrOrFrOc@rC)Deb822SpaceSeparatorTokenz@Whitespace between values in a space list (e.g. "Architectures")rNrErrrrrPrFrPc@rC)r+z)Token that represents a syntactical errorrNrErrrrr+rFr+c@seZdZdZeddZdS)Deb822CommentTokenrcCr/rBrr&rrrr)r1zDeb822CommentToken.is_commentN)r$r;r<r>r?r)rrrrrQsrQcs,eZdZdZfddZeddZZS)Deb822FieldNameTokenrcs(t|ts tt|}t|dSr )r*rsysinternrKrrrLrrrs zDeb822FieldNameToken.__init__cCs td|jS)Nr)rrr&rrrrs zDeb822FieldNameToken.text)r$r;r<r>rr?rrNrrrLrrRs  rRc@eZdZdZdS)Deb822SeparatorTokenrNr$r;r<r>rrrrrVrVcs"eZdZdZdfdd ZZS)Deb822FieldSeparatorTokenrreturnNcrH)N:rJr&rLrrrz"Deb822FieldSeparatorToken.__init__rZN)r$r;r<r>rrNrrrLrrYsrYc&eZdZdZdZdfdd ZZS)Deb822CommaTokenzZUsed by the comma-separated list value parsers to denote a comma between two value tokens.rrZNcrH)N,rJr&rLrrrr\zDeb822CommaToken.__init__r]rMrrrLrr_r_cr^)Deb822PipeTokenz-Used in some dependency fields as OR relationrrZNcrH)N|rJr&rLrrrr\zDeb822PipeToken.__init__r]rMrrrLrrb rarbc@rC)Deb822ValueTokenzWA field value can be split into multi "Deb822ValueToken"s (as well as separator tokens)rNrErrrrrdrFrdc@rC)Deb822ValueDependencyTokenzZPackage name, architecture name, a version number, or a profile name in a dependency fieldrNrErrrrrerFrec@rU)1Deb822ValueDependencyVersionRelationOperatorTokenrNrWrrrrrf!rXrfsequencerZccsvd}i}dttttfdttfdd}t||}t|ddD]\}}|dsJ|dur._as_str)startr zInvalid line iterator: Line zD did not end on a newline and it is not the last line in the stream!rzLine z[ was completely empty. The tokenizer expects whitespace (including newlines) to be presentcSst|duSr )_RE_WHITESPACE_LINEmatch)rkrrrrHsz&tokenize_deb822_file..r#)  r(TF)r r strrir enumerater-peekrrorplist takewhilejoinrArSrTrQrOrdrGr+_RE_FIELD_LINEgroupsgetrrRrY)rgcurrent_field_namefield_name_cacherl text_streamnolinerleadingemit_newline_tokenfield_line_match field_name_ space_beforevalue space_afterrrrtokenize_deb822_file&s"                      rcsfdd}|S)Nc3sd}|jddD]L}t|rJ|drt|Vq d}d}|s-|d}|dd}d}|dr.implr)rrrrr_value_line_tokenizers rccsbd|vsJt|D]"}|\}}}|rtt|Vt|V|r.tt|Vq dSrI)"_RE_WHITESPACE_SEPARATED_WORD_LISTfinditerr{rPrSrTrd)rrprwordrrrrwhitespace_split_tokenizers  rccsd|vsJt|D]6}|\}}}}}|r!tt|V|r'tV|r1tt|V|r8t|V|rBtt|Vq dSrI)_RE_COMMA_SEPARATED_WORD_LISTrr{rArSrTr_rd)rrpspace_before_commacommaspace_before_wordrspace_after_wordrrrcomma_split_tokenizers   r)0rerSr6r debian._utilrrdebian._deb822_repro._utilrtypingrrrr r r r ImportErrordebian._deb822_repro.parsingrcompileroVERBOSErrrzrrArDrGrOrPr+rQrRrVrYr_rbrdrerfrtrirrrrrrrrs\  (      $N    "r