
    Cfc<%                        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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#y# e$ r dZd ZY w xY w)    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          	      J   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        |
|      rb|j                  ||
j                  j                  t        |
j                               f        |||
j                  j                  z          d} nR ||t        |
      z           |j                          d}|(||z   |k  r |r|dt        |      z  } ||dz   |z          |ryy)	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!,,
',Ry$$# 	AG!OJ~E
*'=1j'*;*;*D*Dd7K]K]K_F`ab):):)C)C CDFS\12	A IIKF+;K0Kz0Y^b>!CJ.F 84 ?@' r   )constructorc                8     |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).
    zCallable[[List[TE]], R]c              3      K   g }| D ]I  }t        |      r|j                  |       !|r# t        |             |j                          | K |r |       y y wr   )r%   r*   listclear)token_streamtokenstoken_constructorsource_classs      r   _implz'combine_into_replacement.<locals>._imple   si     ! 	E%.e$"4<00K	 v&& s   AA")r   )rB   replacement_classr9   rC   rA   s   `   @r   combine_into_replacementrE   T   s,     57HI #'  Lr   )   	   c                       e Zd Zy)_bufferingIterator_BaseN)r,   
__module____qualname__r   r   r   rI   rI   }   s    r   rI   c                   L    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y)BufferingIteratorc                 d    t        |      | _        t        j                         | _        d| _        y )NF)r&   _streamcollectionsdeque_buffer_expired)selfstreams     r   __init__zBufferingIterator.__init__   s$    F|"((*r   c                     | j                   r| j                   j                         S | j                  rt        t	        | j
                        S r   )rR   popleftrS   StopIterationnextrO   rT   s    r   __next__zBufferingIterator.__next__   s8    <<<<''))==DLL!!r   c              #      K   | j                   }|s| j                  d      r9|d   } ||      r|j                          | ny|r&| j                  d      r8yyw)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   sU      ))!,q	A|  ))!,s   AAAAc                     | j                  |       | j                  }t        |      |k(  rt        |      }|j	                          |S g }|r+|r)|j                  |j                                |dz  }|r|r)|S Nr#   )r^   rR   r)   r<   r=   r*   rX   )rT   countr`   rets       r   consume_manyzBufferingIterator.consume_many   st    % v;%v,CLLN 
	 CU

6>>+,
 U 
r   c                 ,    t        | j                        S r   )r<   rR   r[   s    r   peek_bufferzBufferingIterator.peek_buffer   s    DLL!!r   Nc                     | j                   }d}|||k  rQ|t        |      k\  r#| j                  |dz          |t        |      k\  ry ||   } ||      r|dz   S |dz  }|K||k  rQy )Nr   r   r#   )rR   r)   r^   )rT   r_   limitr`   ir   s         r   	peek_findzBufferingIterator.peek_find   s~    
 mq5yCK!!!a%(F#q	A|1uFA mq5y r   c                 0   | j                   s`t        | j                        |k  rH	 | j                  j                  t	        | j
                               t        | j                        |k  rHt        | j                        S # t        $ r
 d| _         Y 'w xY w)NT)rS   r)   rR   r*   rZ   rO   rY   bool)rT   numbers     r   r^   zBufferingIterator._fill_buffer   sy    }}dll#f,LL''T\\(:; dll#f, DLL!! % $(DMs   .B BBc                 $    | j                  d      S rc   )peek_atr[   s    r   peekzBufferingIterator.peek   s    ||Ar   c                 |    | j                  |       t        | j                        |k\  r| j                  |dz
     S d S rc   )r^   r)   rR   )rT   tokens_aheads     r   rq   zBufferingIterator.peek_at   s:    ,'14T\\1Bl1Rt||L1,-\X\\r   c                     | j                  |       | j                  }t        |      |k(  rt        |      }|S |r&g }|D ]  }|j	                  |       |dz  }|r |S  |S g }|S rc   )r^   rR   r)   r<   r*   )rT   ro   r`   re   r   s        r   	peek_manyzBufferingIterator.peek_many   s    &!v;& v,C 
 C 

1! 
 
 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 ]A  }	 t        d|      j                         }|D ]  }|t        |j                        z  } 	 | C ||k7  ri||k  r2t        j                  d      j                  |||       }t        |      t        j                  d      j                  |||       }t        |      y# t        $ r' t        d|      }|t        |j                        z  }Y w xY ww)	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      s     'lG" 	+/+;<HHJF
   +3uzz?*+ +[ // #  [wO  S/!oo    [RYZ	 	
 o   	'(89Es5::&G	's(   C:CBC:-C74C:6C77C: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()*	+ :7
  !"2Ap *.!H v)oo66q9+//":":GAJ c/2GAJ cP $("g  MDs   A C 
C+*C+