)uyc?ddlZddlZddlmZddlZddlmZmZddlmZ ddl m Z m Z m Z m Z mZmZmZn#e$rdZ dZ YnwxYwe rddlmZejd ejZejd ejZejd ejZGd d ZGddeZGddeZGddeZGddeZGddeZGddeZGddeZ GddeZ!GddeZ"Gd d!eZ#Gd"d#e"Z$Gd$d%e"Z%Gd&d'eZ&Gd(d)eZ'Gd*d+eZ(d1d-Z)d.Z*e*d/Z+e*d0Z,dS)2N) ReferenceType) resolve_ref_strI)BufferingIterator)Optionalcast TYPE_CHECKINGIterableUnionDictCallableFc|SN)tvs =/usr/lib/python3/dist-packages/debian/_deb822_repro/tokens.pyrs) Deb822Elementa (?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 )? ceZdZdZdZdZdZdZedZ edZ edZ d Z ed Z e jd Z d Zd S) 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_parent_element __weakref__ct|dkrtd||_d|_|dS)NzTokens must have content) ValueErrorrr_verify_token_text)selftexts r__init__zDeb822Token.__init__bsA 2::788 8 # !!!!!rcvd|jj|jddS)Nz{clsname}('{text}') z\n)clsnamer!)format __class____name__rreplacer s r__repr__zDeb822Token.__repr__js;$++DN4K151C1CD%1P1P,.. .rc&d|jvrd}|jst|trd}|s|jst d|jdst d|r"d|jddvrt ddSdSdS)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_whitespacerr!endswith)r is_single_line_tokens rrzDeb822Token._verify_token_textps 4:  #(  ,*T3C"D"D ,'+$' c0B c !abbb9%%d++ W !UVVV# 7 #2#(>(> "6777   7 7(>(>rcdSNFrr*s rr1zDeb822Token.is_whitespace~ urcdSr5rr*s rr.zDeb822Token.is_commentr6rc|jSrrr*s rr!zDeb822Token.texts zrc|jSrr9r*s rconvert_to_textzDeb822Token.convert_to_texts zrc*t|jSr)rrr*s rparent_elementzDeb822Token.parent_elements4/000rc@|tj|nd|_dSr)weakrefrefr)r new_parents rr=zDeb822Token.parent_elements(;E:Pw{:666VZrc*||jur d|_dSdSr)r=r)r parents rclear_parent_if_parentz"Deb822Token.clear_parent_if_parents& T( ( (#'D  ) (rN)r( __module__ __qualname____doc__ __slots__r"r+rpropertyr1r.r!r;r=setterrDrrrrrWsI XrrLceZdZdZdZdS)'Deb822SemanticallySignificantWhiteSpacezZWhitespace that (if removed) would change the meaning of the file (or cause syntax errors)rNr(rErFrGrHrrrrQrQddIIIrrQc&eZdZdZdZfdZxZS)Deb822NewlineAfterValueTokenzyThe newline after a value token. If not followed by a continuation token, this also marks the end of the field. rcJtddSNr$superr"r r's rr"z%Deb822NewlineAfterValueToken.__init__s! rr(rErFrGrHr" __classcell__r's@rrUrUsI IrrUceZdZdZdZdS)Deb822ValueContinuationTokenzWThe whitespace denoting a value spanning an additional line (the first space on a line)rNrRrrrr_r_aaIIIrr_ceZdZdZdZdS)Deb822SpaceSeparatorTokenz@Whitespace between values in a space list (e.g. "Architectures")rNrRrrrrbrbsJJIIIrrbceZdZdZdZdS)r0z)Token that represents a syntactical errorrNrRrrrr0r0s33IIIrr0c(eZdZdZedZdS)Deb822CommentTokenrcdSrNrr*s rr.zDeb822CommentToken.is_commentrOrN)r(rErFrHrIr.rrrreres2I Xrrec8eZdZdZfdZedZxZS)Deb822FieldNameTokenrct|ts!ttj|}t |dSr)r/rsysinternrYr")r r!r's rr"zDeb822FieldNameToken.__init__sJ$&& +D))**D rc,td|jS)Nr)rrr*s rr!zDeb822FieldNameToken.textsGTZ(((r)r(rErFrHr"rIr!r\r]s@rrhrhsXI ))X)))))rrhceZdZdZdS)Deb822SeparatorTokenrNr(rErFrHrrrrnrnIIIrrnc"eZdZdZfdZxZS)Deb822FieldSeparatorTokenrcJtddS)N:rXrZs rr"z"Deb822FieldSeparatorToken.__init__! r)r(rErFrHr"r\r]s@rrrrrs=Irrrc&eZdZdZdZfdZxZS)Deb822CommaTokenzZUsed by the comma-separated list value parsers to denote a comma between two value tokens.rcJtddS)N,rXrZs rr"zDeb822CommaToken.__init__rurr[r]s@rrwrwsCddIrrwc&eZdZdZdZfdZxZS)Deb822PipeTokenz-Used in some dependency fields as OR relationrcJtddS)N|rXrZs rr"zDeb822PipeToken.__init__rurr[r]s@rr{r{ sC77Irr{ceZdZdZdZdS)Deb822ValueTokenzWA field value can be split into multi "Deb822ValueToken"s (as well as separator tokens)rNrRrrrrrr`rrceZdZdZdZdS)Deb822ValueDependencyTokenzZPackage name, architecture name, a version number, or a profile name in a dependency fieldrNrRrrrrrrSrrceZdZdZdS)1Deb822ValueDependencyVersionRelationOperatorTokenrNrorrrrr!rprrutf-8c# Kd}i}fd}t||}|D]e}|rn|rd}t|tj}|r|d|z }t tj|V|ddkrt|V|ddvrl|Wtj|d}|dd}t|Vt|VtVnt|Vt|} | r| \} } } } }|| }| | dkr |r| |zn| }d} |r|d r |dd}|(tj| } t'| }||| <~ t)|Vt+V| r#t tj| V| rt| V|r#t tj|VtVTt|VgdS) zTokenize a deb822 file :param sequence: An iterable of lines (a file open for reading will do) :param encoding: The encoding to use (this is here to support Deb822-like APIs, new code should not use this parameter). Nc3K|D]J}t|tr|}|ds|dz }|VKdSrW)r/bytesdecoder2)sxencodings r_normalize_inputz.tokenize_deb822_file.._normalize_input1sm  A!U## 'HHX&&::d##  T GGGG  rrr#)  r-r$)risspacelist takewhilestrjoinrLrjrkrer_rrUr0_RE_FIELD_LINEmatchgroupsgetr2rrhrr)sequencercurrent_field_namefield_name_cacher text_streamlinerleadingfield_line_match field_name_ space_beforevalue space_afters ` rtokenize_deb822_filer&s)     $$4$4X$>$>??KL)L) <<>> ! *%)"[**3;7788A # "( 4(8(899 9 9 9  7c>>$T** * * *  7k ! !!-*T!W--AbDz27;;;;;&t,,,,,2444444&t,,,,, )//55 ( )AQ@W@W@Y@Y =ZL%!1!5!5j!A!A } =HYl[88\ !  3''--3"-crc"2K!) Z 33 %*:%6%6"/A , &'9:: : : :+-- - - - F+CJ|,D,DEEEEE .&u----- E+CJ{,C,CDDDDD.00 0 0 0 0"4(( ( ( ( (YL)L)rcfd}|S)Nc3Kd}t|dD]\}}|r|dksJ|drt |VHd}d}|s|d}|dd}d}|dr d}|dd}|#t tj|V|Ed{V|rtVdS) NT)keependsrrFrr$r-) enumerate splitlinesr startswithrer2r_rjrkrU)r first_linenor has_newlinecontinuation_line_markerfuncs rimplz#_value_line_tokenizer..impls9 !!,,,"="=>> 5 5HByy{{ -bAggggs## (.....K'+ $ +/7(ABBxJ}}T"" !" CRCy'323:>V3W3WXXXXXtDzz ! ! ! ! ! ! ! 5244444% 5 5rr)rrs` r_value_line_tokenizerrs#55555, Krc#6Kd|vsJt|D]u}|\}}}|r#tt j|Vt |V|r#tt j|VvdSrW)"_RE_WHITESPACE_SEPARATED_WORD_LISTfinditerrrbrjrkr)rrrwordrs rwhitespace_split_tokenizerrs q====3<rsf !!!!!!++++++++888888UUUUUUUUUUUUUUUUUUUM >DDD ;::::::&0RZ 1Z & &"!+ ,2Z3!!HZ"H(H(H(H(H(H(H(H(VK".C     #J   #J  G {  ) ) ) ) ); ) ) )";  +*{    g)g)g)g)T6 E E EFFFFFs5 AA