o 7]h@s>ddlZddlZddlZddlZddlmZddlmZmZm Z e dZ GdddZ eddd e d ed e fd d Zeddd e d ed e fddZeddd e d ed efddZGdddZGdddZGdddZGdddeZded efddZ d$deee efded efdd Zd!ed efd"d#ZdS)%N) lru_cache)ListUnionIterable\c@sZeZdZUdZgZeeed<gZeeed<dZ e ddZ e ddZ e d dZ d S) __config_flagsz=Internal class for defining compatibility and debugging flags _all_names _fixed_names configurationc Csb||jvrtd|j||jtt||dS||j vr(t |||dSt d|j|)Nz'{}.{} {} is {} and cannot be overriddenzno such {} {!r}) r warningswarnformat__name__ _type_descstrgetattrupperrsetattr ValueError)clsdnamevaluer$ z__config_flags.cCr)NFrrrrrr%r N)r __module__ __qualname____doc__rrr__annotations__r r classmethodrenabledisablerrrrr s   r)maxsizelocstrgreturncCsF|}d|krt|krnn ||ddkrdS||dd|S)a Returns current column within a string, counting newlines as line separators. The first column is number 1. Note: the default parsing behavior is to expand tabs in the input string before starting the parsing process. See :class:`ParserElement.parseString` for more information on parsing strings containing ```` s, and suggested methods to maintain a consistent view of the parsed string, the parse location, and line and column positions within the parsed string. r )lenrfind)r*r+srrrcol(s Br2cCs|dd|dS)aReturns current line number within a string, counting newlines as line separators. The first line is number 1. Note - the default parsing behavior is to expand tabs in the input string before starting the parsing process. See :class:`ParserElement.parseString` for more information on parsing strings containing ```` s, and suggested methods to maintain a consistent view of the parsed string, the parse location, and line and column positions within the parsed string. r.rr-)count)r*r+rrrlineno9s r4cCsB|dd|}|d|}|dkr||d|S||ddS)zh Returns the line of text containing loc within a string, counting newlines as line separators. r.rr-N)r0find)r*r+last_crnext_crrrrlineGs (r8c@eZdZddZdS)_UnboundedCachecspijt|_fdd}fdd}fdd}d|_t|||_t|||_t|||_dS)Nc |SNr_key cache_get not_in_cacherrgetW z%_UnboundedCache.__init__..getcs ||<dSr<rr>r?rcacherrset_Z z&_UnboundedCache.__init__..set_c dSr<clearr>rFrrrL]rIz'_UnboundedCache.__init__..clear)rCobjectrBsizetypes MethodTypesetrL)selfrCrHrLr)rGrArBr__init__Rs   z_UnboundedCache.__init__Nrr!r"rTrrrrr:Q r:c@r9) _FifoCachecsvt|_tjfdd}fdd}fdd}|_t|||_t|||_t|||_ dS)Ncr;r<rr=r@rrrClrDz _FifoCache.__init__..getcs4||<tkrjddtks dSdSNF)last)r/popitemrE)rGrOrrrHos  z!_FifoCache.__init__..set_crJr<rKrMrFrrrLtrIz"_FifoCache.__init__..clear) rNrB collections OrderedDictrCrOrPrQrRrL)rSrOrCrHrLr)rGrArBrOrrTgs  z_FifoCache.__init__NrUrrrrrWfrVrWc@s8eZdZdZddZddZddZdd Zd d Zd S) LRUMemoz A memoizing mapping that retains `capacity` deleted items The memo tracks retained items by their access order; once `capacity` items are retained, the least recently used item is discarded. cCs||_i|_t|_dSr<) _capacity_activer[r\_memory)rScapacityrrrrTszLRUMemo.__init__cCs6z|j|WSty|j||j|YSwr<)r_KeyErrorr` move_to_endrSr?rrr __getitem__s    zLRUMemo.__getitem__cCs|j|d||j|<dSr<)r`popr_rSr?rrrr __setitem__szLRUMemo.__setitem__cCsbz|j|}Wn tyYdSwt|j|jkr*|jjddt|j|jks||j|<dSrX)r_rfrbr/r`r^rZrgrrr __delitem__s zLRUMemo.__delitem__cCs|j|jdSr<)r_rLr`)rSrrrrLs z LRUMemo.clearN) rr!r"r#rTrerhrirLrrrrr]}s r]c@seZdZdZddZdS) UnboundedMemoz< A memoizing mapping that retains all deleted items cCsdSr<rrdrrrrizUnboundedMemo.__delitem__N)rr!r"r#rirrrrrjs rjr1cCs:dD] }||t|}q|dd}|dd}t|S)Nz\^-[]r.z\n z\t)replace_bslashr)r1crrr_escape_regex_range_charss   rpT re_escapec sfddd_t_d_dddd}|s|g}d tt|}t|d krytj |d D]B\}}t |}}t j t t|g|d d }||kr[||q5t|t|d krgd nd}|d|||q5n fdd|D}d |S)Ncs4t|}|j_}||dkrtj_jS)Nr-)ordprevnextcounterr)roc_intrs)is_consecutiverrrws   z2_collapse_string_to_ranges..is_consecutivercSs|dvrd|S|S)Nz\^-][\rrorrrescape_re_range_charsz8_collapse_string_to_ranges..escape_re_range_charcSs|Sr<rrzrrrno_escape_re_range_charrkz;_collapse_string_to_ranges..no_escape_re_range_char)r?r-)maxlen-z{}{}{}csg|]}|qSrr).0ro)r{rr sz._collapse_string_to_ranges..)rs itertoolsr3rurjoinsortedrRr/groupbyrtr[dequechainiterrfappendrrr ) r1rqr|retr>charsfirstrYsepr)r{rwr_collapse_string_to_rangess:     rllcCs6g}|D]}t|tr|t|q||q|Sr<) isinstancelistextend_flattenr)rrirrrrs   r)T)r rPr[r functoolsrtypingrrrchrrnrintrr2r4r8r:rWr]dictrjrpboolrrrrrrrs8   '   .