
    )g~                       S SK rS SKrS SKrS SK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JrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJrJrJ r   S SK!J"r"J#r#J$r$  S SK%J&r&J'r'J(r(J)r)  S S	K*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9  S S
K:J;r;J<r<  S SK=J>r>J?r?J@r@JArAJBrBJCrC  S SK=JDrD  S SK:JErEJFrFJGrGJHrHJIrIJJrJJKrKJLrL  \\+\\+   /\F4   rM\\N/\\S\F4      4   rO\@S   rP " S S\\G   5      rQ\R                  S:  d  \(       a  \R                  \D   rTO " S S\\D   5      rT " S S\\F\E4   \TS   5      rU " S S\\D   5      rV " S S\V\D   \\D\F4   5      rWS rX " S S\W\U\F\E4   \F4   5      rYS rZS  r[S! r\S" r] " S# S$\&5      r^ " S% S&\^5      r_ " S' S(\^5      r` " S) S*\^5      ra " S+ S,\^5      rb " S- S.\^5      rc " S/ S0\^5      rd " S1 S\^5      reS2 rf SUS4 jrgS5 rh\R                  S:  d  \(       a  \R                  R2                  \H\D4   riO$ " S6 S7\R                  R2                  \\D   \5      ri " S8 S9\\D   \i\D   5      rj " S: S;\j\N   \5      rk " S< S=\j\D   \5      rl " S> S?\l\D   5      rm " S@ SA\l\N   \k5      rn " SB SC\^\k\5      ro " SD SE\o5      rp " SF SG\o5      rq " SH SI\^5      rr\" \6\`5      rs\" \/\d5      rt\" \a\b5      ru\" \e\o\oR                  SJ9rwSK rx\Y" \9\Z\c\-SL \x5      ry\Y" \8\\\c\3\3\x5      rz\Y" \8\]\c\3\3\x5      r{SM r|SN r}SO r~SP rS3S3SQSR.SS jr\ST:X  a  S SKr\GR                  " 5         gg)V    N)ABC)TracebackType)IterableIteratorListUnionDictOptionalCallableAnyGenericTypeTupleIOcastoverloadMappingTYPE_CHECKINGSequence)ReferenceType)combine_into_replacementBufferingIteratorlen_check_iterator)FormatterContentToken%one_value_per_line_trailing_separatorformat_field)	LocatableSTART_POSITIONPositionRange)Deb822TokenDeb822ValueToken'Deb822SemanticallySignificantWhiteSpaceDeb822SpaceSeparatorTokenDeb822CommentTokenDeb822WhitespaceTokenDeb822ValueContinuationTokenDeb822NewlineAfterValueTokenDeb822CommaTokenDeb822FieldNameTokenDeb822FieldSeparatorTokenDeb822ErrorTokentokenize_deb822_filecomma_split_tokenizerwhitespace_split_tokenizer)AmbiguousDeb822FieldKeyErrorSyntaxOrParseError)resolve_ref
LinkedListLinkedListNode
OrderedSet_strIdefault_field_sort_key)T)STVETEParagraphKeyTokenOrElement
CommentishParagraphKeyBaseFormatterCallbackr!   Deb822KeyValuePairElementc                       \ rS rSrSrSrS rS r\S\	4S j5       r
\
R                  S 5       r
\S\4S	 j5       rSS jrSrg
)ValueReference0   a2  Reference to a value inside a Deb822 paragraph

This is useful for cases where want to modify values "in-place" or maybe
conditionally remove a value after looking at it.

ValueReferences can be invalidated by various changes or actions performed
to the underlying provider of the value reference.  As an example, sorting
a list of values will generally invalidate all ValueReferences related to
that list.

The ValueReference will raise validity issues where it detects them but most
of the time it will not notice.  As a means to this end,  the ValueReference
will *not* keep a strong reference to the underlying value.  This enables it
to detect when the container goes out of scope.  However, keep in mind that
the timeliness of garbage collection is implementation defined (e.g., pypy
does not use ref-counting).
)_node_render_value_factory_removal_handler_mutation_notifierc                 j    [         R                  " U5      U l        X l        X0l        X@l        XPl        g N)weakrefrefrE   rF   rG   rH   rI   )selfnoderendervalue_factoryremoval_handlermutation_notifiers         >/usr/lib/python3/dist-packages/debian/_deb822_repro/parsing.py__init__ValueReference.__init__F   s+     [[&
+ /"3    c                 r    U R                   c  [        S5      eU R                  5       nUc  [        S5      eU$ )Nz(Cannot use ValueReference after remove()z-ValueReference is invalid (garbage collected))rE   RuntimeError)rN   rO   s     rT   _resolve_nodeValueReference._resolve_nodeS   s;     ::IJJzz|<NOOrW   returnc                 T    U R                  U R                  5       R                  5      $ )z Resolve the reference into a str)rF   rZ   valuerN   s    rT   r^   ValueReference.value^   s"     ||D..06677rW   c                     U R                  U5      U R                  5       l        U R                  b  U R                  5         gg)ae  Update the reference value

Updating the value via this method will *not* invalidate the reference (or other
references to the same container).

This can raise an exception if the new value does not follow the requirements
for the referenced values.  As an example, values in whitespace separated
lists cannot contain spaces and would trigger an exception.
N)rG   rZ   r^   rI   rN   	new_values     rT   r^   r`   c   s=     &*%8%8%C""".##% /rW   c                 6    U R                  5       R                  $ )zJReference to a locatable that can be used to determine where this value is)rZ   r^   r_   s    rT   	locatableValueReference.locatables   s     !!#)))rW   Nc                 d    U R                  [        SU R                  5       5      5        SU l        g)zRemove the underlying value

This will invalidate the ValueReference (and any other ValueReferences pointing
to that exact value).  The validity of other ValueReferences to that container
remains unaffected.
zLinkedListNode[TokenOrElement]N)rH   r   rZ   rE   r_   s    rT   removeValueReference.removex   s*     	d#CTEWEWEYZ[
rW   )rI   rE   rH   rF   rG   r\   N)__name__
__module____qualname____firstlineno____doc__	__slots__rU   rZ   propertystrr^   setterr   re   rh   __static_attributes__ rW   rT   rC   rC   0   sl    $ aI4	 8s 8 8 \\& & *9 * *rW   rC   )   	   c                        \ rS rSrS rS rSrg)%_Deb822ParsedTokenList_ContextManager   c                     U $ rK   ru   r_   s    rT   	__enter__/_Deb822ParsedTokenList_ContextManager.__enter__   s    KrW   c                     g rK   ru   )rN   exc_typeexc_valexc_tbs       rT   __exit__._Deb822ParsedTokenList_ContextManager.__exit__   s    rW   ru   N)rk   rl   rm   rn   r|   r   rt   ru   rW   rT   ry   ry      s    		rW   ry   c                     ^  \ rS rSrS rS rS\4S jrU 4S jr\	S 5       r
S\\   4S jrS*S
 jrS rS+S jrS rS rS rS rS rS\4S jrS*S jrS r\	S\4S j5       rS*S jrS*S jrS*S jrS*S jr S,S jrS*S jr S r!S\4S jr"S\4S jr#S-S  jr$SS!.S"\S\4S# jjr%S*S$ jr&S	SS%.S& jr'S	S'.S( jr(S)r)U =r*$ ).Deb822ParsedTokenList   c                    Xl         X l        [        UR                  5      U l        X0l        X@l        XPl        X`l        [        XS5      U l
        Xpl        SU l        [        U l        SU l        S U l        U R                  (       d   eU R                  R"                  nUb1  [%        U[&        5      (       a  U R                  R)                  5         g g g NTF)_kvpair_element_proxy_elementr3   parts_token_list_vtype_stype_str2value_parser_default_separator_factory_parser_to_value_factoryrG   rF   $_format_preserve_original_formattingr   
_formatter_changed._Deb822ParsedTokenList__continuation_line_chartail
isinstancer(   pop)	rN   kvpair_elementinterpreted_value_elementvtypestypestr2value_parserdefault_separator_factoryrP   
last_tokens	            rT   rU   Deb822ParsedTokenList.__init__   s      .7%&?&E&EF!1*C'67GO481?(,%%%**
!j=Y&Z&Z   " '[!rW   c              #   N   ^ #    U 4S jT R                    5        S h  vN   g  N7f)Nc              3   F   >#    U  H  nTR                  U5      v   M     g 7frK   )rF   .0vrN   s     rT   	<genexpr>1Deb822ParsedTokenList.__iter__.<locals>.<genexpr>   s     >-=DLLOO-=s   !)value_partsr_   s   `rT   __iter__Deb822ParsedTokenList.__iter__   s     >T-=-=>>>   %#%r\   c                 0    [        [        U 5      S 5      S L$ rK   )nextiterr_   s    rT   __bool__Deb822ParsedTokenList.__bool__   s    DJ%T11rW   c                 l   > Uc!  U R                   (       a  U R                  5         [        TU ]  XU5      $ rK   )r   _update_fieldsuperr   )rN   r   r   r   	__class__s       rT   r   Deb822ParsedTokenList.__exit__   s/      w6::rW   c              #   N   ^ #    U 4S jT R                    5        S h  vN   g  N7f)Nc              3   b   >#    U  H$  n[        UTR                  5      (       d  M   Uv   M&     g 7frK   )r   r   r   s     rT   r   4Deb822ParsedTokenList.value_parts.<locals>.<genexpr>   s"     N/!:a3MAA/s   /	/r   r_   s   `rT   r   !Deb822ParsedTokenList.value_parts   s      Ot//NNNr   c              #   8   #    U R                    S h  vN   g  N7frK   r   r_   s    rT   
iter_parts Deb822ParsedTokenList.iter_parts   s     ####   Nc                     SU l         g NT)r   r_   s    rT   _mark_changed#Deb822ParsedTokenList._mark_changed   s	    rW   c              #   j   ^ #    U 4S jT R                   R                  5        5        Sh  vN   g N7f)zIterate over all values in the list (as ValueReferences)

This is useful for doing inplace modification of the values or even
streaming removal of field values.  It is in general also more
efficient when more than one value is updated or removed.
c              3      >#    U  Hm  n[        UR                  TR                  5      (       d  M*  [        [	        S U5      TR
                  TR                  TR                  TR                  5      v   Mo     g7f)zLinkedListNode[VE]N)	r   r^   r   rC   r   rF   rG   _remove_noder   )r   nrN   s     rT   r   >Deb822ParsedTokenList.iter_value_references.<locals>.<genexpr>   sg      
 1a!''4;;/
N%q)LL
 
 1s   )A8AA8N)r   
iter_nodesr_   s   `rT   iter_value_references+Deb822ParsedTokenList.iter_value_references   s.     
 ##..0
 	
 	
s   (313c                 *   U R                  5       nUR                  (       a  SnSU l        U R                  5         U R                  R                  U5        U(       a7  UR                  (       d%  U R                  R                  [        S5      5        g g g NFT )r   is_whitespacer   ,_append_continuation_line_token_if_necessaryr   appendr&   )rN   space_after_separatorseparator_tokens      rT   append_separator&Deb822ParsedTokenList.append_separator   sv     99;(($)!99;0 )F)F##$9#$>? *G rW   c                 (   U R                   nU R                  R                  5        H^  n[        UR                  U5      (       d  M   U R                  UR                  5      U:X  d  MA  U R                  U5      Ul        SU l          g   [        S5      e)zsReplace the first instance of a value with another

This method will *not* affect the validity of ValueReferences.
Tz!list.replace(x, y): x not in listN)	r   r   r   r   r^   rF   rG   r   
ValueError)rN   
orig_valuerc   r   rO   s        rT   replaceDeb822ParsedTokenList.replace   su     $$//1D$**e,,djj1IZ1W!00;
 $	 2 @AArW   c                    U R                   nU R                  R                  5        HC  n[        UR                  U5      (       d  M   U R                  UR                  5      U:X  d  MA  Un  O   [        S5      eU R                  U5      $ )zRemove the first instance of a value

Removal will invalidate ValueReferences to the value being removed.
ValueReferences to other values will be unaffected.
zlist.remove(x): x not in list)r   r   r   r   r^   rF   r   r   )rN   r^   r   rO   node_to_removes        rT   rh   Deb822ParsedTokenList.remove  sr     $$//1D$**e,,djj1IU1R!% 2
 <==  00rW   c                    U R                   nSU l        S nS nSnSnUR                  SS9 HM  nUR                  n[	        U[
        5      (       a  UR                  (       a  SnM9  [	        X5      (       d  MK  Un  O   UR                  SS9 HM  n	U	R                  n
[	        U
[
        5      (       a  U
R                  (       a  SnM9  [	        X5      (       d  MK  U	n  O   Uc  Uc  U R                  R                  5         g Ub
  U(       d  SnOUb
  U(       d  SnOUS LnU(       a  UnUR                  nOUR                  nUnUc  XR                  l        Uc  XR                  l        [        R                  " X5        g )NTFskip_current)r   r   iter_previousr^   r   r!   
is_comment	iter_nextr   clear	next_nodeprevious_node	head_node	tail_noder4   
link_nodes)rN   r   r   first_value_on_lhsfirst_value_on_rhscomment_before_previous_valuecomment_before_next_value	past_node
past_tokenfuture_nodefuture_tokendelete_lhs_of_nodefirst_remain_lhsfirst_remain_rhss                 rT   r   "Deb822ParsedTokenList._remove_node  s   v "!(-%$)!'5545HI"J*k22z7L7L04-*,,%." I *333FK&,,L,449P9P,0),..%0" G %*<*D""$)2O!%+4M!&
 "44!?1-77-;;1 #)9&#)9&!!"2ErW   c                 H    U R                  U5      nU R                  U5        g rK   )rG   append_value)rN   r^   vts      rT   r   Deb822ParsedTokenList.append  s       '"rW   c                    U R                   nU(       aj  SnU R                  nU R                  n[        U5       H)  n[	        Xe5      (       a  Sn  O[	        Xd5      (       d  M)    O   U(       a  U R                  5         O$U R                   R                  [        S5      5        U R                  5         SU l	        UR                  U5        g r   )
r   r   r   reversedr   r   r   r&   r   r   )rN   r   r   needs_separatorr   r   ts          rT   r   "Deb822ParsedTokenList.append_value  s    &&#OKKEKKEk*a''&*Oa'' + %%' ##$9#$>?99;2rW   c                     U R                   R                  nUS L=(       a    UR                  5       R                  S5      $ N
)r   r   convert_to_textendswithrN   r   s     rT   _previous_is_newline*Deb822ParsedTokenList._previous_is_newline  s7    $$4ID$8$8$:$C$CD$IIrW   c                     U R                  5       (       a  [        S5      eU R                  R                  [	        5       5        g )Nz9Cannot add a newline after a token that ends on a newline)r  r   r   r   r(   r_   s    rT   append_newline$Deb822ParsedTokenList.append_newline  s5    $$&&XYY < >?rW   c                     U R                   R                  nUb$  UR                  5       R                  S5      (       d  U R	                  5         [        [        U5      5      nU R                   R                  U5        g r   )r   r   r  r  r  r%   _format_commentr   )rN   comment_textr   comment_tokens       rT   append_comment$Deb822ParsedTokenList.append_comment  s`    $$<t335>>tDD!*?<+HI.rW   c                     U R                   nUc>  SnU R                   H&  n[        U[        5      (       d  M  UR                  n  O   Xl         U$ Nr   )r   r   r   r'   text)rN   chartokens      rT   _continuation_line_char-Deb822ParsedTokenList._continuation_line_char  sN    ,,<D))e%ABB ::D * -1)rW   c                     U R                   R                  nUbT  UR                  5       R                  S5      (       a/  U R                   R	                  [        U R                  5      5        g g g r   )r   r   r  r  r   r'   r  r  s     rT   r   BDeb822ParsedTokenList._append_continuation_line_token_if_necessary  s[    $$ 4 4 6 ? ? E E##$@A]A]$^_ !FrW   c                 2    U R                  5         SU l        g r   )_enable_reformattingr   r_   s    rT   reformat_when_finished,Deb822ParsedTokenList.reformat_when_finished  s    !!#rW   c                     SU l         g NFr   r_   s    rT   r  *Deb822ParsedTokenList._enable_reformatting  s
    491rW   c                     SU l         g r   r  r_   s    rT   no_reformatting_when_finished3Deb822ParsedTokenList.no_reformatting_when_finished  s
    481rW   Fc                 <    Xl         SU l        U(       a  SU l        gg)a<  Use a custom formatter when formatting the value

:param formatter: A formatter (see debian._deb822_repro.formatter.format_field
  for details)
:param force_reformat: If True, always reformat the field even if there are
  no (other) changes performed.  By default, fields are only reformatted if
  they are changed.
FTN)r   r   r   )rN   	formatterforce_reformats      rT   value_formatter%Deb822ParsedTokenList.value_formatter  s      $491 DM rW   c                 h    U R                   (       a  SU l        U R                   R                  5         g)zGLike list.clear() - removes all content (including comments and spaces)TN)r   r   r   r_   s    rT   r   Deb822ParsedTokenList.clear  s$     DM rW   c              #      #    U R                    H6  n[        U[        5      (       a  UR                  5        S h  vN   M2  Uv   M8     g  N7frK   )r   r   Deb822Elementiter_tokens)rN   tes     rT   _iter_content_as_tokens-Deb822ParsedTokenList._iter_content_as_tokens  s:     ""B"m,,>>+++	 #+s   8AA
Ac                   ^^^ U R                  5       nU R                  mU R                  mU R                  mUUU4S jn[	        U R
                  U R                  R                  [        R                  " UR                  5      U" 5       5      $ )Nc               3     >#    Sn T H  n[        U[        5      (       an  UR                  (       a$  [        R                  " UR
                  5      v   MM  [        UT5      (       a&  UR
                  n [        R                  " U 5      v   M  M  [        UT5      (       d   eUR                  5       n [        R                  " U 5      v   M     g 7f)N )	r   r!   r   r   r  r  r   r  value_token)r  r-  r   
token_listr   s     rT   _token_iterNDeb822ParsedTokenList._generate_reformatted_field_content.<locals>._token_iter  s     D b+..}}3AA"''JJ#B..!ww3CCDII / &b%0000--/D/;;DAA !s   CC)r   r   r   r   r   r   r   
field_namer   r   r  )rN   r   r5  r   r4  r   s      @@@rT   #_generate_reformatted_field_content9Deb822ParsedTokenList._generate_reformatted_field_content  sq    99;%%
	B DOO 00;;1AA/BVBVW'M 	rW   c                 N    SR                  S U R                  5        5       5      $ )Nr2  c              3   8   #    U  H  oR                   v   M     g 7frK   r  r   r   s     rT   r   @Deb822ParsedTokenList._generate_field_content.<locals>.<genexpr>  s     F'E!vv'E   )joinr.  r_   s    rT   _generate_field_content-Deb822ParsedTokenList._generate_field_content  s     wwFt'C'C'EFFFrW   c                    U R                   nUR                  nU R                  nUR                  nSnU R	                  5        H+  nSnUR
                  (       a  M  UR                  (       a  M+    O   U(       a  [        S5      eUb  [        U[        5      (       a  UR
                  (       a  [        S5      eUR                  5       R                  S5      (       d  U R                  5         U R                  (       a#  U R                  5       nSR                  X'45      nOU R!                  5       nUR#                  SS9n	OUS-   /n	[%        ['        U	5      5      n
U
R)                  5       nU(       a  [        S	U-   5      e[+        ['        U
5      5      n[        U[,        5      (       d   eUR/                  U5      nUc   eU$ )
NFTzUField must be completely empty or have content (i.e. non-whitespace and non-comments)z Fields must not end on a commentr   :keependsz:
$Syntax error in new field value for )r   r7  r   r   r.  r   r   r   r   r!   r  r  r  r   rA  r@  r8  
splitlinesparse_deb822_filer   find_first_error_elementr   'Deb822NoDuplicateFieldsParagraphElementget_kvpair_element)rN   r   r7  r4  r   
had_tokensr   
value_textr  new_contentdeb822_fileerror_token	paragraphnew_kvpair_elements                 rT   _generate_kvpair&Deb822ParsedTokenList._generate_kvpair  s   --#..
%%

--/AJ<<< 0
   "J K K$,, !CDD'')22488##%88!99;
xx 89??A//4/8K
 &-.K ([(9:!::<CjPQQk*+	)%LMMMM&99*E!---!!rW   )with_field_namerV  c                l    U R                  5       nU(       a  UOUR                  nUR                  5       $ rK   )rT  value_elementr  )rN   rV  kvpairelements       rT   r  %Deb822ParsedTokenList.convert_to_textB  s.    &&(+&1E1E&&((rW   c                 h    U R                   nU R                  5       R                  Ul        SU l        g r  )r   rT  rX  r   )rN   r   s     rT   r   #Deb822ParsedTokenList._update_fieldG  s+    --'+'<'<'>'L'L$rW   keyreversec                8  ^^ SnU R                   nU R                  mU4S jn/ nU R                  R                  5        H  nUR                  n[        U[        5      (       a  UR                  (       a  Uc  UnM<  [        X5      (       d  MN  / n	Ub7  UR                  SS9 H$  n
XL a    OU	R                  U
R                  5        M&     UR                  X45        SnM     UR                  XRS9  SU l        U R                  R                  5         SnU R                  5       R                  nU H  u  pU(       a?  SnU	(       a5  U	 Vs/ s H  n[        UT5      (       a  M  UPM     n	nU R                  5         OlU(       d)  [!        U4S jU	 5       5      (       d  U R#                  SS9  U	(       a  U R                  5         O$U R                  R                  [%        S	5      5        U R                  R'                  U	5        U R)                  U5        M     gs  snf )
a  Sort the elements (abstract values) in this list.

This method will sort the logical values of the list. It will
attempt to preserve comments associated with a given value where
possible.  Whether space and separators are preserved depends on
the contents of the field as well as the formatting settings.

Sorting (without reformatting) is likely to leave you with "awkward"
whitespace. Therefore, you almost always want to apply reformatting
such as the reformat_when_finished() method.

Sorting will invalidate all ValueReferences.
Nc                 N   > T(       a  T" U S   5      $ U S   R                  5       $ Nr   r  )xr_  s    rT   key_func5Deb822ParsedTokenList.sort_elements.<locals>.key_funcb  s'    1Q4y Q4''))rW   Fr   r^  Tc              3   <   >#    U  H  n[        UT5      v   M     g 7frK   )r   )r   re  r   s     rT   r   6Deb822ParsedTokenList.sort_elements.<locals>.<genexpr>  s     5]T\qjE6J6JT\s   )r   r   )r   r   r   r   r^   r   r!   r   r   r   sortr   r   r   r   r  anyr   r&   extendr   )rN   r_  r`  comment_start_noder   rf  r   rO   r^   comments	keep_nodefirst_valueseparator_is_spacere  r   s    `            @rT   sort_elements#Deb822ParsedTokenList.sort_elementsL  s   $ "	* $$//1DJJE%--%2B2B%-)-&%''%1%7%A%Au%A%U	$,! 	8 &V e./%)" 2" 	

x
1 !<<>LL$OE# ,4P8a:a;O8HP ''))#5]T\5]2]2]
 )))F'')$$++,A#,FG##H-e$/  %  Qs   H!Hr_  c                ^   ^^ Tb  U R                   mUU4S jUS'   U R                  " S0 UD6  g)a  Sort the values (rendered as str) in this list.

This method will sort the logical values of the list. It will
attempt to preserve comments associated with a given value where
possible.  Whether space and separators are preserved depends on
the contents of the field as well as the formatting settings.

Sorting (without reformatting) is likely to leave you with "awkward"
whitespace. Therefore, you almost always want to apply reformatting
such as the reformat_when_finished() method.

Sorting will invalidate all ValueReferences.
Nc                     > T" T" U 5      5      $ rK   ru   )r   r_  rP   s    rT   <lambda>,Deb822ParsedTokenList.sort.<locals>.<lambda>  s    s6":rW   r_  ru   )rF   rr  )rN   r_  kwargsrP   s    ` @rT   rj  Deb822ParsedTokenList.sort  s-    & ?\\F6F5M$V$rW   )__continuation_line_charr   r   r   r   r   r   rF   r   r   r   rG   r   rj   TF)r\   rA   )+rk   rl   rm   rn   rU   r   boolr   r   rq   r   r   r=   r   r   r   r   r   rh   r   r   r   r  r  r  rr   r  r   r  r  r!  r&  r   r.  r8  rA  rT  r  r   rr  rj  rt   __classcell__r   s   @rT   r   r      s+   "#H?2$ 2; O O$H^4 $
$@B1"rFh
.Jd J@
/ 
 
 
`
:9
 (-!$!S 6G G."` :? )$ )3 )
 #N%d % %rW   r   zDeb822ParsedTokenList[VE, ST]c                        \ rS rSr SS jrSrg)Interpretationi  c                     [         erK   NotImplementedError)rN   r   discard_comments_on_reads      rT   	interpretInterpretation.interpret  
    
 "!rW   ru   Nr|  )rk   rl   rm   rn   r  rt   ru   rW   rT   r  r    s     ,0"rW   r  c                   R   ^  \ rS rSrU 4S jr S	S jrS rS rS r S	S jr	Sr
U =r$ )
!GenericContentBasedInterpretationi  c                 :   > [         TU ]  5         Xl        X l        g rK   )r   rU   
_tokenizer_value_parser)rN   	tokenizervalue_parserr   s      rT   rU   *GenericContentBasedInterpretation.__init__  s    
 	#)rW   c                     [         erK   r  rN   r   proxy_elementr  s       rT   _high_level_interpretation<GenericContentBasedInterpretation._high_level_interpretation  
     "!rW   c              #      #    U R                   nU H(  n[        U[        5      (       a  U" X15      v   M$  Uv   M*     g 7frK   )r  r   r"   )rN   buffered_iteratorr  r  s       rT   _parse_stream/GenericContentBasedInterpretation._parse_stream  s:     
 ))&E%!122"5<<	 's   <>c                     UR                   nUR                  5       n/ nUR                  U R                  U5      5        [	        X$5      $ rK   )rX  r  rl  
_parse_str Deb822InterpretationProxyElement)rN   rY  rX  contentr4  s        rT   _parse_kvpair/GenericContentBasedInterpretation._parse_kvpair  sD    
 ,,//1
$//'23/JJrW   c              #      #    [        U5      n[        [        UU R                  U5      US95      n[        UU R	                  U5      US9 S h  vN   g  N7f)N)content_len)lenr   r   r  r  )rN   r  r  biters       rT   r  ,GenericContentBasedInterpretation._parse_str  sZ     'l!"4W59__W5MAL#O P &g&*&8&8&?2=( 	( 	(s   AAAAc                 F    U R                  U5      nU R                  UUUS9$ N)r  )r  r  )rN   r   r  r  s       rT   r  +GenericContentBasedInterpretation.interpret  s4    
 **>:..~/<H` / 1 	1rW   )r  r  r|  )rk   rl   rm   rn   rU   r  r  r  r  r  rt   r  r  s   @rT   r  r    s2    * =A"
	K	( ,0	1 	1rW   r  c                    ^ ^ U U4S jnU$ )Nc                   > U S:X  a  [        S5      e[        T" U 5      5      n[        US 5      n[        US 5      nUc   SU -   S-   5       eUb.  [        R                  " S5      R                  U S9n[        U5      e[        UT5      (       dh  [        U[        5      (       a-  UR                  (       d  UR                  (       a  [        S5      eSn[        UR                  U TR                  US	95      e[        UR                  5       5      [        U 5      :X  d5   S
R                  [        UR                  5       5      [        U 5      S95       eU$ )Nr2  zThe empty string is not a valuez.Bad parser - it returned None (or no TE) for ""z            The input "{v}" should have been exactly one element, but the parser provided at
             least two.  This can happen with unnecessary leading/trailing whitespace
             or including commas the value for a comma list.
            r   z<The input "{v}" is whitespace or a comment: Expected a valuezaThe input "{v}" should have produced a element of type {vtype_name}, but instead it produced {t1})r   
vtype_namet1zSBad tokenizer - the token did not cover the input text exactly ({t1_len} != {v_len})t1_lenv_len)r   r   r   textwrapdedentformatr   r!   r   r   rk   r  r  )r   
token_iterr  t2msgparserr   s        rT   rG   0_parser_to_value_factory.<locals>._value_factory  s=   7>??&)_
*d#*d#~YORSSVYYY~>// #  !	 
 S/!"e$$"k**AQAQ !_``.CSZZ!2ZNOO2%%'(CF2 	,,2F2--/0A -3 -	2
 	rW   ru   )r  r   rG   s   `` rT   r   r      s    : rW   c                   4   ^  \ rS rSrU 4S jr SS jrSrU =r$ )ListInterpretationi$  c                 T   > [         TU ]  X5        X0l        X@l        XPl        X`l        g rK   )r   rU   r   r   r   _render_factory)rN   r  r  r   r   r   render_factoryr   s          rT   rU   ListInterpretation.__init__&  s(     	1*C'-rW   c                     [        UUU R                  U R                  U R                  U R                  U R                  U5      5      $ rK   )r   r   r   r  r   r  r  s       rT   r  -ListInterpretation._high_level_interpretation5  sD     %KKKKOO++  !9:
 	
rW   )r   r  r   r   r|  )rk   rl   rm   rn   rU   r  rt   r  r  s   @rT   r  r  $  s    .$ =A
 
rW   r  c                     [        U /5      $ rK   )Deb822ParsedValueElement)r  _s     rT   _parse_whitespace_list_valuer  F  s    #UG,,rW   c                 "    [        U [        5      $ rK   )r   r)   r  s    rT   _is_comma_tokenr  K  s     a)**rW   c                    UR                  [        5      nU /nUb$  UR                  UR                  US-
  5      5        OUR                  UR	                  5       5        U(       aI  [        US   [        5      (       d1  UR                  5         U(       a  [        US   [        5      (       d  M1  UR                  [        U5      S-
  5        [        U5      $ )N   )	peek_findr  rl  	peek_manypeek_bufferr   r"   r   consume_manyr  r  )r  r  comma_offsetr   s       rT   _parse_comma_list_valuer  Q  s    $..?L'K,66|a7GHI 	,88:;
jR:JKK jR:JKK ""3{#3a#78#K00rW   c                    U /nSnUGb  UR                  [        5      nUGb9  US   /nUR                  UR                  US-
  5      5        Sn[	        U5      S-
  nUS:  a  XF   n [        U [        5      (       a  U R                  R                  S5      (       ap  UR                  UR                  U5      5        [        US   [        5      (       a#  US   R                  R                  S5      (       d   S[        U5      -   5       eSnOUS-  nUS:  a  M  U(       a  OUR                  UR                  U5      5        [        US   [        5      (       d   eOUR                  5       n[	        U5      nUR                  U5        U(       aN  [        US   [        5      (       d6  UR                  5         US-  nU(       a  [        US   [        5      (       d  M6  UR                  U5        Ub  GM  [        U5      $ )Nr  r  Fr   >zGot: T)r  r  rl  r  r  r   r"   r  r  r  rr   r)   r  r   r  )	r  r  r   r  peeked_elementscomma_was_separatoriremaining_partconsume_elementss	            rT   _parse_uploaders_list_valuer  c  s   
 'KL

"(22?C#  +2/O""#4#>#>|a?O#PQ"'O$q(Aq&'*e%566zz**3//#**+<+I+I!+LM)+b/;KLL*233<<SAA^CJSQ\M]C]^  B.2+Q q& #0==lKLk"o/?@@@@ /::<N">2~.jRBR&S&S! A%  jRBR&S&S **+;<I 
"L $K00rW   c                      \ rS rSrSrSrSS jrS rS rS	 r	S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 5       r\R$                  S 5       rSS jrS\4S jrS rS\4S jrSrg)r+  i  z1Composite elements (consists of 1 or more tokens))_parent_element_full_size_cache__weakref__r\   Nc                      S U l         S U l        g rK   )r  r  r_   s    rT   rU   Deb822Element.__init__  s    # $rW   c                     [         erK   r  r_   s    rT   r   Deb822Element.iter_parts      !!rW   c              #   f   #    U R                  5        H  n[        X!5      (       d  M  Uv   M     g 7frK   )r   r   rN   only_element_or_token_typeparts      rT   iter_parts_of_type Deb822Element.iter_parts_of_type  s&     OO%D$;;
 &s   "1	1c              #      #    U R                  5        HE  nUR                  c   e[        U[        5      (       a  UR	                  5        S h  vN   MA  Uv   MG     g  N7frK   )r   r  r   r+  r,  rN   r  s     rT   r,  Deb822Element.iter_tokens  sQ     OO%D''333$..++---
 & .s   AAAAr  c             #      #    U R                  5        HR  nUb  [        X!5      (       a  [        SU5      v   [        U[        5      (       d  M;  UR	                  US9 S h  vN   MT     g  N	7f)Nr;   r  )r   r   r   r+  iter_recurser  s      rT   r  Deb822Element.iter_recurse  s`      OO%D)1Z5a5a4&&$..,,Hb,ccc	 & ds   AA,A, A*!
A,c                     gr  ru   r_   s    rT   is_errorDeb822Element.is_error      rW   c                     gr  ru   r_   s    rT   r   Deb822Element.is_comment  r  rW   c                     gr  ru   r_   s    rT   r   Deb822Element.is_whitespace  r  rW   c                     gr  ru   r_   s    rT   is_separatorDeb822Element.is_separator  r  rW   c                 ,    [        U R                  5      $ rK   )r2   r  r_   s    rT   parent_elementDeb822Element.parent_element  s     4//00rW   c                 P    Ub  [         R                  " U5      U l        g S U l        g rK   )rL   rM   r  )rN   
new_parents     rT   r  r    s#     ;E:Pw{{:6VZrW   c                 >    U R                  5        H	  nXl        M     g rK   )r   r  r  s     rT   _init_parent_of_parts#Deb822Element._init_parent_of_parts  s    OO%D"& &rW   c                 N    SR                  S U R                  5        5       5      $ )Nr2  c              3   8   #    U  H  oR                   v   M     g 7frK   r<  r=  s     rT   r   0Deb822Element.convert_to_text.<locals>.<genexpr>  s     :'9!vv'9r?  r@  r,  r_   s    rT   r  Deb822Element.convert_to_text  s     ww:t'7'7'9:::rW   c                 0    XR                   L a  S U l        g g rK   )r  r  rN   parents     rT   clear_parent_if_parent$Deb822Element.clear_parent_if_parent  s    (((#'D  )rW   c                     U R                   nUc6  [        R                  " [        S U R	                  5        5       5      nXl         U$ )Nc              3   @   #    U  H  oR                  5       v   M     g 7frK   sizer   ps     rT   r   %Deb822Element.size.<locals>.<genexpr>       5#4a#4   )r  r    from_position_and_sizesr   r   )rN   
size_caches     rT   r  Deb822Element.size  sC    **
6654??#45J %/!rW   )r  r  rj   )rk   rl   rm   rn   ro   rp   rU   r   r  r,  r  rq   r~  r  r   r   r  r  rs   r   rr   r  r
  r    r  rt   ru   rW   rT   r+  r+    s    ;FI%" 15d $   D   t   d   1 1 [ ['
; ;(
e rW   r+  c                   r   ^  \ rS rSrSrS\S\\   SS4U 4S jjrS r	S\
4S	 jrS\
4S
 jrS\4S jrSrU =r$ )r  i  )r   real_elementr   r\   Nc                 X   > [         TU ]  5         Xl        X l        U H	  nXl        M     g rK   )r   rU   r  r   )rN   r  r   r  r   s       rT   rU   )Deb822InterpretationProxyElement.__init__  s)    *
A# rW   c                 ,    [        U R                  5      $ rK   )r   r   r_   s    rT   r   +Deb822InterpretationProxyElement.iter_parts  s    DJJrW   c                 V    U R                   nUc  [        S5      eUR                  5       $ Nzparent was garbage collected)r  rY   position_in_parentr  s     rT   r   3Deb822InterpretationProxyElement.position_in_parent  s-    $$>=>>((**rW   c                 V    U R                   nUc  [        S5      eUR                  5       $ r  )r  rY   position_in_filer  s     rT   r#  1Deb822InterpretationProxyElement.position_in_file  s-    $$>=>>&&((rW   c                 f    S U R                  5        5       n[        R                  " [        U5      $ )Nc              3   @   #    U  H  oR                  5       v   M     g 7frK   r  r  s     rT   r   8Deb822InterpretationProxyElement.size.<locals>.<genexpr>	  r  r  )r   r    r  r   )rN   sizess     rT   r  %Deb822InterpretationProxyElement.size  s&    54??#45,,^UCCrW   )r  r   )rk   rl   rm   rn   rp   r+  r   r=   rU   r   r   r   r#  r    r  rt   r  r  s   @rT   r  r    sY    I$] $4;O $TX $ +H +)( )De D DrW   r  c                   N   ^  \ rS rSrSrSrU 4S jrS r\S\	4S j5       r
SrU =r$ )Deb822ErrorElementi  ah  Element representing elements or tokens that are out of place

Commonly, it will just be instances of Deb822ErrorToken, but it can be other
things.  As an example if a parser discovers out of order elements/tokens,
it can bundle them in a Deb822ErrorElement to signal that the sequence of
elements/tokens are invalid (even if the tokens themselves are valid).
_partsc                 b   > [         TU ]  5         [        U5      U l        U R	                  5         g rK   )r   rU   tupler-  r   )rN   r   r   s     rT   rU   Deb822ErrorElement.__init__  s%    El""$rW   c              #   8   #    U R                    S h  vN   g  N7frK   r,  r_   s    rT   r   Deb822ErrorElement.iter_parts  s     ;;r   r\   c                     gr   ru   r_   s    rT   r  Deb822ErrorElement.is_error"      rW   )rk   rl   rm   rn   ro   rp   rU   r   rq   r~  r  rt   r  r  s   @rT   r+  r+    s4     I% $  rW   r+  c                      ^  \ rS rSrSrSrU 4S jr\S 5       r\S 5       r	\S 5       r
S\4S	 jrS
 rS rS\4S jrS rSrU =r$ )Deb822ValueLineElementi'  z!Consists of one "line" of a value)_comment_element_continuation_line_token_leading_whitespace_token_value_tokens_trailing_whitespace_token_newline_tokenc                    > [         TU ]  5         Ub  Uc  [        S5      eXl        X l        UU l        X@l        XPl        X`l        U R                  5         g )Nz)Only continuation lines can have comments)
r   rU   r   r8  r9  r:  r;  r<  r=  r   )rN   comment_elementcontinuation_line_tokenleading_whitespace_tokenr   trailing_whitespace_tokennewline_tokenr   s          rT   rU   Deb822ValueLineElement.__init__-  s]     	&+B+JHII /(?%$ 	&(*C'+""$rW   c                     U R                   $ rK   r8  r_   s    rT   r?  &Deb822ValueLineElement.comment_elementD       $$$rW   c                     U R                   $ rK   )r9  r_   s    rT   r@  .Deb822ValueLineElement.continuation_line_tokenI  s     ,,,rW   c                     U R                   $ rK   )r=  r_   s    rT   rC  $Deb822ValueLineElement.newline_tokenN       """rW   r\   c                 l    U R                   c'  [        5       U l         X R                   l        S U l        ggr   )r=  r(   r  r  r_   s    rT   add_newline_if_missing-Deb822ValueLineElement.add_newline_if_missingS  s3    &">"@D15.$(D!rW   c              #      #    U R                   (       a  U R                   v   U R                   S h  vN   U R                  (       a  U R                  v   g g  N%7frK   )r:  r;  r<  r_   s    rT   _iter_content_parts*Deb822ValueLineElement._iter_content_parts[  sH     ))000%%%%**111 + 	&s   /AA&Ac              #      #    U R                  5        H6  n[        U[        5      (       a  UR                  5        S h  vN   M2  Uv   M8     g  N7frK   )rR  r   r+  r,  r  s     rT   _iter_content_tokens+Deb822ValueLineElement._iter_content_tokensc  s?     ,,.D$..++---
	 /-s   <AAAc                 :   [        U R                  5      S:X  a]  U R                  (       dL  U R                  (       d;  [	        U R                  S   [
        5      (       a  U R                  S   R                  $ SR                  S U R                  5        5       5      $ )Nr  r   r2  c              3   8   #    U  H  oR                   v   M     g 7frK   r<  r=  s     rT   r   ADeb822ValueLineElement.convert_content_to_text.<locals>.<genexpr>u  s     C'B!vv'Br?  )	r  r;  r:  r<  r   r!   r  r@  rU  r_   s    rT   convert_content_to_text.Deb822ValueLineElement.convert_content_to_textk  sv    t!!"a'6677t11!4kBB %%a(---wwCt'@'@'BCCCrW   c              #      #    U R                   (       a  U R                   v   U R                  (       a  U R                  v   U R                  5        S h  vN   U R                  (       a  U R                  v   g g  N%7frK   )r8  r9  rR  r=  r_   s    rT   r   !Deb822ValueLineElement.iter_partsw  s`       '''((///++---%%%  	.s   AA<A:&A<)r8  r9  r  r:  r=  r<  r;  )rk   rl   rm   rn   ro   rp   rU   rq   r?  r@  rC  r~  rO  rR  rU  rr   rZ  r   rt   r  r  s   @rT   r7  r7  '  s}    +RI%. % % - - # # 2
D 
D& &rW   r7  c                   P   ^  \ rS rSrSrU 4S jr\S 5       rS rS\	4S jr
SrU =r$ )	Deb822ValueElementi  _value_entry_elementsc                 d   > [         TU ]  5         [        U5      nX l        U R	                  5         g rK   )r   rU   r/  ra  r   )rN   value_entry_elementsr   r   s      rT   rU   Deb822ValueElement.__init__  s+    &'%&"""$rW   c                     U R                   $ )zRead-only list of value entriesr`  r_   s    rT   value_linesDeb822ValueElement.value_lines  s     )))rW   c              #   8   #    U R                    S h  vN   g  N7frK   r`  r_   s    rT   r   Deb822ValueElement.iter_parts  s     ----r   r\   c                     U R                   (       a-  U R                   S   R                  5       nU(       a  S U l        U$ g)Nr  F)ra  rO  r  )rN   changeds     rT   add_final_newline_if_missing/Deb822ValueElement.add_final_newline_if_missing  s7    %%004KKMG(,%NrW   )r  ra  )rk   rl   rm   rn   rp   rU   rq   rf  r   r~  rl  rt   r  r  s   @rT   r_  r_    s7    *I% * *
.d  rW   r_  c                   T   ^  \ rS rSrSrU 4S jrS\4U 4S jjrS\4S jrS r	Sr
U =r$ )r  i  )_text_cached_text_no_comments_cachedr   c                 |  > [         TU ]  5         Xl        U R                  5         [	        US   [
        5      (       a  [	        US   [
        5      (       d"  [        U R                  R                  S-   5      e[        U5      S:X  a(  US   nUR                  U l        UR                  U l        g S U l        S U l        g )Nr   r  z) MUST start and end on a Deb822ValueTokenr  )r   rU   r   r   r   r"   r   r   rk   r  r  ro  rp  )rN   tokensr  r   s      rT   rU   !Deb822ParsedValueElement.__init__  s    !""$&)%566vbz+;<<T^^447bbccv;!1IE %

D,1JJD) $D,0D)rW   r\   c                 \   > U R                   c  [        TU ]	  5       U l         U R                   $ rK   )rp  r   r  )rN   r   s    rT   r  (Deb822ParsedValueElement.convert_to_text  s+    ((0,1G,C,ED),,,rW   c                     U R                   c+  SR                  S U R                  5        5       5      U l         U R                   $ )Nr2  c              3   `   #    U  H$  nUR                   (       a  M  UR                  v   M&     g 7frK   r   r  r=  s     rT   r   LDeb822ParsedValueElement.convert_to_text_without_comments.<locals>.<genexpr>  s%      4I=O;<<< 5;AFF=O   ..)rp  r@  r,  r_   s    rT    convert_to_text_without_comments9Deb822ParsedValueElement.convert_to_text_without_comments  sF    ((0,.GG 4I=A=M=M=O4I -ID) ,,,rW   c              #   8   #    U R                    S h  vN   g  N7frK   r   r_   s    rT   r   #Deb822ParsedValueElement.iter_parts  s     ####r   )rk   rl   rm   rn   rp   rU   rr   r  r{  r   rt   r  r  s   @rT   r  r    s/    KI1 - -
-# -$ $rW   r  c                   ^   ^  \ rS rSrSrU 4S jr\S\4S j5       rS\	4S jr
S rS rSrU =r$ )	Deb822CommentElementi  _comment_tokensc                    > [         TU ]  5         [        U5      U l        U(       d  [	        S5      eU R                  5         g )Nz5Comment elements must have at least one comment token)r   rU   r/  r  r   r   )rN   comment_tokensr   s     rT   rU   Deb822CommentElement.__init__  s6    $^4TUU""$rW   r\   c                     gr   ru   r_   s    rT   r   Deb822CommentElement.is_comment  r5  rW   c                 ,    [        U R                  5      $ rK   )r  r  r_   s    rT   __len__Deb822CommentElement.__len__  s    4''((rW   c                      U R                   U   $ rK   r  rN   items     rT   __getitem__ Deb822CommentElement.__getitem__  s    ##D))rW   c              #   8   #    U R                    S h  vN   g  N7frK   r  r_   s    rT   r   Deb822CommentElement.iter_parts  s     ''''r   )rk   rl   rm   rn   rp   rU   rq   r~  r   intr  r  r   rt   r  r  s   @rT   r  r    sC    $I% D  ) )*( (rW   r  c                      ^  \ rS rSrSrU 4S jr\S 5       r\S 5       r\S 5       r	\	R                  S 5       r	 SS jr\S	 5       r\R                  S
 5       rS rSrU =r$ )rA   i  r8  _field_token_separator_token_value_elementc                 r   > [         TU ]  5         Xl        X l        X0l        X@l        U R                  5         g rK   )r   rU   r8  r  r  r  r   )rN   r?  field_tokenr   rX  r   s        rT   rU   "Deb822KeyValuePairElement.__init__  s4     	 /' /+""$rW   c                 .    U R                   R                  $ rK   )r  r  r_   s    rT   r7  $Deb822KeyValuePairElement.field_name  s     $$$rW   c                     U R                   $ rK   )r  r_   s    rT   r  %Deb822KeyValuePairElement.field_token  s        rW   c                     U R                   $ rK   )r  r_   s    rT   rX  'Deb822KeyValuePairElement.value_element  rM  rW   c                 `    S U l         U R                  R                  U 5        Xl        Xl        g rK   )r  r  r
  r  rb   s     rT   rX  r     s,     !%2248'#' rW   c                      UR                  XS9$ r  )r  )rN   interpreterr  s      rT   interpret_as&Deb822KeyValuePairElement.interpret_as  s    
 $$T$]]rW   c                     U R                   $ rK   rF  r_   s    rT   r?  )Deb822KeyValuePairElement.comment_element  rH  rW   c                     S U l         Ub.  US   R                  R                  S5      (       d  [        S5      eU R                  (       a  U R                  R                  U 5        Ub  Xl        Xl        g )Nr  r   z&Field comments must end with a newline)r  r  r  r   r8  r
  r  )rN   r^   s     rT   r?  r    sf     !%9>>**400 !IJJ  !!88>#'  %rW   c              #      #    U R                   (       a  U R                   v   U R                  v   U R                  v   U R                  v   g 7frK   r  r_   s    rT   r   $Deb822KeyValuePairElement.iter_parts!  s>       '''###!!!s   AA)r8  r  r  r  r  r|  )rk   rl   rm   rn   rp   rU   rq   r7  r  rX  rs   r  r?  r   rt   r  r  s   @rT   rA   rA     s    ZI% % % ! ! # # ( ( /3^ % % 
& 
&" "rW   c                     U S:X  a  gSU S S ;   a  [        S5      eU R                  S5      (       d  U R                  5       S-   n U R                  S5      (       d  SU R	                  5       -   n U $ )Nr2  z#
r   r  z-Comment lines must not have embedded newlines#z# )r   r  rstrip
startswithlstrip)cs    rT   r
  r
  *  sh    Bwq"v~HII::dHHJ<<188:HrW   Fc                    S nS n[        U [        5      (       a9  U u  pBU(       a"  US:w  a  Sn[        UR                  XBS95      eS n[	        U5      nO1S n[        U [
        5      (       a  U nUR                  nO[	        U 5      nXBU4$ )Nr   zECannot resolve key "{key}" with index {index}. The key is not indexedr_  index)r   r/  KeyErrorr  r6   r*   r  )r  raise_if_indexedr  
name_tokenr_  r  s         rT   _unpack_keyr  8  s     EJ$
 z]szzcz?@@ECjd011J//C+Cz!!rW   c              #      #    U(       d  S U  5        S h  vN   g U  H+  nSR                  S UR                  5        5       5      v   M-     g  N77f)Nc              3   @   #    U  H  oR                  5       v   M     g 7frK   rd  )r   r   s     rT   r   0_convert_value_lines_to_lines.<locals>.<genexpr>X  s     =A%%''r  r2  c              3   `   #    U  H$  nUR                   (       a  M  UR                  v   M&     g 7frK   rx  r   re  s     rT   r   r  [  s$      /*?Q!" !!&&*?rz  r  )rf  strip_commentsrZ  s      rT   _convert_value_lines_to_linesr  S  sM      ===="G'' /'*=*=*? / / / # 	>s   AA8Ac                       \ rS rSrSrg)_ParagraphMapping_Baseid  ru   N)rk   rl   rm   rn   rt   ru   rW   rT   r  r  d  s    rW   r  c                   h    \ rS rSr\S\4S j5       r\S 5       rS\4S jr	S r
S rS rS	 rS
 rSrg)AutoResolvingMixinik  r\   c                     gr   ru   r_   s    rT   _auto_resolve_ambiguous_fields1AutoResolvingMixin._auto_resolve_ambiguous_fieldsm  r5  rW   c                     [         erK   r  r_   s    rT   
_paragraphAutoResolvingMixin._paragraphq  
     "!rW   c                 .    U R                   R                  $ rK   )r  kvpair_countr_   s    rT   r  AutoResolvingMixin.__len__v  s    +++rW   c                 8    U R                   R                  U5      $ rK   )r  contains_kvpair_elementr  s     rT   __contains__AutoResolvingMixin.__contains__y  s    66t<<rW   c                 H    [        U R                  R                  5       5      $ rK   )r   r  	iter_keysr_   s    rT   r   AutoResolvingMixin.__iter__}  s    DOO--/00rW   c                     U R                   (       a3  [        U[        5      (       a  U R                  R	                  US45      nOU R                  R	                  U5      nUc   eU R                  X5      $ rc  )r  r   rr   r  rL  _interpret_value)rN   r  r   s      rT   r  AutoResolvingMixin.__getitem__  s^    ..:dC3H3H22D!9=A2248A}}$$T--rW   c                 :    U R                   R                  U5        g rK   )r  remove_kvpair_elementr  s     rT   __delitem__AutoResolvingMixin.__delitem__  s    --d3rW   c                     [         erK   r  rN   r_  r^   s      rT   r  #AutoResolvingMixin._interpret_value  r  rW   ru   N)rk   rl   rm   rn   rq   r~  r  r  r  r  r  r   r  r  r  rt   ru   rW   rT   r  r  k  sT       " ", ,=1.4"rW   r  c                       \ rS rS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 r
S rS	 rS
rg) Deb822ParagraphToStrWrapperMixini  r\   c                     gr   ru   r_   s    rT   !_auto_map_initial_line_whitespaceBDeb822ParagraphToStrWrapperMixin._auto_map_initial_line_whitespace  r5  rW   c                     gr   ru   r_   s    rT   _discard_comments_on_read:Deb822ParagraphToStrWrapperMixin._discard_comments_on_read  r5  rW   c                     gr   ru   r_   s    rT   +_auto_map_final_newline_in_multiline_valuesLDeb822ParagraphToStrWrapperMixin._auto_map_final_newline_in_multiline_values  r5  rW   c                     gr   ru   r_   s    rT   )_preserve_field_comments_on_field_updatesJDeb822ParagraphToStrWrapperMixin._preserve_field_comments_on_field_updates  r5  rW   c                   ^ UR                   nUR                  n[        U5      S:X  a8  US   nUR                  5       nU R                  (       a  UR                  5       nU$ U R                  (       d  U R                  (       aF  [        UU R                  5      nU R                  mSR                  U4S j[        USS9 5       5      nOUR                  5       nU R                  (       a  US   S:X  a  US S nU$ )Nr  r   r2  c              3   l   >#    U  H)  u  pT(       a  US :X  a  UR                  5       S-   OUv   M+     g7f)r  r   N)strip)r   r  lineauto_map_spaces      rT   r   IDeb822ParagraphToStrWrapperMixin._convert_value_to_str.<locals>.<genexpr>  s4       -J'! 6DQdjjlT1TXX-Js   14startr  r   )rX  rf  r  r  r  r  r  r  r@  	enumerater  )	rN   r   rX  value_entriesvalue_entryr   	converteras_textr  s	           @rT   _convert_value_to_str6Deb822ParagraphToStrWrapperMixin._convert_value_to_str  s    &44%11}" (*K++-A55GGIH11T5S5S5m6:6T6T8I "CCN gg  -6y-J   G
 $335G;;t@ScrlGrW   c                 $   U R                   nS nU(       aW  U R                  (       aF  S nUn[        U[        5      (       a  US4nU R                  R                  USS9nUb  UR                  nU R                  (       a   UR                  S5      nUS:X  d  U[        U5      :X  a+  U R                  R                  UUR                  5       UUS9  g UR                  SS5      u  pU(       a-  US S S;  a$  S	R                  S
UR                  5       SU	45      nOS	R                  USU	45      nUR                  S5      (       d!  U R                   (       d  [        S5      eUS-  nU R                  R#                  UUUUS9  g ! [         a    Sn Nf = f)Nr   Tuse_getr   r  preserve_original_field_commentfield_commentr  )	r   r2  r   zeValues must end with a newline (or be single line values and use the auto whitespace mapping feature))r  r  r   rr   r  rL  r?  r  r  r   r  set_field_to_simple_valuer  splitr@  r  r  set_field_from_raw_string)
rN   r  r^   keep_commentscomment
key_lookuporig_kvpairidx
first_linerests
             rT   __setitem__,Deb822ParagraphToStrWrapperMixin.__setitem__  s   FFT@@
 !MJ$$$"AY
//<<ZQU<VK&%5511kk$' byC3u:-99KKM4A")	 :  ${{43Jj!nK?j&6&6&8$ EFT4 89~~d##CC  "X Y YTME11,9!	 	2 	
+  s   ?F   FFc                 $    U R                  U5      $ rK   )r  r  s      rT   r  1Deb822ParagraphToStrWrapperMixin._interpret_value  s     ))%00rW   ru   N)rk   rl   rm   rn   rq   r~  r  r  r  r  r  r  r  rt   ru   rW   rT   r  r    s     4   4   T   4  B.
`1rW   r  c                   d    \ rS rSrSSS.S jr\S 5       r\S\4S j5       r\S\4S	 j5       r	S
r
g)AbstractDeb822ParagraphWrapperi   FTauto_resolve_ambiguous_fieldsr  c                (    Xl         X l        X0l        g rK   )*_AbstractDeb822ParagraphWrapper__paragraph>_AbstractDeb822ParagraphWrapper__auto_resolve_ambiguous_fields9_AbstractDeb822ParagraphWrapper__discard_comments_on_read)rN   rR  r  r  s       rT   rU   'AbstractDeb822ParagraphWrapper.__init__  s     %/L,*B'rW   c                     U R                   $ rK   )r  r_   s    rT   r  )AbstractDeb822ParagraphWrapper._paragraph  s     rW   r\   c                     U R                   $ rK   )r  r_   s    rT   r  8AbstractDeb822ParagraphWrapper._discard_comments_on_read  s    ...rW   c                     U R                   $ rK   )r  r_   s    rT   r  =AbstractDeb822ParagraphWrapper._auto_resolve_ambiguous_fields  s    333rW   )__auto_resolve_ambiguous_fields__discard_comments_on_read__paragraphN)rk   rl   rm   rn   rU   rq   r  r~  r  r  rt   ru   rW   rT   r  r     sZ    
 05*.		C     /4 / / 4 4 4rW   r  c                   8   ^  \ rS rSrSSS.U 4S jjrS rSrU =r$ )"Deb822InterpretingParagraphWrapperi  FTr  c                0   > [         TU ]  UUUS9  X l        g Nr  )r   rU   _interpretation)rN   rR  interpretationr  r  r   s        rT   rU   +Deb822InterpretingParagraphWrapper.__init__  s'     	7T2J 	 	  .rW   c                 8    U R                   R                  U5      $ rK   )r&  r  r  s      rT   r  3Deb822InterpretingParagraphWrapper._interpret_value+  s    ##--e44rW   )r&  )rk   rl   rm   rn   rU   r  rt   r  r  s   @rT   r#  r#    s     05*.. .5 5rW   r#  c                      ^  \ rS rSrSSSSSS.U 4S jjr\S\4S j5       r\S\4S j5       r\S\4S	 j5       r	S
r
U =r$ )Deb822DictishParagraphWrapperi0  TFr   auto_map_initial_line_whitespacer  (preserve_field_comments_on_field_updates*auto_map_final_newline_in_multiline_valuesc                J   > [         TU ]  UUUS9  X0l        XPl        UU l        g r%  )r   rU   @_Deb822DictishParagraphWrapper__auto_map_initial_line_whitespaceH_Deb822DictishParagraphWrapper__preserve_field_comments_on_field_updatesJ_Deb822DictishParagraphWrapper__auto_map_final_newline_in_multiline_values)rN   rR  r  r.  r  r/  r0  r   s          rT   rU   &Deb822DictishParagraphWrapper.__init__3  s9     	7T2J 	 	 3S/:b76 	9rW   r\   c                     U R                   $ rK   )r2  r_   s    rT   r  ?Deb822DictishParagraphWrapper._auto_map_initial_line_whitespaceF  s    666rW   c                     U R                   $ rK   )r3  r_   s    rT   r  GDeb822DictishParagraphWrapper._preserve_field_comments_on_field_updatesJ  s    >>>rW   c                     U R                   $ rK   )r4  r_   s    rT   r  IDeb822DictishParagraphWrapper._auto_map_final_newline_in_multiline_valuesN  s    @@@rW   ),__auto_map_final_newline_in_multiline_values"__auto_map_initial_line_whitespace*__preserve_field_comments_on_field_updates)rk   rl   rm   rn   rU   rq   r~  r  r  r  rt   r  r  s   @rT   r,  r,  0  sr     +/26/4:><@7 7& 74 7 7 ?4 ? ? AT A ArW   r,  c                   D   \ rS rSr\S 5       r\S 5       r\S 5       r\S\	4S j5       r
SS.S	 jrSSSSSS
.S jr\S 5       rS rS rS rS r\S\4S j5       rS rS r S S jrS rS r S!S jrSSS.S jrSSS.S jr\S 5       r\S\4S j5       r S!S jrSrg)"Deb822ParagraphElementiS  c                 *    [        / [        5       5      $ rK   )rK  r5   clss    rT   new_empty_paragraph*Deb822ParagraphElement.new_empty_paragraphU  s     7r:<HHrW   c                 `    U R                  5       nUR                  5        H	  u  p4XBU'   M     U$ rK   )rD  items)rC  mappingrR  kr   s        rT   	from_dict Deb822ParagraphElement.from_dictZ  s1     ++-	MMODAaL $rW   c                     U(       d  [        S5      e[        S U 5       5      n[        U5      [        U5      :X  a  [        X5      $ [	        U5      $ )Nz9A paragraph must consist of at least one field/value pairc              3   8   #    U  H  oR                   v   M     g 7frK   r7  r   kvs     rT   r   6Deb822ParagraphElement.from_kvpairs.<locals>.<genexpr>g  s     !J/B--/r?  )r   r5   r  rK  %Deb822DuplicateFieldsParagraphElement)rC  kvpair_elementskvpair_orders      rT   from_kvpairs#Deb822ParagraphElement.from_kvpairsb  sO     XYY!!J/!JJ|O 44 ;?YY 5_EErW   r\   c                     g)z0Tell whether this paragraph has duplicate fieldsFru   r_   s    rT   has_duplicate_fields+Deb822ParagraphElement.has_duplicate_fieldsq  s     rW   Tr  c                    [        U UUS9$ )a  Provide a Dict-like view of the paragraph

This method returns a dict-like object representing this paragraph and
is useful for accessing fields in a given interpretation. It is possible
to use multiple versions of this dict-like view with different interpretations
on the same paragraph at the same time (for different fields).

    >>> example_deb822_paragraph = '''
    ... Package: foo
    ... # Field comment (because it becomes just before a field)
    ... Architecture: amd64
    ... # Inline comment (associated with the next line)
    ...               i386
    ... # We also support arm
    ...               arm64
    ...               armel
    ... '''
    >>> dfile = parse_deb822_file(example_deb822_paragraph.splitlines())
    >>> paragraph = next(iter(dfile))
    >>> list_view = paragraph.as_interpreted_dict_view(LIST_SPACE_SEPARATED_INTERPRETATION)
    >>> # With the defaults, you only deal with the semantic values
    >>> # - no leading or trailing whitespace on the first part of the value
    >>> list(list_view["Package"])
    ['foo']
    >>> with list_view["Architecture"] as arch_list:
    ...     orig_arch_list = list(arch_list)
    ...     arch_list.replace('i386', 'kfreebsd-amd64')
    >>> orig_arch_list
    ['amd64', 'i386', 'arm64', 'armel']
    >>> list(list_view["Architecture"])
    ['amd64', 'kfreebsd-amd64', 'arm64', 'armel']
    >>> print(paragraph.dump(), end='')
    Package: foo
    # Field comment (because it becomes just before a field)
    Architecture: amd64
    # Inline comment (associated with the next line)
                  kfreebsd-amd64
    # We also support arm
                  arm64
                  armel
    >>> # Format preserved and architecture replaced
    >>> with list_view["Architecture"] as arch_list:
    ...     # Prettify the result as sorting will cause awkward whitespace
    ...     arch_list.reformat_when_finished()
    ...     arch_list.sort()
    >>> print(paragraph.dump(), end='')
    Package: foo
    # Field comment (because it becomes just before a field)
    Architecture: amd64
    # We also support arm
                  arm64
                  armel
    # Inline comment (associated with the next line)
                  kfreebsd-amd64
    >>> list(list_view["Architecture"])
    ['amd64', 'arm64', 'armel', 'kfreebsd-amd64']
    >>> # Format preserved and architecture values sorted

:param interpretation: Decides how the field values are interpreted.  As an example,
  use LIST_SPACE_SEPARATED_INTERPRETATION for fields such as Architecture in the
  debian/control file.
:param auto_resolve_ambiguous_fields: This parameter is only relevant for paragraphs
  that contain the same field multiple times (these are generally invalid).  If the
  caller requests an ambiguous field from an invalid paragraph via a plain field name,
  the return dict-like object will refuse to resolve the field (not knowing which
  version to pick).  This parameter (if set to True) instead changes the error into
  assuming the caller wants the *first* variant.
rZ  )r#  )rN   r'  r  s      rT   as_interpreted_dict_view/Deb822ParagraphElement.as_interpreted_dict_viewv  s    T 2*G
 	
rW   r-  c          	          [        U UUUUUS9$ )ay  Provide a Dict[str, str]-like view of this paragraph with non-standard parameters

This method returns a dict-like object representing this paragraph that is
optionally configured differently from the default view.

    >>> example_deb822_paragraph = '''
    ... Package: foo
    ... # Field comment (because it becomes just before a field)
    ... Depends: libfoo,
    ... # Inline comment (associated with the next line)
    ...          libbar,
    ... '''
    >>> dfile = parse_deb822_file(example_deb822_paragraph.splitlines())
    >>> paragraph = next(iter(dfile))
    >>> # With the defaults, you only deal with the semantic values
    >>> # - no leading or trailing whitespace on the first part of the value
    >>> paragraph["Package"]
    'foo'
    >>> # - no inline comments in multiline values (but whitespace will be present
    >>> #   subsequent lines.)
    >>> print(paragraph["Depends"])
    libfoo,
             libbar,
    >>> paragraph['Foo'] = 'bar'
    >>> paragraph.get('Foo')
    'bar'
    >>> paragraph.get('Unknown-Field') is None
    True
    >>> # But you get asymmetric behaviour with set vs. get
    >>> paragraph['Foo'] = ' bar\n'
    >>> paragraph['Foo']
    'bar'
    >>> paragraph['Bar'] = '     bar\n#Comment\n another value\n'
    >>> # Note that the whitespace on the first line has been normalized.
    >>> print("Bar: " + paragraph['Bar'])
    Bar: bar
     another value
    >>> # The comment is present (in case you where wondering)
    >>> print(paragraph.get_kvpair_element('Bar').convert_to_text(), end='')
    Bar:     bar
    #Comment
     another value
    >>> # On the other hand, you can choose to see the values as they are
    >>> # - We will just reset the paragraph as a "nothing up my sleeve"
    >>> dfile = parse_deb822_file(example_deb822_paragraph.splitlines())
    >>> paragraph = next(iter(dfile))
    >>> nonstd_dictview = paragraph.configured_view(
    ...     discard_comments_on_read=False,
    ...     auto_map_initial_line_whitespace=False,
    ...     # For paragraphs with duplicate fields, you can choose to get an error
    ...     # rather than the dict picking the first value available.
    ...     auto_resolve_ambiguous_fields=False,
    ...     auto_map_final_newline_in_multiline_values=False,
    ... )
    >>> # Because we have reset the state, Foo and Bar are no longer there.
    >>> 'Bar' not in paragraph and 'Foo' not in paragraph
    True
    >>> # We can now see the comments (discard_comments_on_read=False)
    >>> # (The leading whitespace in front of "libfoo" is due to
    >>> #  auto_map_initial_line_whitespace=False)
    >>> print(nonstd_dictview["Depends"], end='')
     libfoo,
    # Inline comment (associated with the next line)
             libbar,
    >>> # And all the optional whitespace on the first value line
    >>> # (auto_map_initial_line_whitespace=False)
    >>> nonstd_dictview["Package"] == ' foo\n'
    True
    >>> # ... which will give you symmetric behaviour with set vs. get
    >>> nonstd_dictview['Foo'] = '  bar \n'
    >>> nonstd_dictview['Foo']
    '  bar \n'
    >>> nonstd_dictview['Bar'] = '  bar \n#Comment\n another value\n'
    >>> nonstd_dictview['Bar']
    '  bar \n#Comment\n another value\n'
    >>> # But then you get no help either.
    >>> try:
    ...     nonstd_dictview["Baz"] = "foo"
    ... except ValueError:
    ...     print("Rejected")
    Rejected
    >>> # With auto_map_initial_line_whitespace=False, you have to include minimum a newline
    >>> nonstd_dictview["Baz"] = "foo\n"
    >>> # The absence of leading whitespace gives you the terse variant at the expensive
    >>> # readability
    >>> paragraph.get_kvpair_element('Baz').convert_to_text()
    'Baz:foo\n'
    >>> # But because they are views, changes performed via one view is visible in the other
    >>> paragraph['Foo']
    'bar'
    >>> # The views show the values according to their own rules. Therefore, there is an
    >>> # asymmetric between paragraph['Foo'] and nonstd_dictview['Foo']
    >>> # Nevertheless, you can read or write the fields via either - enabling you to use
    >>> # the view that best suit your use-case for the given field.
    >>> 'Baz' in paragraph and nonstd_dictview.get('Baz') is not None
    True
    >>> # Deletion via the view also works
    >>> del nonstd_dictview['Baz']
    >>> 'Baz' not in paragraph and nonstd_dictview.get('Baz') is None
    True


:param discard_comments_on_read: When getting a field value from the dict,
  this parameter decides how in-line comments are handled.  When setting
  the value, inline comments are still allowed and will be retained.
  However, keep in mind that this option makes getter and setter asymmetric
  as a "get" following a "set" with inline comments will omit the comments
  even if they are there (see the code example).
:param auto_map_initial_line_whitespace: Special-case the first value line
  by trimming unnecessary whitespace leaving only the value. For single-line
  values, all space including newline is pruned. For multi-line values, the
  newline is preserved / needed to distinguish the first line from the
  following lines.  When setting a value, this option normalizes the
  whitespace of the initial line of the value field.
  When this option is set to True makes the dictionary behave more like the
  original Deb822 module.
:param preserve_field_comments_on_field_updates: Whether to preserve the field
  comments when mutating the field.
:param auto_resolve_ambiguous_fields: This parameter is only relevant for paragraphs
  that contain the same field multiple times (these are generally invalid).  If the
  caller requests an ambiguous field from an invalid paragraph via a plain field name,
  the return dict-like object will refuse to resolve the field (not knowing which
  version to pick).  This parameter (if set to True) instead changes the error into
  assuming the caller wants the *first* variant.
:param auto_map_final_newline_in_multiline_values: This parameter controls whether
  a multiline field with have / need a trailing newline. If True, the trailing
  newline is hidden on get and automatically added in set (if missing).
  When this option is set to True makes the dictionary behave more like the
  original Deb822 module.
r-  )r,  )rN   r  r.  r  r/  r0  s         rT   configured_view&Deb822ParagraphElement.configured_view  s$    V -%=-M*G5]7a
 	
rW   c                     U $ rK   ru   r_   s    rT   r  !Deb822ParagraphElement._paragraphZ  s	     rW   c                     [         e)9Re-order the given field so it is "last" in the paragraphr  rN   fields     rT   
order_last!Deb822ParagraphElement.order_last_  r  rW   c                     [         e):Re-order the given field so it is "first" in the paragraphr  re  s     rT   order_first"Deb822ParagraphElement.order_firstd  r  rW   c                     [         e)}Re-order the given field so appears directly after the reference field in the paragraph

The reference field must be present.r  rN   rf  reference_fields      rT   order_before#Deb822ParagraphElement.order_beforei  r  rW   c                     [         e)Re-order the given field so appears directly before the reference field in the paragraph

The reference field must be present.
r  ro  s      rT   order_after"Deb822ParagraphElement.order_afterp  r  rW   c                     [         erK   r  r_   s    rT   r  #Deb822ParagraphElement.kvpair_countx  r  rW   c                     [         erK   r  r_   s    rT   r   Deb822ParagraphElement.iter_keys|  r  rW   c                     [         erK   r  r  s     rT   r  .Deb822ParagraphElement.contains_kvpair_element  r  rW   c                     [         erK   r  )rN   r  r  s      rT   rL  )Deb822ParagraphElement.get_kvpair_element  r  rW   c                     [         erK   r  r  s      rT   set_kvpair_element)Deb822ParagraphElement.set_kvpair_element  r  rW   c                     [         erK   r  rN   r_  s     rT   r  ,Deb822ParagraphElement.remove_kvpair_element  r  rW   Nc                     [         e)Re-order all fields

:param key: Provide a key function (same semantics as for sorted).  Keep in mind that
  the module preserve the cases for field names - in generally, callers are recommended
  to use "lower()" to normalize the case.
r  r  s     rT   sort_fields"Deb822ParagraphElement.sort_fields  s
     "!rW   r  c                    SU;   a  [        S5      eUR                  5       nU(       a	  SU-   S-   nOSnU R                  UUUUS9  g)a  Sets a field in this paragraph to a simple "word" or "phrase"

In many cases, it is better for callers to just use the paragraph as
if it was a dictionary.  However, this method does enable to you choose
the field comment (if any), which can be a reason for using it.

This is suitable for "simple" fields like "Package".  Example:

    >>> example_deb822_paragraph = '''
    ... Package: foo
    ... '''
    >>> dfile = parse_deb822_file(example_deb822_paragraph.splitlines())
    >>> p = next(iter(dfile))
    >>> p.set_field_to_simple_value("Package", "mscgen")
    >>> p.set_field_to_simple_value("Architecture", "linux-any kfreebsd-any",
    ...                             field_comment=['Only ported to linux and kfreebsd'])
    >>> p.set_field_to_simple_value("Priority", "optional")
    >>> print(p.dump(), end='')
    Package: mscgen
    # Only ported to linux and kfreebsd
    Architecture: linux-any kfreebsd-any
    Priority: optional
    >>> # Values are formatted nicely by default, but it does not work with
    >>> # multi-line values
    >>> p.set_field_to_simple_value("Foo", "bar\nbin\n")
    Traceback (most recent call last):
        ...
    ValueError: Cannot use set_field_to_simple_value for values with newlines

:param item: Name of the field to set.  If the paragraph already
  contains the field, then it will be replaced.  If the field exists,
  then it will preserve its order in the paragraph.  Otherwise, it is
  added to the end of the paragraph.
  Note this can be a "paragraph key", which enables you to control
  *which* instance of a field is being replaced (in case of duplicate
  fields).
:param simple_value: The text to use as the value.  The value must not
  contain newlines.  Leading and trailing will be stripped but space
  within the value is preserved.  The value cannot contain comments
  (i.e. if the "#" token appears in the value, then it is considered
  a value rather than "start of a comment)
:param preserve_original_field_comment: See the description for the
  parameter with the same name in the set_field_from_raw_string method.
:param field_comment: See the description for the parameter with the same
  name in the set_field_from_raw_string method.
r   z=Cannot use set_field_to_simple_value for values with newlinesr   r  N)r   r  r  )rN   r  simple_valuer  r   stripped	raw_values          rT   r  0Deb822ParagraphElement.set_field_to_simple_value  s`    l <\]]
  %%'h-I I&&,K'	 	' 	
rW   c                   / nUb  Ub  [        S5      eO4Ub1  [        U[        5      (       d  UR                  S U 5       5        SnSn[	        U5      u  n  nUn U R                  USS9n	Uc  SnU	(       a  U	R                  nSR                  X45      n
U
R                  SS	9n[        US
S9 Ha  u  pUR                  S5      (       d  [        SR                  US95      eUS
:w  d  M;  US   S;  d  MF  Sn[        UR                  XS   S95      e   [        U5      S
:  a$  US   R                  S5      (       a  [        S5      eUR                  U5        [        [!        U5      5      nUR#                  5       nU(       a  [        SU-   5      e[%        [!        U5      5      n[        U[&        5      (       d   eUR                  U5      nUc   eU(       a   U	(       a  U	R(                  Ul        SU	l        O
Ub  UUl        U R+                  UU5        g! [         a    U(       a  e U R                  US4SS9n	 GNf = f)a  Sets a field in this paragraph to a given text value

In many cases, it is better for callers to just use the paragraph as
if it was a dictionary.  However, this method does enable to you choose
the field comment (if any) and lets to have a higher degree of control
over whitespace (on the first line), which can be a reason for using it.

Example usage:

    >>> example_deb822_paragraph = '''
    ... Package: foo
    ... '''
    >>> dfile = parse_deb822_file(example_deb822_paragraph.splitlines())
    >>> p = next(iter(dfile))
    >>> raw_value = '''
    ... Build-Depends: debhelper-compat (= 12),
    ...                some-other-bd,
    ... # Comment
    ...                another-bd,
    ... '''.lstrip()  # Remove leading newline, but *not* the trailing newline
    >>> fname, new_value = raw_value.split(':', 1)
    >>> p.set_field_from_raw_string(fname, new_value)
    >>> print(p.dump(), end='')
    Package: foo
    Build-Depends: debhelper-compat (= 12),
                   some-other-bd,
    # Comment
                   another-bd,
    >>> # Format preserved

:param item: Name of the field to set.  If the paragraph already
  contains the field, then it will be replaced.  Otherwise, it is
  added to the end of the paragraph.
  Note this can be a "paragraph key", which enables you to control
  *which* instance of a field is being replaced (in case of duplicate
  fields).
:param raw_string_value: The text to use as the value.  The text must
  be valid deb822 syntax and is used *exactly* as it is given.
  Accordingly, multi-line values must include mandatory leading space
  on continuation lines, newlines after the value, etc. On the
  flip-side, any optional space or comments will be included.

  Note that the first line will *never* be read as a comment (if the
  first line of the value starts with a "#" then it will result
  in "Field-Name:#..." which is parsed as a value starting with "#"
  rather than a comment).
:param preserve_original_field_comment: If True, then if there is an
  existing field and that has a comment, then the comment will remain
  after this operation.  This is the default is the `field_comment`
  parameter is omitted.
  Note that if the parameter is True and the item is ambiguous, this
  will raise an AmbiguousDeb822FieldKeyError.  When the parameter is
  omitted, the ambiguity is resolved automatically and if the resolved
  field has a comment then that will be preserved (assuming
  field_comment is None).
:param field_comment: If not None, add or replace the comment for
  the field.  Each string in the list will become one comment
  line (inserted directly before the field name). Will appear in the
  same order as they do in the list.

  If you want complete control over the formatting of the comments,
  then ensure that each line start with "#" and end with "\n" before
  the call.  Otherwise, leading/trailing whitespace is normalized
  and the missing "#"/"\n" character is inserted.
NzNThe "preserve_original_field_comment" conflicts with "field_comment" parameterc              3   8   #    U  H  n[        U5      v   M     g 7frK   )r
  r  s     rT   r   CDeb822ParagraphElement.set_field_from_raw_string.<locals>.<genexpr>9  s     "M}!?1#5#5}r?  FTr  r   rD  rE  r  r  r   z2Line {i} in new value was missing trailing newline)r  )r   r  r  zLine {i} in new value was invalid.  It must either start with " " space (continuation line) or "#" (comment line). The line started with "{line}")r  r  r  r  z2The last line in a value field cannot be a commentrG  )r   r   r  rl  r  rL  r0   r7  r@  rH  r  r  r  r  r  rI  r   rJ  r   rK  r?  r  )rN   r  raw_string_valuer  r   rO  r7  r  cased_field_nameoriginalraw	raw_linesr  r  r  rP  rQ  rR  r^   s                      rT   r  0Deb822ParagraphElement.set_field_from_raw_string  sf   T *6(  "> ? ? ) &m-ABB"""M}"MM $.3+&t,
Aq%	N..tT.BH +2 /3+'22hh(;<NNDN1	 !4GA==&& !U!\!\_`!\!abbAv$q')998 !a1g!>?? 5 y>A)B-":":3"?"?QRR9% ([(9:!::<CjPQQk*+	)%LMMMM,,Z8   *(0(@(@%+/(&$1E!e,[ , 	N. ..
A.MH	Ns   H $H=<H=c                     g rK   ru   rN   fds     rT   dumpDeb822ParagraphElement.dumpq      
 	rW   c                     g rK   ru   r_   s    rT   r  r  x      rW   c                     Uc&  SR                  S U R                  5        5       5      $ U R                  5        H-  nUR                  UR                  R	                  S5      5        M/     g )Nr2  c              3   8   #    U  H  oR                   v   M     g 7frK   r<  r=  s     rT   r   .Deb822ParagraphElement.dump.<locals>.<genexpr>       >+=a66+=r?  utf-8r@  r,  writer  encoderN   r  r  s      rT   r  r  |  X     :77>4+;+;+=>>>%%'EHHUZZ&&w/0 (rW   ru   r}  rK   ) rk   rl   rm   rn   classmethodrD  rJ  rU  rq   r~  rX  r\  r_  r  rg  rk  rq  ru  r  r  r  r  rL  r  r  r  r  r  r   r  rr   rt   ru   rW   rT   r@  r@  S  sG   I I   F F d   @DN
d 269=6:AECGR
h  "
"
"" "c " """ $)"""
 
"  CG04G
Z CG04G-R   c   rW   r@  c                      ^  \ rS rSrSrU 4S jr\S\4S j5       rS r	S r
S rS	 rS
 rS rS rS r SS jrS rSS jrS rSrU =r$ )rK  i  zParagraph implementation optimized for valid deb822 files

When there are no duplicated fields, we can use simpler and faster
datastructures for common operations.
c                    > [         TU ]  5         U Vs0 s H  o3R                  U_M     snU l        X l        U R                  5         g s  snf rK   )r   rU   r7  _kvpair_elements_kvpair_orderr   )rN   rS  rT  rP  r   s       rT   rU   0Deb822NoDuplicateFieldsParagraphElement.__init__  sF    
 	=L M_r!2_ M)""$ !Ns   A	r\   c                 ,    [        U R                  5      $ rK   )r  r  r_   s    rT   r  4Deb822NoDuplicateFieldsParagraphElement.kvpair_count  s    4(())rW   c                 V    [        USS9u  n  nU R                  R                  U5        g)rd  Tr  N)r  r  rg  rN   rf  unpacked_fieldr  s       rT   rg  2Deb822NoDuplicateFieldsParagraphElement.order_last  s+      +54H1%%n5rW   c                 V    [        USS9u  n  nU R                  R                  U5        g)rj  Tr  N)r  r  rk  r  s       rT   rk  3Deb822NoDuplicateFieldsParagraphElement.order_first  s+      +54H1&&~6rW   c                 r    [        USS9u  n  n[        USS9u  n  nU R                  R                  X55        g)rn  Tr  N)r  r  rq  rN   rf  rp  r  r  unpacked_ref_fields         rT   rq  4Deb822NoDuplicateFieldsParagraphElement.order_before  s@    
  +54H1#.QU#V Aq''KrW   c                 r    [        USS9u  n  n[        USS9u  n  nU R                  R                  X55        g)rt  Tr  N)r  r  ru  r  s         rT   ru  3Deb822NoDuplicateFieldsParagraphElement.order_after  s@      +54H1#.QU#V Aq&&~JrW   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  n[        U5      v   M     g 7frK   rr   r   rI  s     rT   r   CDeb822NoDuplicateFieldsParagraphElement.__iter__.<locals>.<genexpr>       7$6qCFF$6r?  )r   r  r_   s    rT   r   0Deb822NoDuplicateFieldsParagraphElement.__iter__  s    7D$6$6777rW   c              #   F   #    S U R                    5        S h  vN   g  N7f)Nc              3   8   #    U  H  n[        U5      v   M     g 7frK   r  r  s     rT   r   DDeb822NoDuplicateFieldsParagraphElement.iter_keys.<locals>.<genexpr>  r  r?  r  r_   s    rT   r  1Deb822NoDuplicateFieldsParagraphElement.iter_keys  s     7D$6$6777   !!c                 ~    S U l         [        USS9u  n  nU R                  U	 U R                  R	                  U5        g NTr  )r  r  r  r  rh   )rN   r_  r  s      rT   r  =Deb822NoDuplicateFieldsParagraphElement.remove_kvpair_element  s>     $d;	Q!!#&!!#&rW   c                     [        U[        [        [        45      (       d  g[	        SU5      n[        USS9u  n  nX R                  ;   $ )NFr<   Tr  )r   rr   r/  r*   r   r  r  )rN   r  r_  r  s       rT   r  ?Deb822NoDuplicateFieldsParagraphElement.contains_kvpair_element  sG    $e-A BCCND)t<	Q++++rW   c                     [        USS9u  n  nU(       a  U R                  R                  U5      $ U R                  U   $ r  )r  r  get)rN   r  r  r  s       rT   rL  :Deb822NoDuplicateFieldsParagraphElement.get_kvpair_element  sA    
 !=
a((,,T22$$T**rW   c                    [        USS9u  n  n[        U[        5      (       a&  XR                  La  [	        S5      eUR
                  nO&XR
                  :w  a  [	        S5      eUR
                  nU R                  R                  U5      nS U l        X R                  U'   U R                  R                  U5        Ub  S Ul        Xl        g )NTr  zOKey is a Deb822FieldNameToken, but not *the* Deb822FieldNameToken for the valuegCannot insert value under a different field value than field name from its Deb822FieldNameToken implies)r  r   r*   r  r   r7  r  r  r  r  r   r  )rN   r_  r^   r  original_values        rT   r  :Deb822NoDuplicateFieldsParagraphElement.set_kvpair_element  s    d;	Qc/00+++  "2 3 3""C&&&  "J K K ""C..2237 $%*c"!!#&%,0N)#rW   c                    [        U R                  5       HB  nU R                  [        SU5         nUR                  R                  5       (       a  SU l          O   Uc  [        n[        [        U R                  US95      U l        g)r  r6   Nrt  )
r   r  r  r   rX  rl  r  r7   r5   sorted)rN   r_  last_field_namelast_kvpairs       rT   r  3Deb822NoDuplicateFieldsParagraphElement.sort_fields  sv      ((:(:;O//Wo0NOK((EEGG(,%	  < ;(C't/A/As(KLrW   c              #   b   ^ #    U 4S j[        ST R                  5       5        S h  vN   g  N7f)Nc              3   B   >#    U  H  nTR                   U   v   M     g 7frK   )r  )r   re  rN   s     rT   r   EDeb822NoDuplicateFieldsParagraphElement.iter_parts.<locals>.<genexpr>		  s$      JH ))!,Hs   zIterable[_strI])r   r  r_   s   `rT   r   2Deb822NoDuplicateFieldsParagraphElement.iter_parts	  s/     J!"3T5G5GHJ 	J 	Js   $/-/r  r  r  r}  rK   )rk   rl   rm   rn   ro   rU   rq   r  r  rg  rk  rq  ru  r   r  r  r  rL  r  r  r   rt   r  r  s   @rT   rK  rK    ss    % *c * *67LK88', $)+$.M&J JrW   rK  c                      ^  \ rS rSrU 4S jr\S\4S j5       rS rS r	S r
S rS	 rS
 rS rS r\S\4S j5       rS r SS jr SS jr\S 5       rS rS rS rSS jrSrU =r$ )rR  i	  c                    > [         TU ]  5         [        5       U l        0 U l        U R                  U5        U R                  5         g rK   )r   rU   r3   r  r  _init_kvpair_fieldsr   )rN   rS  r   s     rT   rU   .Deb822DuplicateFieldsParagraphElement.__init__	  s=    '\ 	  1""$rW   r\   c                 X    [        U R                  5      [        U R                  5      :  $ rK   )r  r  r  r_   s    rT   rX  :Deb822DuplicateFieldsParagraphElement.has_duplicate_fields	  s%     4%%&T-B-B)CCCrW   c                 .   U R                   (       a   eU R                  (       a   eU Hi  nUR                  nU R                   R                  U5      nX0R                  ;  a  U/U R                  U'   MK  U R                  U   R                  U5        Mk     g rK   )r  r  r7  r   )rN   kvpairsrP  r7  rO   s        rT   r  9Deb822DuplicateFieldsParagraphElement._init_kvpair_fields	  s    %%%%((((BJ%%,,R0D!6!6659F%%j1%%j188> rW   c                     [        U5      u  p#nU R                  U   n/ nUc  Ub+  U R                  XRX45      nUc   eUR                  U5        XV4$ UnXV4$ rK   )r  r  _resolve_to_single_noder   )rN   rf  r_  r  r  nodesnodes_being_relocatedsingle_nodes           rT   _nodes_being_relocated<Deb822DuplicateFieldsParagraphElement._nodes_being_relocated*	  sz    !,U!3J%%c* "!U%666u5UK***!((5 ++ %*!++rW   c                    U R                  U5      u  p#[        U5      S:X  d  [        U5      [        U5      :X  d   eU R                  nU HO  nUR                  UL a  M  UR	                  U5        UR                  c   eUR                  XTR                  5        MQ     [        U5      S:X  a4  US   US   La(  US   nUR                  U5        UR                  U5        ggg)rd  r  Nr   r  )r  r  r  r   remove_nodeinsert_node_afterrh   r   rN   rf  r  r  rT  rO   r  s          rT   rg  0Deb822DuplicateFieldsParagraphElement.order_last8	  s     (,'B'B5'I$()Q.#e*DY@Z2ZZZ)))D%%-$$T*))555**41G1GH * $%*/DQ/GuUWy/X/2KLL%LL% 0Y*rW   c                    U R                  U5      u  p#[        U5      S:X  d  [        U5      [        U5      :X  d   eU R                  nU HO  nUR                  UL a  M  UR	                  U5        UR                  c   eUR                  XTR                  5        MQ     [        U5      S:X  a5  US   US   La)  US   nUR                  U5        UR                  SU5        ggg)rj  r  Nr   )r  r  r  r   r  insert_node_beforerh   insertr  s          rT   rk  1Deb822DuplicateFieldsParagraphElement.order_firstM	  s     (,'B'B5'I$()Q.#e*DY@Z2ZZZ)))D%%-$$T*))555++D2H2HI * $%*/DQ/GuUVx/W/2KLL%LLK( 0X*rW   c                    U R                  U5      u  p4[        U5      S:X  d  [        U5      [        U5      :X  d   eU R                  U5      u  pVUS   nXt;   a  [        S5      eU R                  nU H%  n	UR	                  U	5        UR                  X5        M'     [        U5      S:X  a;  [        U5      S:  a+  US   R                  R                  n
U R                  U
5        ggg)rn  r  r   *Cannot re-order a field relative to itselfN)	r  r  r   r  r  r  r^   r7  !_regenerate_relative_kvapir_orderrN   rf  rp  r  r  r  reference_nodesreference_noderT  rO   r7  s              rT   rq  2Deb822DuplicateFieldsParagraphElement.order_beforeb	  s    
 (,'B'B5'I$()Q.#e*DY@Z2ZZZ!88I(+2IJJ)))D$$T*++DA * $%*s5zA~.q177BBJ22:> 0>*rW   c                    U R                  U5      u  p4[        U5      S:X  d  [        U5      [        U5      :X  d   eU R                  U5      u  pVUS   nXt;   a  [        S5      eU R                  n[	        U5       H%  n	UR                  U	5        UR                  X5        M'     [        U5      S:X  a;  [        U5      S:  a+  US   R                  R                  n
U R                  U
5        ggg)rt  r  r  r  r   N)
r  r  r   r  r   r  r  r^   r7  r  r  s              rT   ru  1Deb822DuplicateFieldsParagraphElement.order_aftery	  s     (,'B'B5'I$()Q.#e*DY@Z2ZZZ!88I(,2IJJ))23D$$T***4@ 4 $%*s5zA~.q177BBJ22:> 0>*rW   c                     / nU R                   R                  5        H0  nUR                  R                  U:X  d  M  UR	                  U5        M2     X R
                  U'   g rK   )r  r   r^   r7  r   r  )rN   r7  r  rO   s       rT   r  GDeb822DuplicateFieldsParagraphElement._regenerate_relative_kvapir_order	  sN    &&113Dzz$$
2T" 4 -2j)rW   c              #   8   #    U R                    S h  vN   g  N7frK   r  r_   s    rT   r   0Deb822DuplicateFieldsParagraphElement.iter_parts	  s     %%%%r   c                 ,    [        U R                  5      $ rK   )r  r  r_   s    rT   r  2Deb822DuplicateFieldsParagraphElement.kvpair_count	  s    4%%&&rW   c              #   F   #    S U R                    5        S h  vN   g  N7f)Nc              3   8   #    U  H  oR                   v   M     g 7frK   rN  rO  s     rT   r   BDeb822DuplicateFieldsParagraphElement.iter_keys.<locals>.<genexpr>	  s     ?,>bMM,>r?  r  r_   s    rT   r  /Deb822DuplicateFieldsParagraphElement.iter_keys	  s     ?D,>,>???r  c           	      *   Uc[  [        U5      S:w  aJ  Ub  U R                  XA5      nUb  U$ Sn[        UR                  U[        U5      [        U5      S-
  S95      eSn X   $ ! [         a$    U(       a   g Sn[        UR                  X#S95      ef = f)Nr  zAmbiguous key {key} - the field appears {res_len} times. Use ({key}, index) to denote which instance of the field you want.  (Index can be 0..{res_len_1} or e.g. -1 to denote the last field))r_  res_len	res_len_1r   z>Field "{key}" was present but the index "{index}" was invalid.r  )r  _find_node_via_name_tokenr0   r  
IndexErrorr  )rN   r  r_  r  r  r  rO   r  s           rT   r  =Deb822DuplicateFieldsParagraphElement._resolve_to_single_node	  s     =5zQ)99*LD'#T 33::#FI%jHKE
UV 4> 4X Y Y E	=< 	=RC3::#:;<<		=s    A$ $B7Bc                     [        U5      u  p4nU(       a   U R                  R                  U5      nUc  g OU R                  U   nU R                  XcXEUS9nUb  UR                  $ g )Nr  )r  r  r  r  r^   )rN   r  r  r_  r  r  r  rO   s           rT   rL  8Deb822DuplicateFieldsParagraphElement.get_kvpair_element	  sv    
 "-T!2J))--c2E}  ))#.E++ESZ+[::rW   c                 N    U H  nXR                   R                  L d  M  Us  $    g rK   )r^   r  )r  elementsrO   s      rT   r  ?Deb822DuplicateFieldsParagraphElement._find_node_via_name_token	  s(     DZZ333  rW   c                     [        U[        [        [        45      (       d  g[	        SU5      n U R                  USS9S L$ ! [         a     gf = f)NFr<   Tr  )r   rr   r/  r*   r   rL  r0   r  s     rT   r  =Deb822DuplicateFieldsParagraphElement.contains_kvpair_element	  sX    $e-A BCCND)	**4*>dJJ+ 		s   A 
AAc                    [        U5      u  pnU(       az  XBR                  La_  U R                  R                  UR                  5      nS nUb  U R                  XE5      nUc  [        S5      eUc   eUR                  U5      nUR                  nO&XR                  :w  a  [        S5      eUR                  nS U l        U R                  R                  U5      nUb  U(       d}  Ub   US:w  a  Sn[        UR                  XS95      eU R                  R                  U5      nXR                  ;  a  U/U R                  U'   g U R                  U   R                  U5        g Sn	Uc'  Sn	US   n[        U5      S:w  a  U/U R                  U'   OXS   nS UR                  l        Xl        X(l        U	(       aI  [        U5      S:w  a9  USS   H/  n
S U
R                  l        U R                  R!                  U
5        M1     g g g )	NzKey is a Deb822FieldNameToken, but not *the* Deb822FieldNameToken for the value nor the Deb822FieldNameToken for an existing field in the paragraphr  r   zCannot replace field ({key}, {index}) as the field does not exist in the first place.  Please index-less key or ({key}, 0) if you want to add the field.r  FTr  )r  r  r  r  r7  r  r   r  r  r  r  r  r   r  r^   r  r  )rN   r_  r^   r  r  original_nodesoriginal_noder  rO   replace_allr   s              rT   r  8Deb822DuplicateFieldsParagraphElement.set_kvpair_element	  s   !,S!1J!2!22!%!6!6!:!:5;K;K!L $!-$($B$B:$^M ($ &d e e &111&,,];""C&&&  "J K K ""C $..2237! UaZ0 szzcz?@@%%,,U3D///.2V%%c*  %%c*11$7=K!!$D>"a'.2V%%c*
 "(D %)

!#
3~.!3#AB')-&""..q1 ( 4;rW   c                 l   [        U5      u  pnU R                  U   nUcM  UcJ  S U l        U H/  nS UR                  l        U R
                  R                  U5        M1     U R                  U	 g Ub1  U R                  X45      nUc  Sn[        UR                  US95      eUnO
Uc   e XB   nS U l        [        U5      S:X  a  U R                  U	 OUR                  U5        S UR                  l        U R
                  R                  U5        g ! [         a    Sn[        UR                  XS95      ef = f)Nz>The field "{key}" is present but key used to access it is not.rt  z@The field "{key}" is present, but the index "{idx}" was invalid.)r_  r	  r  )r  r  r  r^   r  r  r  r  r  r  r  rh   )rN   r_  r	  r  
field_listrO   r  r  s           rT   r  ;Deb822DuplicateFieldsParagraphElement.remove_kvpair_element.
  s@   *3/***3/
#+$(D!",0

)""..t4 # %%c*! :::RM$Vszzcz233 D?"?=!
 !%z?a%%c*d#$(

!&&t,  =Xszzcz;<<=s   (D %D3c                 "  ^ Uc  [         nUmU4S jn[        U R                  5       H)  nUR                  R	                  5       (       a  SU l          O   [        U R                  US9n[        5       U l        0 U l        U R                  U5        g)zRe-order all fields

:param key: Provide a key function (same semantics as for sorted).   Keep in mind that
  the module preserve the cases for field names - in generally, callers are recommended
  to use "lower()" to normalize the case.
Nc                 (   > T" U R                   5      $ rK   rN  )rY  key_impls    rT   _actual_keyFDeb822DuplicateFieldsParagraphElement.sort_fields.<locals>._actual_keyc
  s    F--..rW   rt  )
r7   r   r  rX  rl  r  r  r3   r  r  )rN   r_  r%  r  sorted_kvpair_listr$  s        @rT   r  1Deb822DuplicateFieldsParagraphElement.sort_fieldsS
  s     ;(C 	/ $D$6$67K((EEGG(,% 8
 $D$6$6KH'\ "  !34rW   r  r}  rK   )rk   rl   rm   rn   rU   rq   r~  rX  r  r  rg  rk  rq  ru  r  r   r  r  r  r  rL  staticmethodr  r  r  r  r  rt   r  r  s   @rT   rR  rR  	  s    % Dd D D

?,&*)*?.?22& 'c ' '@ ).=> $)"  ?2B#-J5 5rW   rR  c                      ^  \ rS rSrSrU 4S jr\S 5       r\S\	4S j5       r
S rS rS	 rS
 rS rS rS rS\4S jrS\4S jr\S 5       r\S\4S j5       r SS jrSrU =r$ )Deb822FileElementir
  z!Represents the entire deb822 filec                 N   > [         TU ]  5         Xl        U R                  5         g rK   )r   rU   _token_and_elementsr   )rN   token_and_elementsr   s     rT   rU   Deb822FileElement.__init__u
  s     #5 ""$rW   c                 "    U " [        5       5      $ )zsCreates a new Deb822FileElement with no contents

Note that a deb822 file must be non-empty to be considered valid
)r3   rB  s    rT   new_empty_file Deb822FileElement.new_empty_file{
  s     :<  rW   r\   c                     SnU  H  nSnU(       a  UR                   (       d  M    g   U(       d  gU R                  5       SL $ )zReturns true if the file is valid

Invalid elements include error elements (Deb822ErrorElement) but also
issues such as paragraphs with duplicate fields or "empty" files
(a valid deb822 file contains at least one paragraph).
FTN)rX  rJ  )rN   had_paragraphrR  s      rT   is_valid_fileDeb822FileElement.is_valid_file
  sE     I M	 > > > 
 ,,.$66rW   c                 N    [        [        U R                  [        S95      S5      $ )z:Returns the first Deb822ErrorElement (or None) in the filer  N)r   r   r  r+  r_   s    rT   rJ  *Deb822FileElement.find_first_error_element
  s&     D**FX*YZ\`aarW   c                 >    [        U R                  [        5      5      $ rK   )r   r  r@  r_   s    rT   r   Deb822FileElement.__iter__
  s    D++,BCDDrW   c              #   8   #    U R                    S h  vN   g  N7frK   )r-  r_   s    rT   r   Deb822FileElement.iter_parts
  s     ++++r   c                 f   SnSnSU l         US:X  aO  U R                  (       d  U R                  U5        gU R                  R                  n[	        U R                  5      nOUSnU R                  R                  5        H5  nUR                  n[        U[        5      (       a  US-  nXS-
  :X  d  M3  Un  O   Uc  U R                  U5        gU(       a5  U R                  [        S5      5      nU R                  R                  X5      nU R                  R                  U R                  U5      U5        g)a  Inserts a paragraph into the file at the given "index" of paragraphs

Note that if the index is between two paragraphs containing a "free
floating" comment (e.g. paragraph/start-of-file, empty line, comment,
empty line, paragraph) then it is unspecified which "side" of the
comment the new paragraph will appear and this may change between
versions of python-debian.


>>> original = '''
... Package: libfoo-dev
... Depends: libfoo1 (= ${binary:Version}), ${shlib:Depends}, ${misc:Depends}
... '''.lstrip()
>>> deb822_file = parse_deb822_file(original.splitlines())
>>> para1 = Deb822ParagraphElement.new_empty_paragraph()
>>> para1["Source"] = "foo"
>>> para1["Build-Depends"] = "debhelper-compat (= 13)"
>>> para2 = Deb822ParagraphElement.new_empty_paragraph()
>>> para2["Package"] = "libfoo1"
>>> para2["Depends"] = "${shlib:Depends}, ${misc:Depends}"
>>> deb822_file.insert(0, para1)
>>> deb822_file.insert(1, para2)
>>> expected = '''
... Source: foo
... Build-Depends: debhelper-compat (= 13)
...
... Package: libfoo1
... Depends: ${shlib:Depends}, ${misc:Depends}
...
... Package: libfoo-dev
... Depends: libfoo1 (= ${binary:Version}), ${shlib:Depends}, ${misc:Depends}
... '''.lstrip()
>>> deb822_file.dump() == expected
True
NTr   r  r   )r  r-  r   r   r~  r   r^   r   r@  _set_parentr&   insert_before)	rN   r	  paraanchor_nodeneeds_newliner  rO   entrynl_tokens	            rT   r  Deb822FileElement.insert
  s   L  $!8 ++D!22<<K !9!9:MA00;;=

e%;<<FAa%<"&K > KK++,A$,GH"66DDX[$$2243C3CD3I;WrW   c                    U R                   R                  nUR                  b%  UR                  U L a  [        S5      e[        S5      eSU l        U(       aH  [        U[        5      (       d3  U R                   R                  U R                  [        S5      5      5        U R                   R                  U R                  U5      5        g)az  Appends a paragraph to the file

>>> deb822_file = Deb822FileElement.new_empty_file()
>>> para1 = Deb822ParagraphElement.new_empty_paragraph()
>>> para1["Source"] = "foo"
>>> para1["Build-Depends"] = "debhelper-compat (= 13)"
>>> para2 = Deb822ParagraphElement.new_empty_paragraph()
>>> para2["Package"] = "foo"
>>> para2["Depends"] = "${shlib:Depends}, ${misc:Depends}"
>>> deb822_file.append(para1)
>>> deb822_file.append(para2)
>>> expected = '''
... Source: foo
... Build-Depends: debhelper-compat (= 13)
...
... Package: foo
... Depends: ${shlib:Depends}, ${misc:Depends}
... '''.lstrip()
>>> deb822_file.dump() == expected
True
Nz(Paragraph is already a part of this filez/Paragraph is already part of another Deb822Filer   )	r-  r   r  r   r  r   r&   r   r>  )rN   rR  tail_elements      rT   r   Deb822FileElement.append
  s    . //44##/''4/ !KLLNOO $
 
<9N O O$$++D,<,<=RSW=X,YZ  ''(8(8(CDrW   c                 <   UR                   U La  [        S5      eS nU R                  R                  5        H  nUR                  UL d  M    O   Uc  [        S5      eS U l        UR                  nUR                  nU R                  R                  U5        UcB  U(       a:  [        UR                  [        5      (       a  U R                  R                  U5        O:[        UR                  [        5      (       a  U R                  R                  U5        S Ul         g )Nz%Paragraph is part of a different filezunable to find paragraph)r  r   r-  r   r^   rY   r  r   r   r  r   r&   )rN   rR  rO   r   r   s        rT   rh   Deb822FileElement.remove  s    ##4/DEE,,779DzzY& : <9:: $**NN	  ,,T2M,?,?AV!W!W((44]C)//+@AA((44Y?#'	 rW   c                     Xl         U$ rK   )r  )rN   r   s     rT   r>  Deb822FileElement._set_parent&  s    rW   c                     [         $ rK   r   r_   s    rT   r   $Deb822FileElement.position_in_parent+      rW   c                     [         $ rK   rN  r_   s    rT   r#  "Deb822FileElement.position_in_file/  rP  rW   c                     g rK   ru   r  s     rT   r  Deb822FileElement.dump3  r  rW   c                     g rK   ru   r_   s    rT   r  rT  :  r  rW   c                     Uc&  SR                  S U R                  5        5       5      $ U R                  5        H-  nUR                  UR                  R	                  S5      5        M/     g )Nr2  c              3   8   #    U  H  oR                   v   M     g 7frK   r<  r=  s     rT   r   )Deb822FileElement.dump.<locals>.<genexpr>C  r  r?  r  r  r  s      rT   r  rT  >  r  rW   )r  r-  rK   )rk   rl   rm   rn   ro   rU   r  r1  rq   r~  r5  rJ  r   r   r  r   rh   r>  r   r   r#  r   r  rr   rt   r  r  s   @rT   r+  r+  r
  s    +% ! ! 7t 7 7$b
E,DXL$EL(,
H (    c    rW   r+  )constructorc                 P    U (       a  [         R                  $ [         R                  $ rK   )r  r{  r  )discard_commentss    rT   _parsed_value_render_factoryr\  U  s!    HX#DD 6%556rW   c                      [        S5      $ r  )r$   ru   rW   rT   rw  rw  _  s    AZ[^A_rW   c                 X    [        U [        5      (       + =(       d    U R                  S:g  $ r   )r   r&   r  r  s    rT   _non_end_of_line_tokenr_  r  s"     !233Eqvv~ErW   c           	   #   $  #    [        U 5      nSnSnSnU GHt  nSn[        U[        5      (       a  UnSnSnOs[        U[        5      (       a  SnO[[        U[        5      (       aF  UR                  5       n[        U[        5      (       a!  SnUnSn[        S[        US5      5      nUc   eUb  Uv   U(       d  M  [        UR                  [        5      5      n[        S[        US5      5      nUb  UR                  S:X  d   eSn	Sn
U(       ae  [        US   [        5      (       a  [        SUR                  5       5      n
U(       a,  [        US   [        5      (       a  [        SUS   5      n	US	S n[        UUU	UU
U5      v   SnSnGMw     g7f)
zYParser helper - consumes tokens part of a Deb822ValueEntryElement and turns them into oneNFTr'   r&   r   r  r   r  )r   r   r'   r+   r  peekr   r   list	takewhiler_  r  r&   r   r7  )token_streambuffered_streamr?  r@  r  start_of_value_entry
next_tokentokens_in_value	eol_tokenleading_whitespacetrailing_whitespaces              rT   _build_value_linerl  x  s     (5O: O"E $e9::&+##' E899#' 344(--/J *&BCC'+$"' +//M/3OT/J+1' /:::K"?#<#<=S#TUO4d?D6QRI$	$(>>>!%"&  ob13HII*./F/>/B/B/D+1' #z/"2EG\']'])-.EWXGY)Z&&5ab&9O()@);)8)<)2+ + #O&*#q !s   B5F;CFc              #   t  #    [        U 5      nU GH  nSnS n[        U[        5      (       a  SnOJ[        U[        5      (       a5  UnUR	                  5       n[        U[        5      nU(       a   [        U5      nU(       Ga  Un[        US 5      n[        US 5      nUb  Uc1  U(       a  Uv   U/n	Ub  U	R                  U5        [        U	5      v     g [        U[        5      (       a2  [        U[        5      (       a  [        U[        SU5      UU5      v   GM
  U/n
U
R                  UR                  [         5      5        UR	                  5       nU(       a2  [        U["        5      (       a  [        US 5        U
R                  U5        [        U
5      v   GM  Uv   GM     g ! [         a    [        ef = f7f)NFTr*   )r   r   r*   r  ra  r   StopIterationAssertionErrorr   r+  r+   r_  rA   r   rl  rc  r_  r(   )rd  re  token_or_elementstart_of_fieldr?  rg  r7  	separatorrX  error_elementserror_tokensnls               rT   _build_field_with_valuerv    s     (5O+&(<==!N(*>??.O(--/J'
4HIN)'+O'<$ )J_d3I $7M M$9 #))",(")))4(88)%>??"=2DEE/045KZ0X090=2 2 !11##O$=$=>T$UV$))+*R)EFF$/ ''+(66 #"e , % )(()s   A,F8/F$:D*F8$F55F8c              #      #    SnU  Hr  nUR                   (       a9  UR                  5       R                  SS5      n[        SR	                  UUS95      eXR                  5       R                  S5      -  nUv   Mt     g 7f)Nr  r   z\nzBSyntax or Parse error on or near line {line_no}: "{error_as_text}")error_as_textline_no)r  r  r   r1   r  count)sequencery  r  rx  s       rT   _abort_on_error_tokensr|    s     G>>!113;;D%HM$T[["/# \ %& & 	((*0066 s   A<A>r  )accept_files_with_error_tokens#accept_files_with_duplicated_fieldsencodingc                   [        U [        [        45      (       a  U R                  S5      n [	        XS9nU(       d  [        U5      n[        U5      n[        U5      n[        U5      n[        U5      n[        U5      n[        U5      n[        [        U5      5      nU(       d  [        U5       H  u  pg[        U[        5      (       d  M  [!        5       nSn	UR#                  5        HC  n
[%        U
5      u  n  n[        U[        5      (       d   eX;   a  Un	  OUR'                  U5        ME     U	c  M  Sn[)        UR+                  XS95      e   U$ )a;  

:param sequence: An iterable over lines of str or bytes (an open file for
  reading will do).  If line endings are provided in the input, then they
  must be present on every line (except the last) will be preserved as-is.
  If omitted and the content is at least 2 lines, then parser will assume
  implicit newlines.
:param accept_files_with_error_tokens: If True, files with critical syntax
  or parse errors will be returned as "successfully" parsed. Usually,
  working on files with this kind of errors are not desirable as it is
  hard to make sense of such files (and they might in fact not be a deb822
  file at all).  When set to False (the default) a ValueError is raised if
  there is a critical syntax or parse error.
  Note that duplicated fields in a paragraph is not considered a critical
  parse error by this parser as the implementation can gracefully cope
  with these. Use accept_files_with_duplicated_fields to determine if
  such files should be accepted.
:param accept_files_with_duplicated_fields: If True, then
  files containing paragraphs with duplicated fields will be returned as
  "successfully" parsed even though they are invalid according to the
  specification.  The paragraphs will prefer the first appearance of the
  field unless caller explicitly requests otherwise (e.g., via
  Deb822ParagraphElement.configured_view).  If False, then this method
  will raise a ValueError if any duplicated fields are seen inside any
  paragraph.
:param encoding: The encoding to use (this is here to support Deb822-like
   APIs, new code should not use this parameter).
T)r  Nz6Duplicate field "{dup_field}" in paragraph number {no})	dup_fieldno)r   rr   bytesrH  r-   r|  %_combine_comment_tokens_into_elementsrl  (_combine_vl_elements_into_value_elementsrv  %_combine_kvp_elements_into_paragraphs#_combine_error_tokens_into_elementsr+  r3   r  rR  setkeysr  addr   r  )r{  r}  r~  r  rr  rP  r  rR  field_namesr  rf  r7  r  r  s                 rT   rI  rI  !  s4   H (S%L))&&t, "(>F)'/26:Fv&F5f=F$V,F26:F 18F#Jv$67K.&{3MB)%JKK!e 	&^^-E'25'9$J1%j#6666!0$.	OOJ/ . (RC$SZZ)Z%KLL 4  rW   __main__r}  )collections.abccollections
contextlibsysr  rL   abcr   typesr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   debian._deb822_repro._utilr   r   r   debian._deb822_repro.formatterr   r   r   debian._deb822_repro.locatabler   r   r   r    debian._deb822_repro.tokensr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   debian._deb822_repro.typesr0   r1   debian._utilr2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   StreamingValueParserrr   StrToValueParserKVPNoderC   version_infoAbstractContextManagerry   r   r  r  r   r  r  r  r  r  r+  r  r+  r7  r_  r  r  rA   r
  r  r  r  r  r  r  r#  r,  r@  rK  rR  r+  r  r  r  rU  r  r\  #LIST_SPACE_SEPARATED_INTERPRETATION#LIST_COMMA_SEPARATED_INTERPRETATIONLIST_UPLOADERS_INTERPRETATIONr_  rl  rv  r|  rI  rk   doctesttestmodru   rW   rT   <module>r     s%     
         "* *  V U     X      .?.L Mr QR SE8E-2C,D#EEF 
4
5PWR[ Pf v,6,M,Ma,P)
 _%GBFOABab_%D"WQZ ">1q(971b5> >1B!H
:;PQSUWQW;XZ\;\] 
D-
+1$-1`VI VrD} DB 4X&] X&v <"$} "$J(= (6G" G"T "'"6	/ v(__44\1_E!8!8'!*c %"%;A%> %"Vg1'9#'>'*g1T4%7%:C 465)G)J 5* A$B3$G$D AFq],Lc qhCJ.D CJLb5,B b5JT Tn '??OQc&d #(@ASAU)W %+CDZDV,X ((@&33) %6 '99S9U9Q9`9_9U'; # '99N9P9Q9I9I9U'; # !33H3N3K3C3C3O!5 F]+@7#t" 6;:?&	M` zOO rW   