o 7]hV@sddlZddlmZddlmZddlmZmZmZm Z m Z m Z m Z m Z mZddlmZddlmZddlZeeeddd ZeeZWdn1sPwYed d efd eejfd efgZ e dZGdddejZGdddejZ Gddde eZ!deedefddZ"dddefddZ#   d8dej$d ee%d!ed"e&deef d#d$Z'd%ed&eej$de&fd'd(Z(Gd)d*d*Z)Gd+d,d,Z*dej$de&fd-d.Z+d/d0Z,d&eej$fd1d2Z-e,    d9dej$d3ee!d4e*d!ed ed5ed"e&dee!fd6d7Z.dS):N) pyparsing)resource_filename) ListOptional NamedTupleGenericTypeVarDictCallableSetIterable)Template)StringIOztemplate.jinja2zutf-8)encoding NamedDiagramnamediagramindexTcs$eZdZdZdZfddZZS)EachItemz Custom railroad item to compose a: - Group containing a - OneOrMore containing a - Choice of the elements in the Each with the group label indicating that all must be matched z[ALL]cs<tjt|dg|R}tj|d}tj||jddS)Nitem)label)railroadChoicelen OneOrMoresuper__init__ all_label)selfitems choice_itemone_or_more_item __class__H/usr/lib/python3/dist-packages/pip/_vendor/pyparsing/diagram/__init__.pyr-s zEachItem.__init__)__name__ __module__ __qualname____doc__r r __classcell__r'r'r%r(r"srcs&eZdZdZdeffdd ZZS) AnnotatedItemzC Simple subclass of Group that creates an annotation label rcstj|d|ddS)Nz[{}]rr)rrformat)r!rrr%r'r(r8szAnnotatedItem.__init__)r)r*r+r,strrr-r'r'r%r(r.3sr.c@sfeZdZdZdedefdedefddZe dedefdd fd d Z e d d Z defddZ dS)EditablePartialz Acts like a functools.partial, but can be edited. In other words, it represents a type that hasn't yet been constructed. func.argskwargscCs||_||_||_dSNr3r4r5)r!r3r4r5r'r'r(rEs zEditablePartial.__init__returnEditablePartial[T]cOst|t||dS)z If you call this function in the same way that you would call the constructor, it will store the arguments as you expect. For example EditablePartial.from_call(Fraction, 1, 3)() == Fraction(1, 3) r7)r2list)clsr3r4r5r'r'r( from_callJszEditablePartial.from_callcCs |jdS)Nr)r5r!r'r'r(rRs zEditablePartial.namecCsL|j}|j}t|j}|j|jvr|||j7}|j|i|S)z< Evaluate the partial and return the result )r4copyr5inspectgetfullargspecr3varargspop)r!r4r5arg_specr'r'r(__call__Vs    zEditablePartial.__call__N)r)r*r+r,r rr:dictr classmethodr<propertyrrDr'r'r'r(r2<s r2diagramsr8cKsdg}|D]#}t}|j|j|j}|jdkr|d7}||d|dqtj dd|i|S)z Given a list of NamedDiagram, produce a single HTML string that visualises those diagrams :params kwargs: kwargs to be passed in to the template rz (root))titletextsvgrHNr') rrwriteSvgwriterrappendgetvaluetemplaterender)rHr5datariorJr'r'r(railroad_to_htmlfs rUpartialr9cCs`t|trt|j|_t|j|_|St|tr dd|DSt|tr.dd|DS|S)zS Recursively resolves a collection of Partials into whatever type they are cSg|]}t|qSr'resolve_partial).0xr'r'r( z#resolve_partial..cSsi|] \}}|t|qSr'rX)rZkeyr[r'r'r( sz#resolve_partial..) isinstancer2rYr4r5r:rEr")rVr'r'r(rYws     rYFelementdiagram_kwargsverticalshow_results_namesc Cst|pid}t||d||dt|}||vr*|js d||_||j||ddt|j}t |dkrdt }g}|D]} | jdkrFq>| jdur[| j|vr[| | j| | q>d d |D} nd d |D} t | d d dS)aO Convert a pyparsing element tree into a list of diagrams. This is the recommended entrypoint to diagram creation if you want to access the Railroad tree before it is converted to HTML :param element: base element of the parser being diagrammed :param diagram_kwargs: kwargs to pass to the Diagram() constructor :param vertical: (optional) - int - limit at which number of alternatives should be shown vertically instead of horizontally :param show_results_names - bool to indicate whether results name annotations should be included in the diagram )rcN)lookupparentrdrerIT)forcerz...cSrWr'rXrZrVr'r'r(r\r]zto_railroad..cSrWr'rXrir'r'r(r\r]cSs|jSr6r)diagr'r'r(szto_railroad..)r^)ConverterState_to_diagram_elementid customNamermark_for_extractionr:rHvaluesrsetaddrOsorted) rbrcrdrerfroot_iddiagsseen deduped_diagsdresolvedr'r'r( to_railroads6     r| specificationexprscCs|durdStt||kS)zF Returns true if we should return a vertical list of elements NF)r_visible_exprs)r}r~r'r'r(_should_verticalsrc@s\eZdZdZ  ddejdedededede ef d d Z dd ed ddede fddZ dS) ElementStatez< State recorded for an individual pyparsing Element Nrb convertedrgnumberr parent_indexcCs4||_||_||_||_||_||_d|_d|_dSNF)rbrrrgrrextractcomplete)r!rbrrgrrrr'r'r(rs  zElementState.__init__Fel_idstatermrhcCs\d|_|js|r ||_n |jjr|jj|_nd|_|s#|jr*t|jr,||dSdSdS)a Called when this instance has been seen twice, and thus should eventually be extracted into a sub-diagram :param el_id: id of the element :param state: element/diagram state tracker :param name: name to use for this element's text :param force: If true, force extraction now, regardless of the state of this. Only useful for extracting the root element when we know we're finished TrIN)rrrbrpr_worth_extractingextract_into_diagram)r!rrrrhr'r'r(rqs  z ElementState.mark_for_extraction)NNr) r)r*r+r,r ParserElementr2intr1rrboolrqr'r'r'r(rs6  rc@seZdZdZddeefddZdedefdd Z ded efd d Z defd dZ defddZ d efddZ d efddZdefddZdS)rmzR Stores some state that persists between recursions into the element tree NrccCs.i|_i|_d|_d|_|pi|_t|_dS)Nrr)_element_diagram_statesrH unnamed_indexrrcrsextracted_diagram_names)r!rcr'r'r(r s   zConverterState.__init__r^valuecCs||j|<dSr6r)r!r^rr'r'r( __setitem__szConverterState.__setitem__r8cCs |j|Sr6rr!r^r'r'r( __getitem__ zConverterState.__getitem__cCs |j|=dSr6rrr'r'r( __delitem__s zConverterState.__delitem__cCs ||jvSr6rrr'r'r( __contains__"rzConverterState.__contains__cC|jd7_|jS)zT Generate a number used in the name of an otherwise unnamed diagram r)rr=r'r'r(generate_unnamed%zConverterState.generate_unnamedcCr)z; Generate a number used to index a diagram rrjr=r'r'r(generate_index,rzConverterState.generate_indexrcCs||}|jr,tjtj|jd}d|jjvr||jjd<nd|jjvr,||jjd|j<|jj tj kr:|jjd}n|j}tjt |jtjtj |fi|j |jd|j|<||=dS)z Used when we encounter the same token twice in the same tree. When this happens, we replace all instances of that token with a terminal, and create a new subdiagram for the token rKrr")rrrN)rgr2r<r NonTerminalrr5rrr3GrouprDiagramrcrrH)r!rpositionretcontentr'r'r(r3s*   z#ConverterState.extract_into_diagramr6)r)r*r+r,rrErrrrrrrrrrr'r'r'r(rms rmcCs|}tdd|DS)z Returns true if this element is worth having its own sub-diagram. Simply, if any of its children themselves have children, then its complex enough to extract css|]}|VqdSr6)recurse)rZchildr'r'r( [sz$_worth_extracting..)rany)rbchildrenr'r'r(rUsrcsH     ddtjdttdtdtdtd td td ttffd d }|S)z decorator to ensure enhancements to a diagram item (such as results name annotations) get applied on return from _to_diagram_element (we do this since there are several returns in _to_diagram_element) NrFrbrgrfrdr name_hintrer8c sR|||||||}|r'|dur'|j}|r'||jrdnd7}tjtj||d}|S)NrI*r/) resultsName modalResultsr2r<rr) rbrgrfrdrrrerelement_results_namefnr'r(_inneres"  z0_apply_diagram_item_enhancements.._innerNNrNF)rrrr2rmrr1r)rrr'rr( _apply_diagram_item_enhancements^s.  rcs$tjtjtjjffdd|DS)Ncs&g|]}|js|jst|s|qSr')rprr`rZenon_diagramming_exprsr'r(r\sz"_visible_exprs..)rParseElementEnhance PositionTokenAnd _ErrorStop)r~r'rr(rs rrgrfrc Cs|}|p |jp |jj}t|} |j} |js8t|tjtj fr8|r8|djs*|} nd} t |j ||||| |dSt |rl| |vrW|| } | j | ||dtjtj| jd} | S| |jvrltjtj|j| jdd} | St|tjr|svdSttdd|Dd krtjtjd tt|d } nt||rtjtjgd } ntjtjgd } nt|tjtjfr|sdSt||rtjtjdgd } ntjtj gd } nt|tj!r|sdStjt"gd } nt|tj#rtjt$d d d} nt|tj%rtjt$dd d} nt|tj&r tjt$dd d} n}t|tj'rtjtj(d d} nmt|tjr-tjtjd d} n]t|tj)r=tjtj)d d} nMt|tj*rNtjtj*d| d} n.rrI)rrepeat)r"NOT)rr LOOKAHEAD LOOKBEHINDrr/)rbrrgrrr")rgrfrdrrerT)4rrpr&r)rorr`rTokenConverterLocatedrnexprrrqr2r<rrrrHr5rrrsrr1rStackSequenceOr MatchFirstrHorizontalChoiceEachrNotAnyr. FollowedBy PrecededByOptr ZeroOrMorerEmptyTerminal defaultNamerrinsertrrr)rbrgrfrdrrrer~rrrpropagated_name looked_uprterminalirrr'r'r(rns                   "  rn)NraFr)/r pip._vendorrpip._vendor.pkg_resourcesrtypingrrrrrr r r r jinja2r rTrr?openr)fpreadrQr1 DiagramItemrrrrrr.r2rUrYrrErr|rrrmrrrrnr'r'r'r(s  ,  * 6  >N *