o |a4@sddlZddlmZzddlmZmZmZmZmZmZm Z m Z m Z m Z e dZ Wn ey3dZ YnwddZGdd d eZeZd d ZGd d d ee ZGdddee ZGdddeZdS)N) ReferenceType) IterableOptionalGenericDictListIteratorTypeVar TYPE_CHECKINGAnyCallableTFcCs|dur|SdSN)refrr./usr/lib/python3/dist-packages/debian/_util.py resolve_refsrcs\eZdZdZddgZerfddZddZdd Zd d Z d d Z ddZ ddZ Z S)_CaseInsensitiveStringzCase insensitive string. str_lowerstr_origcs tt||d|_d|_dS)N)superr__init__rr)selfs __class__rrrs z_CaseInsensitiveString.__init__cCs t||}||_||_|Sr)str__new__rlowerr)clsstr_rrrrr$s  z_CaseInsensitiveString.__new__cC|jSr)rrrrr__str__,z_CaseInsensitiveString.__str__cC t|jSr)hashrr#rrr__hash__0 z_CaseInsensitiveString.__hash__cCs&z|j|kWStyYdSw)NF)rrAttributeErrorrotherrrr__eq__4s  z_CaseInsensitiveString.__eq__cCs ||k Srrr+rrr__ne__;r)z_CaseInsensitiveString.__ne__cCr"r)rr#rrrr?r%z_CaseInsensitiveString.lower)__name__ __module__ __qualname____doc__ __slots__r rrr$r(r-r.r __classcell__rrrrrs rcCs|Sr)rxrrrdefault_field_sort_keyGsr7c@s~eZdZdZddZeddZejddZddZd d d d Z d d d dZ e ddZ e ddZ ddZddZdS)LinkedListNode)_previous_nodevalue next_node __weakref__cCsd|_d|_||_dSr)r9r;r:rr:rrrrP zLinkedListNode.__init__cCr&r)rr9r#rrr previous_nodeV zLinkedListNode.previous_nodecCs"|dur t||_dSd|_dSr)weakrefrr9rnoderrrr?[s"cCs"t|j|jd|_d|_|jSr)r8 link_nodesr?r;r:r#rrrremove`szLinkedListNode.removeF) skip_currentcc,|r|jn|}|r|V|j}|s dSdSr)r;rrFrCrrr iter_nextg  zLinkedListNode.iter_nextccrGr)r?rHrrr iter_previousprJzLinkedListNode.iter_previouscCs|r||_|r ||_dSdSrr?r;rLrrrrDys  zLinkedListNode.link_nodescCst||t||dSr)r8rD) first_nodenew_node last_noderrr _insert_links zLinkedListNode._insert_linkcCs*||ur ||jus Jt|j||dSr)r?r8rPrrNrrr insert_beforezLinkedListNode.insert_beforecCs*||ur ||jus Jt|||jdSr)r;r8rPrQrrr insert_afterrSzLinkedListNode.insert_afterN)r/r0r1r3rpropertyr?setterrErIrK staticmethodrDrPrRrTrrrrr8Ls$       r8c@seZdZdZdZd&ddZddZdd Zed d Z d d Z ddZ ddZ ddZ ddZddZddZddZddZddZd d!Zd"d#Zd$d%ZdS)' LinkedListavSpecialized linked list implementation to support the deb822 parser needs We deliberately trade "encapsulation" for features needed by this library to facilitate their implementation. Notably, we allow nodes to leak and assume well-behaved calls to remove_node - because that makes it easier to implement components like Deb822InvalidParagraphElement.  head_node tail_node_sizeNcCs,d|_d|_d|_|dur||dSdSNr)rZr[r\extend)rvaluesrrrrs zLinkedList.__init__cCs |jduSr)rZr#rrr__bool__r)zLinkedList.__bool__cCr"r)r\r#rrr__len__r%zLinkedList.__len__cCs|jdur |jjSdSr)r[r:r#rrrtailszLinkedList.tailcCs"|jdur td||jdS)Nzpop from empty list)r[ IndexError remove_noder#rrrpops zLinkedList.popccs&|j}|dur dS|EdHdSr)rZrI)rrZrrr iter_nodess zLinkedList.iter_nodesccsdd|DEdHdS)Ncs|]}|jVqdSrr:).0rCrrr z&LinkedList.__iter__..)rfr#rrr__iter__szLinkedList.__iter__ccs0|j}|dur dSdd|DEdHdS)Ncsrgrrh)rinrrrrjrkz*LinkedList.__reversed__..)r[rK)rr[rrr __reversed__s zLinkedList.__reversed__cCsl||jur|j|_|jdurd|_n||jur"|j|_|jdus"J|jdks)J|jd8_|dS)Nr)rZr;r[r?r\rErBrrrrds    zLinkedList.remove_nodecCs"|jdur ||S|||jSr)rZappendrRr=rrrinsert_at_heads  zLinkedList.insert_at_headcCsRt|}|jdur||_||_n|jdusJ|j|||_|jd7_|S)Nro)r8rZr[rTr\)rr:rCrrrrps  zLinkedList.appendcC|t||Sr)insert_node_beforer8rr: existing_noderrrrRzLinkedList.insert_beforecCrrr)insert_node_afterr8rtrrrrTrvzLinkedList.insert_aftercCZ|jdur td|jdus|jdurtd||||jur$||_|jd7_|SNz,List is empty; node argument cannot be validz&New node must not already be inserted!ro)rZ ValueErrorr;r?rRr\rrNrurrrrs   zLinkedList.insert_node_beforecCrxry)r[rzr;r?rTr\r{rrrrwr|zLinkedList.insert_node_aftercC|D]}||qdSr)rp)rr_vrrrr^ zLinkedList.extendcCsd|_d|_d|_dSr]rYr#rrrclearr>zLinkedList.clearr)r/r0r1r2r3rr`rarUrbrerfrlrnrdrqrprRrTrsrwr^rrrrrrXs*    rXc@s~eZdZdZdddZddZddZd d Zd d Zd dZ ddZ eZ ddZ ddZ ddZddZddZddZdS) OrderedSetzA set-like object that preserves order when iterating over it We use this to keep track of keys in Deb822Dict, because it's much faster to look up if a key is in a set than in a list. NcCs2i|_t|_|dur g}|D]}||qdSr)_OrderedSet__tablerX_OrderedSet__orderaddriterableitemrrrr#s zOrderedSet.__init__cCsF||vr!|j|}z||j|<WdSty |j|wdSr)rrpr ExceptionrdrrrCrrrr1s   zOrderedSet.addcCs"|j|}|j|=|j|dSr)rrrdrrrrrE?s zOrderedSet.removecCr&r)iterrr#rrrrlGr@zOrderedSet.__iter__cCstt|jSr)rreversedrr#rrrrnLszOrderedSet.__reversed__cCr&r)lenrr#rrrraQr)zOrderedSet.__len__cCs ||jvSr)rrrrrr __contains__Us zOrderedSet.__contains__cCr}r)rrrrrr^^rzOrderedSet.extendcC|||jjdS)z2Re-order the given item so it is "last" in the setN)_reorderrrprrrr order_lastdzOrderedSet.order_lastcCr)z3Re-order the given item so it is "first" in the setN)rrrqrrrr order_firstirzOrderedSet.order_firstc4||krtdj||fdddS)zTRe-order the given item so appears directly after the reference item in the sequence*Cannot re-order an item relative to itselfcj|Sr)rrRr5reference_noderrrtz)OrderedSet.order_before..Nrzrrrrreference_itemrrr order_beforen zOrderedSet.order_beforecr)zURe-order the given item so appears directly before the reference item in the sequencercrr)rrTr5rrrr|rz(OrderedSet.order_after..Nrrrrr order_aftervrzOrderedSet.order_aftercCs.|j|}|j|||j}||j|<dSr)rrrdr:)rr reinserterrCrNrrrr~s   zOrderedSet._reorderr)r/r0r1r2rrrErlrnrarrpr^rrrrrrrrrrs   r)rArtypingrrrrrrr r r r r ImportErrorrrr_strIr7r8rXobjectrrrrrs  0  -I