
    )grD                        S SK r S SKrS SKJrJrJrJrJrJrJ	r	  S SK
r
S SK
Jr  S SKJr  S SKJrJrJrJrJrJr  S SKJrJr  \(       a  S SKJr  \ R4                  " S\ R6                  5      r\ R4                  " S	\ R6                  5      r\ R4                  " S
\ R6                  5      r " S S\5      r " S S\5      r  " S S\ 5      r! " S S\!5      r" " S S\!5      r# " S S\!5      r$ " S S\5      r% " S S\5      r& " S S\5      r' " S S\5      r( " S S \(5      r) " S! S"\(5      r* " S# S$\(5      r+ " S% S&\5      r, " S' S(\5      r- " S) S*\5      r.S/S+ jr/S, r0\0S- 5       r1\0S. 5       r2g)0    N)OptionalcastTYPE_CHECKINGIterableUnionDictCallable)ReferenceType)BufferingIterator)	LocatableSTART_POSITIONRangeONE_CHAR_RANGEONE_LINE_RANGEPosition)resolve_ref_strI)Deb822Elementa  
    (?P<space_before>\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<word>\S+)                        # Consume the word (if present)
    (?P<trailing_whitespace>\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<space_before_comma>\s*)      # This space only occurs in practise if the line
                                             # starts with space + comma.
            (?P<comma> ,)
        )
    )

    # 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<space_before_word>\s*)
    (?P<word> [^,\s] (?: [^,]*[^,\s])? )?    # "Words" can contain spaces for comma separated list.
                                             # But surrounding whitespace is ignored
    (?P<space_after_word>\s*)
a  
    ^                                          # Start of line
    (?P<field_name>                            # 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<separator> : )
    (?P<space_before_value> \s* )
    (?:                                        # Field values are not mandatory on the same line
                                               # as the field name.

      (?P<value>  \S(?:.*\S)?  )               # Values must start and end on a "non-space"
      (?P<space_after_value> \s* )             # We can have optional space after the value
    )?
c                      \ rS rSrSrSrS rS\4S jrSS jr	\
S\4S	 j5       r\
S\4S
 j5       r\
S\4S j5       r\
S\4S j5       r\
S\4S j5       rS\4S jrS\4S jr\
S 5       r\R*                  S 5       rS rSrg)Deb822TokenT   a*  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_token_size__weakref__c                 n    US:X  a  [        S5      eXl        S U l        S U l        U R	                  5         g )N zTokens must have content)
ValueErrorr   r   r   _verify_token_text)selftexts     =/usr/lib/python3/dist-packages/debian/_deb822_repro/tokens.py__init__Deb822Token.__init___   s6    2:788
#!    returnc                 ~    SR                  U R                  R                  U R                  R	                  SS5      S9$ )Nz{clsname}('{text}')
z\n)clsnamer!   )format	__class____name__r   replacer    s    r"   __repr__Deb822Token.__repr__h   s:    $++DNN4K4K151C1CD%1P , . 	.r%   Nc                 Z   SU R                   ;   a  SnU R                  (       d  U R                  (       a  SnU(       d  U R                  (       d  [	        S5      eU R
                  R                  S5      (       d  [	        S5      eU(       a  SU R
                  S S ;   a  [	        S5      eg g g )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is_erroris_whitespacer   r!   endswith)r    is_single_line_tokens     r"   r   Deb822Token._verify_token_textm   s    4::#( $--'+$'0B0B !abb99%%d++ !UVV#		#2(>  "6 7 7 )?# r%   c                     gNF r.   s    r"   r5   Deb822Token.is_whitespacez       r%   c                     gr:   r;   r.   s    r"   r3   Deb822Token.is_comment~   r=   r%   c                     gr:   r;   r.   s    r"   r4   Deb822Token.is_error   r=   r%   c                     gr:   r;   r.   s    r"   is_separatorDeb822Token.is_separator   r=   r%   c                     U R                   $ Nr   r.   s    r"   r!   Deb822Token.text   s    zzr%   c                     U R                   $ rF   rG   r.   s    r"   convert_to_textDeb822Token.convert_to_text   s    zzr%   c                 p   U R                   nUb  U$ [        U R                  5      nUS:X  a  U R                  S:w  a  [        O[        nOfU R                  R                  S5      nU(       a  U R                  S   S:X  d   eU(       a  [        US5      O[        SU5      n[        [        U5      nXl         U$ )N   r(   r2   r   )	r   lenr   r   r   countr   r   r   )r    
token_size	token_len	new_linesend_poss        r"   sizeDeb822Token.size   s    %%
!

O	> ,0::+=>J

((.I DJJrNd$:::09hy!,x9?UG~w7J%r%   c                 ,    [        U R                  5      $ rF   )r   r   r.   s    r"   parent_elementDeb822Token.parent_element   s     4//00r%   c                 P    Ub  [         R                  " U5      U l        g S U l        g rF   )weakrefrefr   )r    
new_parents     r"   rW   rX      s#     ;E:Pw{{:6VZr%   c                 0    XR                   L a  S U l        g g rF   )rW   r   )r    parents     r"   clear_parent_if_parent"Deb822Token.clear_parent_if_parent   s    (((#'D  )r%   )r   r   r   r&   N)r,   
__module____qualname____firstlineno____doc__	__slots__r#   strr/   r   propertyboolr5   r3   r4   rC   r!   rJ   r   rT   rW   setterr_   __static_attributes__r;   r%   r"   r   r   T   s     KI".# .
7 t   D   $   d   c   e $ 1 1 [ [(r%   r   c                   4    \ rS rSrSrSr\S\4S j5       rSr	g)Deb822WhitespaceToken   aB  The 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.).
r;   r&   c                     gNTr;   r.   s    r"   r5   #Deb822WhitespaceToken.is_whitespace       r%   N)
r,   rb   rc   rd   re   rf   rh   ri   r5   rk   r;   r%   r"   rm   rm      s'     It  r%   rm   c                       \ rS rSrSrSrSrg)'Deb822SemanticallySignificantWhiteSpace   zZWhitespace that (if removed) would change the meaning of the file (or cause syntax errors)r;   Nr,   rb   rc   rd   re   rf   rk   r;   r%   r"   rt   rt      
    dIr%   rt   c                   4   ^  \ rS rSrSrSrSU 4S jjrSrU =r$ )Deb822NewlineAfterValueToken   zqThe newline after a value token.

If not followed by a continuation token, this also marks the end of the field.
r;   c                 $   > [         TU ]  S5        g Nr(   superr#   r    r+   s    r"   r#   %Deb822NewlineAfterValueToken.__init__   s    r%   ra   	r,   rb   rc   rd   re   rf   r#   rk   __classcell__r+   s   @r"   ry   ry      s    
 I r%   ry   c                       \ rS rSrSrSrSrg)Deb822ValueContinuationToken   zWThe whitespace denoting a value spanning an additional line (the first space on a line)r;   Nrv   r;   r%   r"   r   r      
    aIr%   r   c                   4    \ rS rSrSrSr\S\4S j5       rSr	g)Deb822SpaceSeparatorToken   z@Whitespace between values in a space list (e.g. "Architectures")r;   r&   c                     grp   r;   r.   s    r"   rC   &Deb822SpaceSeparatorToken.is_separator   rr   r%   N)
r,   rb   rc   rd   re   rf   rh   ri   rC   rk   r;   r%   r"   r   r      s#    JId  r%   r   c                   4    \ rS rSrSrSr\S\4S j5       rSr	g)Deb822ErrorToken   z)Token that represents a syntactical errorr;   r&   c                     grp   r;   r.   s    r"   r4   Deb822ErrorToken.is_error   rr   r%   N)
r,   rb   rc   rd   re   rf   rh   ri   r4   rk   r;   r%   r"   r   r      s#    3I$  r%   r   c                   0    \ rS rSrSr\S\4S j5       rSrg)Deb822CommentToken   r;   r&   c                     grp   r;   r.   s    r"   r3   Deb822CommentToken.is_comment   rr   r%   N)	r,   rb   rc   rd   rf   rh   ri   r3   rk   r;   r%   r"   r   r      s     ID  r%   r   c                   <   ^  \ rS rSrSrU 4S jr\S 5       rSrU =r	$ )Deb822FieldNameToken   r;   c                    > [        U[        5      (       d  [        [        R                  " U5      5      n[        TU ]  U5        g rF   )
isinstancer   sysinternr~   r#   )r    r!   r+   s     r"   r#   Deb822FieldNameToken.__init__   s0    $&&D)*Dr%   c                 .    [        SU R                  5      $ )Nr   )r   r   r.   s    r"   r!   Deb822FieldNameToken.text  s     GTZZ((r%   )
r,   rb   rc   rd   rf   r#   rh   r!   rk   r   r   s   @r"   r   r      s!    I ) )r%   r   c                   0    \ rS rSrSr\S\4S j5       rSrg)Deb822SeparatorTokeni
  r;   r&   c                     grp   r;   r.   s    r"   rC   !Deb822SeparatorToken.is_separator  rr   r%   N)	r,   rb   rc   rd   rf   rh   ri   rC   rk   r;   r%   r"   r   r   
  s     Id  r%   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )Deb822FieldSeparatorTokeni  r;   c                 $   > [         TU ]  S5        g )N:r}   r   s    r"   r#   "Deb822FieldSeparatorToken.__init__      r%   ra   )r,   rb   rc   rd   rf   r#   rk   r   r   s   @r"   r   r     s    I r%   r   c                   4   ^  \ rS rSrSrSrSU 4S jjrSrU =r$ )Deb822CommaTokeni  zZUsed by the comma-separated list value parsers to denote a comma between two value tokens.r;   c                 $   > [         TU ]  S5        g )N,r}   r   s    r"   r#   Deb822CommaToken.__init__   r   r%   ra   r   r   s   @r"   r   r     s    dI r%   r   c                   4   ^  \ rS rSrSrSrSU 4S jjrSrU =r$ )Deb822PipeTokeni$  z-Used in some dependency fields as OR relationr;   c                 $   > [         TU ]  S5        g )N|r}   r   s    r"   r#   Deb822PipeToken.__init__)  r   r%   ra   r   r   s   @r"   r   r   $  s    7I r%   r   c                       \ rS rSrSrSrSrg)Deb822ValueTokeni-  zWA field value can be split into multi "Deb822ValueToken"s (as well as separator tokens)r;   Nrv   r;   r%   r"   r   r   -  r   r%   r   c                       \ rS rSrSrSrSrg)Deb822ValueDependencyTokeni3  zZPackage name, architecture name, a version number, or a profile name in a dependency fieldr;   Nrv   r;   r%   r"   r   r   3  rw   r%   r   c                       \ rS rSrSrSrg)1Deb822ValueDependencyVersionRelationOperatorTokeni9  r;   N)r,   rb   rc   rd   rf   rk   r;   r%   r"   r   r   9  s    Ir%   r   c              #     ^#    Sn0 nU4S jn[        U" U 5      5      nU GH?  nUR                  5       (       ao  U(       a  Sn[        UR                  [        R                  5      5      nU(       a  USR                  U5      -  n[        [        R                  " U5      5      v   M  US   S:X  a  [        U5      v   M  US   S;   aX  UbE  [        R                  " US   5      nUSS n[        U5      v   [        U5      v   [        5       v   O[        U5      v   GM  [        R                  U5      n	U	(       Ga  U	R!                  5       u  ppnUR#                  U
5      nUb  US:X  a  U(       a  X-   OUnSnU(       a  UR%                  S	5      (       a  USS nUc%  [        R                  " U
5      n
['        U
5      nX#U
'   A
[)        U5      v   [+        5       v   U(       a!  [        [        R                  " U5      5      v   U(       a  [        U5      v   U(       a!  [        [        R                  " U5      5      v   [        5       v   GM2  [        U5      v   GMB     g7f)
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).
Nc              3      >#    U  HH  n[        U[        5      (       a  UR                  T5      nUR                  S5      (       d  US-  nUv   MJ     g 7fr|   )r   bytesdecoder6   )sxencodings     r"   _normalize_input.tokenize_deb822_file.<locals>._normalize_inputI  sJ     A!U##HHX&::d## T	G s   AAr   r   #) 	rM   r2   r(   )r   isspacelist	takewhilerg   joinrm   r   r   r   r   r   ry   r   _RE_FIELD_LINEmatchgroupsgetr6   r   r   r   )sequencer   current_field_namefield_name_cacher   text_streamlinerleadingfield_line_match
field_name_space_beforevaluespace_afters    `             r"   tokenize_deb822_filer   >  s      $$4X$>?K<<>>!%)" [**3;;78A
" (

4(8997c>$T**7k!!- **T!W-Abz27;;&t,,244&t,,)//5 AQ@W@W@Y=ZL!1!5!5j!A} =Hl8\! ''--"-cr"2K!) ZZ
3
%*:%6"/A,
 &'9::+--+CJJ|,DEE&u--+CJJ{,CDD.00"4((Y s   I#I&c                    ^  U 4S jnU$ )Nc              3     >#    Sn[        U R                  SS95       H  u  p#U R                  5       (       a  US:X  d   eUR                  S5      (       a  [	        U5      v   MG  SnS nU(       d
  US   nUSS  nSnUR                  S5      (       a  SnUS S nUb!  [        [        R                  " U5      5      v   T" U5       S h  vN   U(       d  M  [        5       v   M     g  N7f)	NT)keependsr   r   FrM   r(   r2   )
	enumerate
splitlinesr   
startswithr   r6   r   r   r   ry   )v
first_linenor   has_newlinecontinuation_line_markerfuncs         r"   impl#_value_line_tokenizer.<locals>.impl  s     
!!,,,"=>HByy{{bAg--s##(..K'+$+/7(ABxJ}}T"""CRy'323::>V3WXXDz!!{244% ?  "s   CC)C'		C)C)r;   )r   r   s   ` r"   _value_line_tokenizerr     s    5, Kr%   c              #     #    SU ;  d   eU (       a  U R                  5       (       a)  U (       a!  [        [        R                  " U 5      5      v   g [        R                  U 5       Hu  nUR                  5       u  p#nU(       a!  [        [        R                  " U5      5      v   [        U5      v   U(       d  MT  [        [        R                  " U5      5      v   Mw     g 7fr|   )r   r   r   r   "_RE_WHITESPACE_SEPARATED_WORD_LISTfinditerr   r   )r   r   r   wordr   s        r"   whitespace_split_tokenizerr     s      q==		+CJJqM::3<<Q?*/,,.'K+CJJ|,DEEt$$;+CJJ{,CDD @s   B3C9&Cc              #     #    SU ;  d   e[         R                  U 5       H  nUR                  5       u  p#pEnU(       a!  [        [        R
                  " U5      5      v   U(       a  [        5       v   U(       a!  [        [        R
                  " U5      5      v   U(       a  [        U5      v   U(       d  M  [        [        R
                  " U5      5      v   M     g 7fr|   )_RE_COMMA_SEPARATED_WORD_LISTr   r   rm   r   r   r   r   )r   r   space_before_commacommaspace_before_wordr   space_after_words          r"   comma_split_tokenizerr     s      q==.77:OT||~L#4<L'

3E(FGG"$$'

3D(EFF"4(('

3C(DEE ;s   B1C7&C)zutf-8)3rer   typingr   r   r   r   r   r   r	   rZ   r
   debian._deb822_repro._utilr   debian._deb822_repro.locatabler   r   r   r   r   r   debian._utilr   r   debian._deb822_repro.parsingr   compileVERBOSEr   r   r   r   rm   rt   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   r%   r"   <module>r      s   	 
 Q Q Q  ! 84 4 + : &(ZZ 1 ZZ& " !#

 ,2 ZZ3! H   ZZ"]() ](@K  .C 	#J 	#J  G {  ); )";  4 + * {   
g)T6 E E" F Fr%   