
    'f.                     \   d Z ddlZddlZddlZddlmZ 	 ddlZn+# e$ r#  ej	        d            ej
        d           Y nw xY w	 ddlmZmZ ddlmZ dZn# e$ r d	ZY nw xY w	 dd
lmZ dZn# e$ r
 	 ddZd	ZY nw xY wd Z	 	 	 ddZd Zej        dd            Z G d d          ZdS )z>This module implements facilities to deal with Debian control.    N)Loggerz=Please install 'python3-debian' in order to use this utility.   )Deb822ParagraphElementparse_deb822_file)Deb822TokenTF)one_value_per_line_formatterc                      t          d          )NzHBug: The dummy one_value_per_line_formatter method should not be called!)AssertionError)indentationtrailing_separatorimmediate_empty_lines      4/usr/lib/python3/dist-packages/devscripts/control.pyr   r   ,   s     V
 
 	
    c              #   p   K   d}dV  | D ]}|s|V  |j         sdV  d}|V  |r|j         s|V  dV  d S )NT F
)is_whitespace)value_tokens	sep_tokenr   first_tokentokens        r   _emit_one_line_valuer   6   s      K
III   	OOO* 			 )"9 
JJJJJr   c                     t           st          d          | dk    r| dk     rt          d          t          | |          dk     rS fd}|S )a5  Provide a formatter that can handle indentation and trailing separators

    This is a custom wrap-and-sort formatter capable of supporting wrap-and-sort's
    needs. Where possible it delegates to python-debian's own formatter.

    :param indentation: Either the literal string "FIELD_NAME_LENGTH" or a positive
    integer, which determines the indentation fields.  If it is an integer,
    then a fixed indentation is used (notably the value 1 ensures the shortest
    possible indentation).  Otherwise, if it is "FIELD_NAME_LENGTH", then the
    indentation is set such that it aligns the values based on the field name.
    This parameter only affects values placed on the second line or later lines.
    :param trailing_separator: If True, then the last value will have a trailing
    separator token (e.g., ",") after it.
    :param immediate_empty_line: Whether the value should always start with an
    empty line.  If True, then the result becomes something like "Field:
 value".
    This parameter only applies to the values that will be formatted over more than
    one line.
    :param max_line_length_one_liner: If greater than zero, then this is the max length
    of the value if it is crammed into a "one-liner" value.  If the value(s) fit into
    one line, this parameter will overrule immediate_empty_line.

    z5wrap_and_sort_formatter requires python-debian 0.1.44FIELD_NAME_LENGTHr   z7indentation must be at least 1 (or "FIELD_NAME_LENGTH"))r   r   c              3     K   dk    sJ t          |          }d |D             }t          d |D                       rsd|j        rdndz   }t          d |D                       }|t	          |          dz
  |z  z  }|t	          |           dz   z  }|k    rt          ||	          E d {V  d S  | ||          E d {V  d S )Nr   c                 .    g | ]}|j         s|j        |S  )
is_commentis_value.0xs     r   
<listcomp>z?wrap_and_sort_formatter.<locals>._formatter.<locals>.<listcomp>z   s&    SSSQS
SqSSSr   c              3   $   K   | ]}|j         V  d S N)r   r    s     r   	<genexpr>z>wrap_and_sort_formatter.<locals>._formatter.<locals>.<genexpr>~   s$      77aqz777777r   r   c              3   >   K   | ]}t          |j                  V  d S r%   )lentextr    s     r   r&   z>wrap_and_sort_formatter.<locals>._formatter.<locals>.<genexpr>   s*      EEACKKEEEEEEr      )listallr   sumr(   r   )
namer   formatter_tokens
all_tokensvalues_and_commentschars_between_values	total_len_chain_formattermax_line_length_one_linerr   s
          r   
_formatterz+wrap_and_sort_formatter.<locals>._formatteru   s@      )1,,,,*++
SS*SSS 77#677777 	 $%Y-D(K!#L EE1DEEEEEI#122Q6:NNNITQ&I555/'4F          $#D)Z@@@@@@@@@@@r   )HAS_FULL_RTS_FORMATTINGNotImplementedError
ValueErrorr   )r   r   r   r5   r6   r4   s    ` ` @r   wrap_and_sort_formatterr:   E   s    8 # 
!C
 
 	
 )))kAooRSSS 4-1   !1$$A A A A A A A< r   c                    	 | j          || |<   	 |                      ||           n# t          $ r Y nw xY wdS # t          $ r Y nw xY wd}| D ]+}|r|                     |          }|| |<   ||k    rd}|| |<   ,|s|| |<   dS dS )zbInsert new_item into directly after item_before

    New items added to a dictionary are appended.NFT)order_afterKeyErrorAttributeErrorpop)	paragraphitem_beforenew_item	new_value
item_founditemvalues          r   _insert_afterrG      s    
 (	(	!!(K8888 	 	 	 D	 	     J , , 	$MM$''E#IdO;J"+Ih ('	(( (s   8 & 
33
AAutf-8c              +   r   K   |.t          | fd|i|5 }|V  d d d            d S # 1 swxY w Y   d S |V  d S )Nencoding)open)filenamefdrJ   kwargsfileobjs        r   _openrP      s      	z(88X888 	GMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 s   &**c                   \    e Zd ZdZddZed             Zd Zd Zd Z	d Z
dd	Zd
 Zd ZdS )Controlz Represents a debian/control fileNc                 n   |,t           j                            |          sJ | d            || _        || _        d| _        | j        rot          st          d          t          ||d          5 }t          |          | _
        d d d            n# 1 swxY w Y   t          | j
                  | _        d S d | _
        g | _        t          ||d          5 }t          j        j                            |          D ]}| j                            |           	 d d d            d S # 1 swxY w Y   d S )Nz does not exist.Fz@The use_rts_parser option requires python-debian 0.1.43 or laterutf8)rM   rJ   )ospathisfilerL   _is_roundtrip_safe!strip_trailing_whitespace_on_saveHAS_RTS_PARSERr9   rP   r   _deb822_filer+   
paragraphsdebiandeb822Deb822iter_paragraphsappend)selfrL   rM   use_rts_parsersequencer@   s         r   __init__zControl.__init__   s   ~!9!9~~h;X;X;X~~~ "016." 	6 "  V   xB888 @H$5h$?$?!@ @ @ @ @ @ @ @ @ @ @ @ @ @ @"4#455DOOO $D DOxB888 6H!'!5!E!Eh!O!O 6 6IO**9555566 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6s%   3BBBAD**D.1D.c                     | j         S r%   )rX   rb   s    r   is_roundtrip_safezControl.is_roundtrip_safe   s    &&r   c                 B    | j         d                             d          S )z*Returns the value of the Maintainer field.r   
Maintainerr\   getrg   s    r   get_maintainerzControl.get_maintainer   s    q!%%l333r   c                 B    | j         d                             d          S )z8Returns the value of the XSBC-Original-Maintainer field.r   XSBC-Original-Maintainerrk   rg   s    r   get_original_maintainerzControl.get_original_maintainer   s    q!%%&@AAAr   c                     | j         r|                                 }n$d                    d | j        D                       }| j        r4d                    d |                                D                       dz   }|S )Nr   c              3   >   K   | ]}|                                 V  d S r%   )dumpr    s     r   r&   zControl.dump.<locals>.<genexpr>   s*      BBQBBBBBBr   c              3   >   K   | ]}|                                 V  d S r%   )rstripr    s     r   r&   zControl.dump.<locals>.<genexpr>   s*      IIq

IIIIIIr   )rh   _dump_rts_filejoinr\   rY   
splitlines)rb   contents     r   rs   zControl.dump   s    ! 	C))++GGiiBB$/BBBBBG1 	QiiIIG4F4F4H4HIIIIIDPGr   c                 <   d}d}d}| j                                         D ]{}t          |t                    r%| j        |                                         }|dz  }n3t          |t                    r
|j        rd}[|                                }|r|dz  }||z  }||S )Nr    Fr   Tr   )	r[   
iter_parts
isinstancer   r\   rs   r   r   convert_to_text)rb   paragraph_indexnew_contentpending_newlinepartpart_contents         r   rv   zControl._dump_rts_file   s     %0022 	( 	(D$ 677 6#?DDFF1$D+.. 	643E 	6 #'#3355 $t#<'KKr   c                     |r|| _         |                                 }t          | j         d          5 }|                    |                    d                     ddd           dS # 1 swxY w Y   dS )zSaves the control file.wbrH   N)rL   rs   rK   writeencode)rb   rL   ry   control_files       r   savezControl.save  s     	%$DM))++$-&& 	8,w~~g66777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   )A))A-0A-c                 &    || j         d         d<   dS )z'Sets the value of the Maintainer field.r   rj   N)r\   )rb   
maintainers     r   set_maintainerzControl.set_maintainer  s    +5<(((r   c                     d| j         d         v r|| j         d         d<   dS t          | j         d         dd|           dS )z5Sets the value of the XSBC-Original-Maintainer field.ro   r   rj   N)r\   rG   )rb   original_maintainers     r   set_original_maintainerzControl.set_original_maintainer  s[    %);;;=PDOA9:::"*#	    r   )NNr%   )__name__
__module____qualname____doc__re   propertyrh   rm   rp   rs   rv   r   r   r   r   r   r   rR   rR      s        **6 6 6 64 ' ' X'4 4 4B B B    <8 8 8 86 6 6
 
 
 
 
r   rR   )TF)TFr   )NrH   )r   
contextlibrU   sysdevscripts.loggerr   debian.deb822r]   ImportErrorerrorexitdebian._deb822_repror   r   debian._deb822_repro.tokensr   rZ   debian._deb822_repro.formatterr   r7   r   r:   rG   contextmanagerrP   rR   r   r   r   <module>r      s  " E D     				 



 $ $ $ $ $ $   FLPQQQCHQKKKKKNNNNNNNN777777NN   NNN$KKKKKK" 	$ 	$ 	$ DI
 
 
 
 $	$  " 	N N N Nb( ( (>    f f f f f f f f f fs3    %AAA A"!A"&A/ /A>=A>