U ʗRe\ @sddlZddlmZddlZddlmZmZmZmZmZm Z m Z m Z ddl m Z ddlmZddlZdZe eZeddefd ejejfd efgZed ZGd d d ejZGdddejZGdddeeZeeedddZdedddZd0ejeje ee!e!eedddZ"ee eje!ddd Z#Gd!d"d"Z$Gd#d$d$Z%eje!d%d&d'Z&d(d)Z'e ejd*d+d,Z(e'd1ejejee%eeee!e!ejed- d.d/Z)dS)2N) pyparsing)List NamedTupleGenericTypeVarDictCallableSetIterable)Template)StringIOaM {% if not head %} {% else %} {{ head | safe }} {% endif %} {{ body | safe }} {% for diagram in diagrams %}

{{ diagram.title }}

{{ diagram.text }}
{{ diagram.svg }}
{% endfor %} 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|df|}tj|d}tj||jddS)Nitemlabel)railroadChoicelen OneOrMoresuper__init__ all_label)selfitemsZ choice_itemZone_or_more_item __class__/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/pyparsing/diagram/__init__.pyrIs zEachItem.__init__)__name__ __module__ __qualname____doc__rr __classcell__r#r#r!r$r>srcs&eZdZdZedfdd ZZS) AnnotatedItemzC Simple subclass of Group that creates an annotation label rcs"tj||rd|n|ddS)Nz[{}]rr)rrformat)rrrr!r#r$rTszAnnotatedItem.__init__)r%r&r'r(strrr)r#r#r!r$r*Osr*c@s`eZdZdZedefeedddZe edefdddd Z e d d Z ed d dZ dS)EditablePartialz Acts like a functools.partial, but can be edited. In other words, it represents a type that hasn't yet been constructed. .funcargskwargscCs||_||_||_dSNr/)rr0r1r2r#r#r$raszEditablePartial.__init__EditablePartial[T])r0returncOst|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) r/)r.list)clsr0r1r2r#r#r$ from_callfszEditablePartial.from_callcCs |jdS)Nr)r2rr#r#r$rnszEditablePartial.namer5cCsH|j}|j}t|j}|j|jkr<|||j7}|j||S)z< Evaluate the partial and return the result )r1copyr2inspectgetfullargspecr0varargspop)rr1r2Zarg_specr#r#r$__call__rs     zEditablePartial.__call__N)r%r&r'r(rrr6dictr classmethodr8propertyrr@r#r#r#r$r.Xs r.)diagramsr5cKspg}|D]R}|jdkrqt}|j|j|j}|jdkrD|d7}||d|dqtj fd|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 Nrz (root))titletextsvgrD) rr ZwriteSvgwriterrappendgetvaluetemplaterender)rDr2datariorFr#r#r$railroad_to_htmls  rPr4)partialr5cCsdt|tr(t|j|_t|j|_|St|tr@dd|DSt|tr\dd|DS|SdS)zS Recursively resolves a collection of Partials into whatever type they are cSsg|] }t|qSr#resolve_partial).0xr#r#r$ sz#resolve_partial..cSsi|]\}}|t|qSr#rR)rTkeyrUr#r#r$ sz#resolve_partial..N) isinstancer.rSr1r2r6rAr )rQr#r#r$rSs     rSF)elementdiagram_kwargsverticalshow_results_names show_groupsr5c Cst|pid}t||d|||dt|}||krV|jsBd||_||j||ddt|j}t |dkrt }g} |D]:} | jdkrq~| jdk r~| j|kr~| | j| | q~d d | D} nd d |D} t | d d dS)a 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 :param show_groups - bool to indicate whether groups should be highlighted with an unlabeled surrounding box r\N)lookupparentr]r^r_rET)forcerz...cSsg|] }t|qSr#rRrTrQr#r#r$rVszto_railroad..cSsg|] }t|qSr#rRrdr#r#r$rVscSs|jSr3r)Zdiagr#r#r$zto_railroad..rW)ConverterState_to_diagram_elementid customNamermark_for_extractionr6rDvaluesrsetaddrJsorted) r[r\r]r^r_raZroot_idZdiagsseenZ deduped_diagsdresolvedr#r#r$ to_railroads6      ru) specificationexprsr5cCs |dkr dStt||kSdS)zF Returns true if we should return a vertical list of elements NF)r_visible_exprs)rvrwr#r#r$_should_verticalsryc@sHeZdZdZd ejeeeee j edddZ d edee dd d Z dS) ElementStatez< State recorded for an individual pyparsing Element N)r[ convertedrbnumberr parent_indexcCs4||_||_||_||_||_||_d|_d|_dS)NF)r[rr{rbr|r}extractcomplete)rr[r{rbr|rr}r#r#r$rs zElementState.__init__Fri)el_idstaterrccCsTd|_|js2|r||_n|jjr,|jj|_nd|_|sF|jrPt|jrP||dS)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 TrEN)r~rr[rlr_worth_extractingextract_into_diagram)rrrrrcr#r#r$rm s  z ElementState.mark_for_extraction)NN)NF)r%r&r'r(r ParserElementr.intr-typingOptionalrboolrmr#r#r#r$rzs&  rzc@seZdZdZdejedddZee dddZ ee d d d Z ed d dZ ed ddZ edddZedddZedddZdS)rizR Stores some state that persists between recursions into the element tree Nr`cCs.i|_i|_d|_d|_|pi|_t|_dS)Nrr)_element_diagram_statesrD unnamed_indexrr\roZextracted_diagram_names)rr\r#r#r$r.s  zConverterState.__init__)rWvaluecCs||j|<dSr3r)rrWrr#r#r$ __setitem__;szConverterState.__setitem__)rWr5cCs |j|Sr3rrrWr#r#r$ __getitem__>szConverterState.__getitem__rhcCs |j|=dSr3rrr#r#r$ __delitem__AszConverterState.__delitem__cCs ||jkSr3rrr#r#r$ __contains__DszConverterState.__contains__r:cCs|jd7_|jS)zT Generate a number used in the name of an otherwise unnamed diagram r)rr9r#r#r$generate_unnamedGszConverterState.generate_unnamedcCs|jd7_|jS)z; Generate a number used to index a diagram rrer9r#r#r$generate_indexNszConverterState.generate_index)rcCs||}|jrXtjtj|jd}d|jjkr:||jjd<nd|jjkrX||jjd|j<|jj tj krt|jjd}n|j}tjt |jtjtj |f|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 rGrr )rrrN)rbr.r8r NonTerminalrr2r}r{r0Groupr ZDiagramr\r|rD)rrpositionretcontentr#r#r$rUs,   z#ConverterState.extract_into_diagram)N)r%r&r'r(rrrArrrzrrrrrrrr#r#r#r$ri)s ri)r[r5cCs|}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|]}|VqdSr3)recurse)rTchildr#r#r$ }sz$_worth_extracting..)rany)r[childrenr#r#r$rwsrc s6dtjtjttttttttjtd fdd }|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) NrF r[rbrar]r name_hintr^r_r5c sT||||||||}|rP|dk rP|j} | rP| |jr8dnd7} tjtj|| d}|S)NrE*r+) resultsName modalResultsr.r8rr) r[rbrar]rrr^r_relement_results_namefnr#r$_inners(  z0_apply_diagram_item_enhancements.._inner)NNrNFF) rrrrr.rirr-r)rrr#rr$ _apply_diagram_item_enhancementss$ "rrwcs$tjtjtjjffdd|DS)Ncs&g|]}|js|jst|s|qSr#)rlrrYrTeZnon_diagramming_exprsr#r$rVs  z"_visible_exprs..)rParseElementEnhance PositionTokenAnd _ErrorStoprr#rr$rxs rxrc Cs8|}|p|jp|jj} t|} |j} |jsnt|tjfrn|rn|djsP| } nd} t |j ||||| ||dSt |r| |kr|| } | j | ||dt jtj| jd}|S| |jkrt jtj|j| jdd}|St|tjrV|sdSttdd|Dd kr$t jtjd tt|d }n.t||rBt jtjgd }nt jtjgd }nBt|tjtjfr|stdSt||rt jtjdgd }nt jtjgd }nt|tj r|sdSt jt!gd }nt|tj"rt jt#d d d}nt|tj$rt jt#dd d}nt|tj%r8t jt#dd d}n`t|tj&rt|r^t jt#d d d}nt jtj&d d d}n$t|tj'rt jt#t(|j)d d}nt|tj*rt jtj+d d}nt|tjrt jtjd d}nt|tj,rt jtj,d d}nt|tj&r t jtj&d| d}nxt|tj-r<|js||jd<n"d|jkrz||jd|<|d 7}nd|jkr|jd|=q|rd|jkrt|jddksd|jkr|jddkrt tj.| }| |krd|| _3| |kr4|| j4r4|| j3r4|5| |dk r4t jtj|j| jdd}|S)ay Recursively converts a PyParsing Element to a railroad Element :param lookup: The shared converter state that keeps track of useful things :param index: The index of this element within the parent :param parent: The parent of this element in the output tree :param vertical: Controls at what point we make a list of elements vertical. If this is an integer (the default), it sets the threshold of the number of items before we go vertical. If True, always go vertical, if False, never do so :param name_hint: If provided, this will override the generated name :param show_results_names: bool flag indicating whether to add annotations for results names :returns: The converted version of the input element, but as a Partial that hasn't yet been constructed :param show_groups: bool flag indicating whether to show groups using bounding box rN)rbrar]rrr^r_)rrrcss|]}|j|jfVqdSr3)rrrr#r#r$rsz&_to_diagram_element..rrE)rrepeat)r ZNOT)rrZ LOOKAHEADZ LOOKBEHINDrr+)r[r{rbr}r|r )rbrar]rr^r_rT)6rrlr"r%rkrrYrLocatedrjexprrrmr.r8rrrrDr2rrrorr-ryStackSequenceOr MatchFirstrZHorizontalChoiceEachrNotAnyr* FollowedBy PrecededByrTokenConvertertypelowerOptr ZeroOrMoreEmptyZTerminal defaultNamerzrinsertrr~r)r[rbrar]rrr^r_rwrrrZpropagated_nameZ looked_uprZterminalirrr#r#r$rjs$                    "  rj)NrZFF)NNrNFF)*r pip._vendorrrrrrrrrr r Zjinja2r rOr r<Zjinja2_template_sourcerLr-rZ DiagramItemrr rrrr*r.rPrSrrArruryrzrirrrxrjr#r#r#r$sr (   * ; >N ,