
    \e?                         d Z ddlZddlZddlZddlZ ej
                  d      Z G d d      Z G d d      Ze	dk(  rd	Z
 ee
      Z ee       yy)
z;deb822 parser with support for comment headers and footers.    NTc                      e Zd ZU dZej
                  eef   ed<   eeef   ed<   eed<   eed<   de	j                  ed f   fdZded	efd
Zded	dfdZdeded	dfdZd	efdZe	j"                  ded	edz  fd       Ze	j"                  deded	eez  fd       Zddededz  d	edz  ez  fdZeded	efd       Zd	efdZy)SectionzcA single deb822 section, possibly with comments.

    This represents a single deb822 section.
    tags_case_mappingheaderfootersectionc                    t        |t              rut        j                  |j                        | _        | j                  D ci c]  }|j                         | c}| _        |j                  | _        |j                  | _        y ddg}d}d}|j                  d      D ]3  }|j                  d      r|dd  }||xx   |dz   z  cc<   *d}||dz   z  }5 t        j                  t        j                  |            | _        | j                  D ci c]  }|j                         | c}| _        |\  | _        | _        y c c}w c c}w )N F
#   T)
isinstancer   collectionsOrderedDictr   casefoldr   r   r	   split
startswithapt_pkg
TagSection)selfr
   kcomments
in_sectiontrimmed_sectionlines          4/usr/lib/python3/dist-packages/aptsources/_deb822.py__init__zSection.__init__   s"   gw'#//=DI;?99!Ea!**,/!ED!..DK!..DK8
MM$' 	+Ds#ABx$t3$Jtd{*O	+  ++G,>,>,OP	7;yyA!ajjlAoA#+ T[+ "F( Bs   E Ekeyreturnc                 p    | j                   | j                  j                  |j                         |         S )zGet the value of a field.r   r   getr   r   r    s     r   __getitem__zSection.__getitem__7   s*    yy++//DEE    Nc                 n    | j                   | j                  j                  |j                         |      = y)zDelete a fieldNr#   r%   s     r   __delitem__zSection.__delitem__;   s'    IId((,,S\\^SABr'   valc                     |j                         | j                  vr|| j                  |j                         <   || j                  | j                  |j                            <   y)zSet the value of a field.N)r   r   r   )r   r    r*   s      r   __setitem__zSection.__setitem__?   sK    <<>!3!3314Ds||~.8;		$$$S\\^45r'   c                 ,    t        | j                        S N)boolr   r   s    r   __bool__zSection.__bool__E   s    DIIr'   c                      y r.    r%   s     r   r$   zSection.getH       r'   defaultc                      y r.   r3   r   r    r5   s      r   r$   zSection.getL   r4   r'   c                 0    	 | |   S # t         $ r |cY S w xY wr.   )KeyErrorr7   s      r   r$   zSection.getP   s%    	9 	N	s    contentc                 \    | r)dj                  d | j                         D              dz   S dS )Nr   c              3   &   K   | ]	  }d |z     yw)r   Nr3   ).0r   s     r   	<genexpr>z*Section.__comment_lines.<locals>.<genexpr>Y   s     BTcDjBs   r   )join
splitlines)r:   s    r   __comment_lineszSection.__comment_linesV   s8      IIBW-?-?-ABBTI	
 	
r'   c                     | j                  | j                        dj                  d | j                  j	                         D              z   | j                  | j
                        z   S )z+Canonical string rendering of this section.r   c              3   2   K   | ]  \  }}| d | d  yw)z: r   Nr3   )r=   r   vs      r   r>   z"Section.__str__.<locals>.<genexpr>b   s      B12aSmB   )_Section__comment_linesr   r?   r   itemsr	   r0   s    r   __str__zSection.__str__^   sU       -ggB		0ABBC""4;;/0	
r'   r.   )__name__
__module____qualname____doc__r   r   str__annotations__dicttypingUnionr   r&   r)   r,   r/   r1   overloadr$   r   staticmethodrF   rH   r3   r'   r   r   r      sP   
 
!
!#s(
++S>!KK,S)^ < ,4Fs Fs FCs Ct C<s < < <$  __s sTz   __s Q 1s7  s QX TC  
 
 
 

 
r'   r   c                   b    e Zd ZdZdej
                  fdZdej                  e	   fdZ
defdZy)FilezC
    Parse a given file object into a list of Section objects.
    fobjc                     g | _         d}|D ]A  }|j                         s||z  }|s| j                   j                  t        |             d}C |r%| j                   j                  t        |             y y )Nr   )sectionsisspaceappendr   )r   rV   r
   r   s       r   r   zFile.__init__l   so     	D<<>4$$WW%56	 MM  !12 r'   r!   c                 ,    t        | j                        S r.   )iterrX   r0   s    r   __iter__zFile.__iter__|   s    DMM""r'   c                 F    dj                  d | j                  D              S )Nr   c              3   2   K   | ]  }t        |        y wr.   )rM   )r=   ss     r   r>   zFile.__str__.<locals>.<genexpr>   s     7AQ7rE   )r?   rX   r0   s    r   rH   zFile.__str__   s    yy7777r'   N)rI   rJ   rK   rL   io
TextIOBaser   rP   Iteratorr   r]   rM   rH   r3   r'   r   rU   rU   g   s8    3R]] 3 #&//'2 #8 8r'   rU   __main__zV# Header
# More header
K1: V1
# Inline
K2: V2
 # not a comment
# Footer
# More footer
)rL   r   ra   rP   r   TypeVarr   r   rU   rI   str`   printr3   r'   r   <module>rh      sf    B  	  FNN3R
 R
j8 88 z
B 	A	!H r'   