
    )uyc<%                        d dl Z d dlZ d dlZd dlZd dlZd dlmZ 	 d dlmZm	Z	m
Z
mZmZmZmZmZmZmZ d dlmZ d dlmZmZmZ ee
e	eef                  ge
e	eef                  f         Zn# e$ r dZd ZY nw xY werd dlmZ d d	lmZ d
dddZdddZej         dk    sere j        j        e         Z!n  G d de j        j        ee         e          Z! G d de!e         ee                   Z"	 ddZ#dS )    N)ABC)
OptionalUnionIterableCallableTYPE_CHECKINGIteratorTypecastListGeneric)T)TERTokenOrElementFc                     |S N )tvs     </usr/lib/python3/dist-packages/debian/_deb822_repro/_util.py<lambda>r      s         Deb822Element)Deb822Token   )end_marker_afteroutput_functionc          	         ddl m} d}t          | |          r| g} ddt          |           fg}d}|t          j        }|r|d         \  }}}	|	D ]}
|dz  }|dt          |          z  }t          |
|          r]|                    ||
j        j	        t          |

                                          f            |||
j        j	        z              d} nd ||t          |
          z              |                                 d}|0||z   |k    r'|r%|dt          |          z  } ||dz   |z              |dS dS )	a~  Debugging aid, which can dump a Deb822Element or a list of tokens/elements

    :param ast_tree: Either a Deb822Element or an iterable Deb822Token/Deb822Element entries
      (both types may be mixed in the same iterable, which enable it to dump the
      ast tree at different stages of parse_deb822_file method)
    :param end_marker_after: The dump will add "end of element" markers if a
      given element spans at least this many tokens/elements. Can be disabled
      with by passing None as value. Use 0 for unconditionally marking all
      elements (note that tokens never get an "end of element" marker as they
      are not an elements).
    :param output_function: Callable that receives a single str argument and is responsible
      for "displaying" that line. The callable may be invoked multiple times (one per line
      of output).  Defaults to logging.info if omitted.

    r   r   N    z  z# <-- END OF )debian._deb822_repro.parsingr   
isinstanceiterlogginginfolenappend	__class____name__
iter_partsstrpop)ast_treer   r   r   prefixstack
current_nostart_nonamecurrent_itercurrents              r   	print_astr8      s   . ;:::::F(M** :T(^^$%EJ!,
 A',Ry$$# 	A 	AG!OJ~E

*'=11 j'*;*Dd7K]K]K_K_F`F`abbb):)C CDDDOFS\\12222 IIKKKF+;K0Kz0Y0Y^b0Y>!CJJ.F 84 ?@@@'  A A A A Ar   )constructorc                @     |t          d|          n| fd}|S )zCombines runs of one type into another type

    This is primarily useful for transforming tokens (e.g, Comment tokens) into
    the relevant element (such as the Comment element).
    NzCallable[[List[TE]], R]c              3      K   g }| D ]\}t          |          r|                    |           (|r. t          |                    V  |                                 |V  ]|r |          V  d S d S r   )r%   r*   listclear)token_streamtokenstoken_constructorsource_classs      r   _implz'combine_into_replacement.<locals>._imple   s      ! 	 	E%.. e$$$ "l4<<00000KKKK 	',v&&&&&&&	' 	'r   )r   )rB   replacement_classr9   rC   rA   s   `   @r   combine_into_replacementrE   T   sK     57HII #' ' ' ' ' '  Lr   )   	   c                       e Zd ZdS )_bufferingIterator_BaseN)r,   
__module____qualname__r   r   r   rI   rI   }   s        r   rI   c                   N    e Zd Zd Zd Zd Zd Zd Z	 ddZd Z	d	 Z
d
 Zd ZdS )BufferingIteratorc                 l    t          |          | _        t          j                    | _        d| _        d S )NF)r&   _streamcollectionsdeque_buffer_expired)selfstreams     r   __init__zBufferingIterator.__init__   s*    F||"(**r   c                     | j         r| j                                         S | j        rt          t	          | j                  S r   )rR   popleftrS   StopIterationnextrO   rT   s    r   __next__zBufferingIterator.__next__   s@    < 	*<'')))= 	 DL!!!r   c              #      K   | j         }|s|                     d          rG|d         } ||          r|                                 |V  ndS |0|                     d          EdS dS )zVVariant of itertools.takewhile except it does not discard the first non-matching tokenr   r   N)rR   _fill_bufferrX   )rT   	predicatebufferr   s       r   	takewhilezBufferingIterator.takewhile   s        	))!,, 	q	Ay||      	))!,, 	 	 	 	 	r   c                    |                      |           | j        }t          |          |k    r$t          |          }|                                 n6g }|r2|r0|                    |                                           |dz  }|r|0|S Nr#   )r^   rR   r)   r<   r=   r*   rX   )rT   countr`   rets       r   consume_manyzBufferingIterator.consume_many   s    %   v;;%v,,CLLNNNNC U 

6>>++,,,
  U  
r   c                 *    t          | j                  S r   )r<   rR   r[   s    r   peek_bufferzBufferingIterator.peek_buffer   s    DL!!!r   Nc                     | j         }d}|||k     re|t          |          k    r-|                     |dz              |t          |          k    rd S ||         } ||          r|dz   S |dz  }|_||k     ed S )Nr   r   r#   )rR   r)   r^   )rT   r_   limitr`   ir   s         r   	peek_findzBufferingIterator.peek_find   s    
 mq5yyCKK!!!a%(((F##4q	Ay|| 1uFA mq5yy tr   c                 "   | j         sut          | j                  |k     r]	 | j                            t	          | j                             n# t          $ r
 d| _         Y nw xY wt          | j                  |k     ]t          | j                  S )NT)rS   r)   rR   r*   rZ   rO   rY   bool)rT   numbers     r   r^   zBufferingIterator._fill_buffer   s    } 	dl##f,,L''T\(:(:;;;;$   $(DME dl##f,, DL!!!s   ,A A"!A"c                 ,    |                      d          S rc   )peek_atr[   s    r   peekzBufferingIterator.peek   s    ||Ar   c                     |                      |           t          | j                  |k    r| j        |dz
           nd S rc   )r^   r)   rR   )rT   tokens_aheads     r   rq   zBufferingIterator.peek_at   sB    ,'''14T\1B1Bl1R1Rt|L1,--X\\r   c                     |                      |           | j        }t          |          |k    rt          |          }n*|r&g }|D ] }|                    |           |dz  }|s n!ng }|S rc   )r^   rR   r)   r<   r*   )rT   ro   r`   re   r   s        r   	peek_manyzBufferingIterator.peek_many   s    &!!!v;;&  v,,CC 	C  

1! E C
r   r   )r,   rJ   rK   rV   r\   ra   rf   rh   rl   r^   rr   rq   rv   r   r   r   rM   rM      s          " " "
 
 
  " " "    $	" 	" 	"  ] ] ]
    r   rM   c              #   ,  K   |t          |           }d}|D ]}}	 t          d|                                          }|D ]}|t          |j                  z  }n7# t          $ r* t          d|          }|t          |j                  z  }Y nw xY w|V  ~||k    rx||k     r9t          j        d                              |||           }t          |          t          j        d                              |||           }t          |          dS )	zOFlatten a parser's output into tokens and verify it covers the entire line/textNr   r   r   z            Value parser did not fully cover the entire line with tokens (
            missing range {covered}..{content_len}).  Occurred when parsing "{content}"
            )coveredcontent_lenlinez                    Value parser emitted tokens for more text than was present?  Should have
                     emitted {content_len} characters, got {covered}. Occurred when parsing
                     "{content}"
                    )rx   ry   content)	r)   r   iter_tokenstextAttributeErrortextwrapdedentformat
ValueError)r{   rU   ry   rx   token_or_elementr?   r@   msgs           r   len_check_iteratorr      sd      'llG"  	+/+;<<HHJJF
   + +3uz??*+	  	' 	' 	'(899Es5:&GGG	' +[  / #   [wOO  S//!o     [RYZZ	 	
 oo s   "A1BBr   )$rP   collections.abcr'   sysr   abcr   typingr   r   r   r   r   r	   r
   r   r   r   debian._utilr   debian._deb822_repro.typesr   r   r   _combine_parts_ret_typeImportErrorr$   r   debian._deb822_repro.tokensr   r8   rE   version_inforI   rM   r   r   r   r   <module>r      s            



                               @@@@@@@@@@&	%*+	,-~q()*	+    M>DDD  8::::::777777
  !"2A 2A 2A 2A 2Ap *.! ! ! ! !H v)o6q9    +/":GAJ   c c c c c/2GAJ c c cP $(" " " " " "s   AA, ,
A98A9