o |aj#@sddlZddlZddlZddlZz;ddlmZmZmZmZm Z m Z m Z m Z m Z ddlmZddlmZmZmZeeeeefgeeeeffZWneyZdZ ddZ Ynwe riddlmZdd lmZd dd d d ZddddZGdddejj eZ dddZdS)N) OptionalUnionIterableCallable TYPE_CHECKINGIteratorTypecastList)T)TERTokenOrElementFcCs|SN)tvrrsr Deb822Element) Deb822Token)end_marker_afteroutput_functionc Csddlm}d}t||r|g}ddt|fg}d}|dur!tj}|r|d\}}} | D]7} |d7}|dur._impl)r )r;replacement_classr3r<rr9rcombine_into_replacementQs  r>c@sneZdZdeeddfddZddZdd Zd d Zd d Z dddZ ddZ ddZ ddZ ddZdS)BufferingIteratorstreamreturnNcCst||_t|_d|_dS)NF)r _stream collectionsdeque_buffer_expired)selfr@rrr__init__ws   zBufferingIterator.__init__cCs$|jr|jS|jr tt|jSr)rEpopleftrF StopIterationnextrBrGrrr__next__|s   zBufferingIterator.__next__ccsP|j}|s |dr&|d}||r||VndS|s |ds dSdS)zVVariant of itertools.takewhile except it does not discard the first non-matching tokenrrN)rE _fill_bufferrI)rG predicatebufferrrrr takewhileszBufferingIterator.takewhilecCs^|||j}t||krt|}||Sg}|r-|r-|||d8}|r-|s|SNr)rNrEr#r4r5r$rI)rGcountrPretrrr consume_manys  zBufferingIterator.consume_manycCs t|jSr)r4rErLrrr peek_buffer zBufferingIterator.peek_buffercCsx|j}d}|dus ||kr:|t|kr"||d|t|kr"dS||}||r.|dS|d7}|dus ||ks dS)Nrrr)rEr#rN)rGrOlimitrPirrrr peek_finds   zBufferingIterator.peek_findcCs\|js)t|j|kr)z |jt|jWn ty!d|_Ynwt|j|ks t|jS)NT)rFr#rEr$rKrBrJbool)rGnumberrrrrNs  zBufferingIterator._fill_buffercCs |dSrR)peek_atrLrrrpeekrWzBufferingIterator.peekcCs"|||jr|j|dSdSrR)rNrE)rG tokens_aheadrrrr]s zBufferingIterator.peek_atcCsb|||j}t||krt|}|S|r-g}|D]}|||d8}|s*|Sq|Sg}|SrR)rNrEr#r4r$)rGr\rPrTrrrr peek_manys"    zBufferingIterator.peek_manyr)r& __module__ __qualname__rr rHrMrQrUrVrZrNr^r]r`rrrrr?us    r?c cs|dur t|}d}|D]0}z td|}Wnty-td|}|t|j7}Yn w|D] }|t|j7}q0|Vq ||krd||krUtdj|||d}t|tdj|||d}t|dS) zOFlatten a parser's output into tokens and verify it covers the entire line/textNrrrz Value parser did not fully cover the entire line with tokens ( missing range {covered}..{content_len}). Occurred when parsing "{content}" )covered content_lenlinez Value parser emitted tokens for more text than was present? Should have emitted {content_len} characters, got {covered}. Occurred when parsing "{content}" )rcrdcontent) r#r iter_tokensAttributeErrortexttextwrapdedentformat ValueError)rfr@rdrctoken_or_elementr7r8msgrrrlen_check_iterators2  rpr)rCcollections.abcr!rjtypingrrrrrrrr r debian._utilr debian._deb822_repro.typesr r r_combine_parts_ret_type ImportErrorrrdebian._deb822_repro.tokensrr2r>abcr?rprrrrs8,      8 $g