K iipddlmZddlZddlZddlZddlZddlZddlmZmZm Z m Z ddl m Z ddl mZddlZddlZdZe eZiZej(dZd d Zd!d Zej0Gd d Zed ZGddej6ZGddej6ZGddeeZd"d#dZd$dZ d% d&dZ! d'dZ"ej0GddZ#GddZ$d(dZ%dZ&d)dZ'e& d* d+dZ(y),) annotationsN)GenericTypeVarCallableIterable)Template)StringIOa{% if not embed %} {% endif %} {% if not head %} {% else %} {{ head | safe }} {% endif %} {% if not embed %} {% endif %} {{ body | safe }} {% for diagram in diagrams %}

{{ diagram.title }}

{{ diagram.text }}
{{ diagram.svg }}
{% endfor %} {% if not embed %} {% endif %} )startc|tvr t|Stjdd|}|ddjsd|}|j j d}|dt tdxt|<}|S)zK Converts a string into a valid HTML bookmark (ID or anchor name). z[^a-zA-Z0-9-]+-Nr z04d)_bookmark_lookupresubisalphalowerstripnext _bookmark_ids)sbookmarks `/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pyparsing/diagram/__init__.py_make_bookmarkr?s ""vv'a0H BQ<   !xj>~~%%c*H(0z4 3Fs2K%LLQ( Ocd|vr|Stjdjj|}t j dd|}|S)N z#.*$z\s*\n\s*) pyparsingRegexsuppresstransform_stringrr) regex_str collapseds r_collapse_verbose_regexr&UsJ 9(113DDYOI{B 2I rcDeZdZUdZded<ded<dZded<ed Zy) NamedDiagramzK A simple structure for associating a name with a railroad diagram strnameintindexNzrailroad.DiagramItemdiagramc0t|j}|SN)rr*)selfrs rrzNamedDiagram.bookmarkgs!$)),r)__name__ __module__ __qualname____doc____annotations__r-propertyrrrr(r(]s0 I J$(G !( rr(Tc(eZdZdZdZdfd ZxZS)EachItema$ Custom railroad item to compose a: - :class:`railroad.Group` containing a - :class:`railroad.OneOrMore` containing a - :class:`railroad.Choice` of the elements in the :class:`railroad.Each` with the group label indicating that all must be matched z[ALL]ctjt|dz g|}tj|}t|||j y)Nr item)label)railroadChoicelen OneOrMoresuper__init__ all_label)r0items choice_itemone_or_more_item __class__s rrDzEachItem.__init__sFooc%j1n=u= #--;? )@r)returnNone)r1r2r3r4rErD __classcell__rIs@rr:r:ps IAArr:c$eZdZdZdfd ZxZS) AnnotatedItemzC Simple subclass of Group that creates an annotation label cDt|||r d|dydy)N[]rr=r>)rCrD)r0r>r=rIs rrDzAnnotatedItem.__init__s' d%AeWA,HRHr)r>r)rJrK)r1r2r3r4rDrLrMs@rrOrOsIIrrOcBeZdZdZddZeddZedZd dZ y) EditablePartialz Acts like a functools.partial, but can be edited. In other words, it represents a type that hasn't yet been constructed. c.||_||_||_yr/funcargskwargs)r0rXrYrZs rrDzEditablePartial.__init__s   rc0t|t||S)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)`` rW)rUlist)clsrXrYrZs r from_callzEditablePartial.from_callsDtDz&IIrc |jdS)Nr*)rZr0s rr*zEditablePartial.names{{6""rc8|jj}|jj}tj|j }|j |jvr||j|j z }|j |i|S)z< Evaluate the partial and return the result )rYcopyrZinspectgetfullargspecrXvarargspop)r0rYrZarg_specs r__call__zEditablePartial.__call__s}yy~~!!#))$))4   t{{ * FJJx//0 0Dtyy$)&))rN)rXCallable[..., T]rYr\rZdictrJrK)rXrirJEditablePartial[T])rJr8) r1r2r3r4rD classmethodr^r6r*rhr7rrrUrUs; JJ## *rrUc g}|D]}|jt} |jd}|jj|j||j}|jdk(r|dz }|j|d|j|jdtjd||d|S#t $r(|jj |jYwxYw) z Given a list of :class:`NamedDiagram`, produce a single HTML string that visualises those diagrams. :params kwargs: kwargs to be passed in to the template css)rnrz (root)r)titletextsvgr)diagramsembedr7)r-r getwriteStandalonewriteAttributeErrorwriteSvgr*r,appendgetvaluertemplaterender)rrrsrZdatar-iornros rrailroad_to_htmlrs D  ?? "  Z /**U#C OO + +BHH# + >  ==A  Y E 2;;=gN^N^   $ ?? @D @ @@ / OO $ $RXX . /s8C.C10C1c~t|tr;t|j|_t|j|_|St|t r|Dcgc] }t|c}St|t r-|jDcic]\}}|t|c}}S|Scc}wcc}}w)zS Recursively resolves a collection of Partials into whatever type they are ) isinstancerUresolve_partialrYrZr\rjrF)partialxkeys rrrs'?+&w||4 (8y GT ",34q"44 GT "6=mmoFFC_Q''FF 5Fs B4B9c t|xsi}t||d||||t|}||vr-|js d||_||j ||dt |jj}t|dkDrt} g} |D]Z} | jdk(r| j | j| vs/| j| j| j| \| D cgc] } t| } } n|D cgc] } t| } } t| d Scc} wcc} w) aG 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 :meth:`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 :param show_hidden: bool to indicate whether internal elements that are typically hidden should be shown )diagram_kwargsN)lookupparentverticalshow_results_names show_groups show_hiddenrT)forcer z...c|jSr/r,)diags rzto_railroad..(s TZZr)r)ConverterState_to_diagram_elementid customNamer*mark_for_extractionr\rrvaluesrAsetaddryrsorted)elementrrrrrrroot_iddiagsseen deduped_diagsdrresolveds r to_railroadrsA:>+?R @F-kG&!!#%F7O w++GV4+H '') *E 5zA~u  (Avvvv!affD&8 $$Q'  (=JJOG,JJ=BBOG,BB ( 7 88 KCs ?D:D?c6|ytt||k\S)zF Returns true if we should return a vertical list of elements F)rA_visible_exprs) specificationexprss r_should_verticalr+s" >%()]::rceZdZUdZded<ded<ded<ded<d Zd ed <d Zd ed <dZded<dZded< d ddZ y ) ElementStatez< State recorded for an individual pyparsing Element pyparsing.ParserElementrrU convertedrr+numberNr)r*ztyping.Optional[int] parent_indexFboolextractcompletecd|_|jsC|r||_n9|jjr|jj|_nd|_|s!|jr(t |jr|j |yyy)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 TrN)rr*rrr_worth_extractingextract_into_diagram)r0el_idstater*rs rrz ElementState.mark_for_extractionNsp yy  (( LL33  T]]'8'F  & &u -(G]r)NF)rr+rrr*r)rr) r1r2r3r4r5r*rrrrr7rrrr7su %$  KD#)-L&-GTHdRW..!/.7:.JN.rrcZeZdZdZd d dZddZddZddZddZd dZ dd Z dd Z dd Z y)rzR Stores some state that persists between recursions into the element tree Ncpi|_i|_d|_d|_|xsi|_t |_y)Nr r)_element_diagram_statesrr unnamed_indexr,rrextracted_diagram_names)r0rs rrDzConverterState.__init__qs7@B$BD "# $2$8b14$rc"||j|<yr/r)r0rvalues r __setitem__zConverterState.__setitem__~s,1$$S)rc |j|Sr/rr0rs r __getitem__zConverterState.__getitem__s++C00rc|j|=yr/rrs r __delitem__zConverterState.__delitem__s  ( ( -rc||jvSr/rrs r __contains__zConverterState.__contains__sd2222rc0 ||S#t$r|cYSwxYwr/)KeyError)r0rdefaults rrtzConverterState.gets% 9  N s  cD|xjdz c_|jS)zT Generate a number used in the name of an otherwise unnamed diagram r )rr`s rgenerate_unnamedzConverterState.generate_unnameds! a!!!rcD|xjdz c_|jS)z; Generate a number used to index a diagram r rr`s rgenerate_indexzConverterState.generate_indexs a zzrc  ||}|jrdt|j}tj t j |j|}d|jjvr||jjd<n>d|jjvr&||jjd|j<|jjt jk(r|jjd}n |j}tj t|jtjt j|fi|j|j|j |<||=y)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 #rphrefr=rF)r*r-r,N)rrr*rUr^r? NonTerminalrZrrrXGroupr(Diagramrrrr)r0rpositionrretcontents rrz#ConverterState.extract_into_diagramsA ; ??~hmm456D!++H,@,@x}}[_+`C///14&&v.HOO222IL&&w/0E0EF    " "hnn 4((//7G((G.88 #--  '-1-@-@// 9  e Krr/)rtyping.Optional[dict]rJrK)rr+rr)rr+rJr)rr+)rJr+)rr+) r1r2r3r4rDrrrrrtrrrr7rrrrls4 721.3 " rrcF|j}td|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 c3<K|]}|jywr/)recurse).0childs r z$_worth_extracting..s55u}}5s)rany)rchildrens rrrs!  H 5H5 55rcJ d dfd }|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) c  ||||||||| } |rS| Q|j} | rC|jrdnd} tjtj | t | | } | S)Nr*rS) resultsName modalResultsrUr^r?rrepr) rrrrr, name_hintrrrrelement_results_name modal_tagfns r_innerz0_apply_diagram_item_enhancements.._inners            #/#*#6#6 #")"6"6BC %//NN!"678 D0  rNNrNFFFrrr typing.Optional[EditablePartial]rrrr+r,r+rr)rrrrrrrJrr7)rrs` r _apply_diagram_item_enhancementsrs"&#(!!#(#0## #  #  #!### *#J Mrctjtjtjjf}|Dcgc]}t ||s|c}Scc}wr/)r ParseElementEnhance PositionTokenAnd _ErrorStopr)rnon_diagramming_exprses rrrsV%%     !23   sAc t|j} |xs#|jxst|j} t |} |j } |js^t |tjtjfr4| r2| djs| } nd} t|j||||| ||| St|r|j| }|rj|j^|j| ||dt!|j}t"j%t&j(|j|}|S| |j*vrP|j*| j,d}t"j%t&j(|dt!|}|S|j.s|syt |tj0r| syt3t5d| Dd k(rHt3| d kDr:t"j%t&j6d t9t3|  }nt;|| r't"j%t&j<g }nVt"j%t&j>g }n/t |tj@tjBfr^| syt;|| r(t"j%t&jDdg }nt"j%t&jFg }nt |tjHr | syt"j%tJg }nmt |tjLrt"j%tNdd }n5t |tjPrt"j%tNdd }nt |tjRrt"j%tNdd }nt |tjTrH|rt"j%tNd d }nt"j%t&jTd| }nct |tjVrmt|jjY}|dk(r't"j%t&j>g }nt"j%tN|d }nt |tjZr't"j%t&j\d }nt |tj6r|j^T||||||||g}t|j^j|jzdja|jg|St"j%t&j6d}nt |tjbr|j^T||||||||g}t|j^j|jzdja|jg|St"j%t&jbd }nYt |tjdr|jsd}n/t |tjfr&t"j%t&j>g }nt3| dkDr)| s't"j%t&jTd | }nt |tjhr:tk|jl}t"j%t&jn|}ndt3| dkDr&t"j%t&j>g }n0t"j%t&jn|jp}|}|yts|||||ju|| <|jr || j| ||jd}| D]}d|j,vr|j,djw|dt||||||||}|Ed|j,vr||j,d<cd|j,vsr||j,d|<|d z }d|j,vs|j,d|=|rjd|j,vrt3|j,ddk(sd|j,vr3|j,d$t"j%t&jn| }| |vr d|| _<| |vr|| jzrr|| jxrc|j}| |P|j*| j,d}dt!|}t"j%t&j(||}|S)a 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 :param show_groups: bool flag indicating whether to show groups using bounding box :param show_hidden: bool flag indicating whether to show elements that are typically hidden :returns: The converted version of the input element, but as a Partial that hasn't yet been constructed rN)rrrr,rrrr)r*rrr*c3LK|]}|j|jfywr/)r*r)rrs rrz&_to_diagram_element..gs:qAFFAMM*:s"$r r)r=repeat)rFNOT)r>r= LOOKAHEAD LOOKBEHINDrStokenconverterr<)r ..)rrrrrrF)rrrr,rrrr=T)?rrtyper1rrrr ForwardLocatedrexprrrtr*rrrUr^r?rrrrZshow_in_diagramrrArrBr)rStackSequenceOr MatchFirstr@HorizontalChoiceEachr:NotAnyrO FollowedBy PrecededByrTokenConverterrOptOptional not_enderset_name ZeroOrMoreEmptyrr!r&patternTerminal defaultNamerrinsertrrr)rrrrr,rrrrrr*rrpropagated_name looked_uprrrpr>rYcollapsed_pattterminalirr=s rrrsN4 OO E  D** Dd7m.D.DD wKE"..     !!!!  Qx**&*O&*O*LL!!%-'9 + +  !JJu% 3  ) )%i ) H~inn567D!++H,@,@y~~\`+aCJ foo %??5)008D!++$$4.:N9O6P,CJ  " ";'9==) s:E:: ;q @SZRS^!++""CE O,Ch .!++HNN"+EC!++H,=,=R+HC GillI,@,@A B He ,!++HOOQb+IC!++H,E,ER+PC GY^^ ,'''; GY-- .'' U'L GY11 2'' [r'R GY11 2'' \PR'S GY__ - !++M"+MC!++T1E,C GY55 6W &&,,. $ $!++H,=,=R+HC!++MR+PC GY]] +''(9(9'C GY00 1    (" D'##(((7<<7@II',,W ''(:(:'F GY11 2    (" D'##(((7<<7=FFw||T ''(;(;"'E GY__ -g6H6H GY:: ;''(9(9'D Ua 4''Rt'L GY__ -0A''(9(9>J Ua''(9(9'D",,X->->@S@ST {!$$& F5Mu ))%9K9KL A' cjj JJw  & &q$ /" 1##    #%) 6"CJJ&)- 7#A&Q  " 7#A&5': CJJ 3szz'':#;q#@ cjj SZZ%7%?''(9(94@ !%u  6%=00VE]5K5K##E* ???5)008D~d+,-D!++$$4d,C Jr)rr)rJr))r$r)rJr))F)rrlist[NamedDiagram]rJr))rrkrJr8)NFFF)rrrrrr+rrrrrrrJr)rr+r!Iterable[pyparsing.ParserElement]rJr)rrrJr)rrrr)) __future__r itertoolsr?r dataclassestypingrrrrjinja2rr~r rcrjinja2_template_sourcer{rcountrrr& dataclassr(r8rr:rOrUrrrrrrrrrrr7rrr(s#"   "H * + a( ,     CLAx~~A,IHNNI(*gaj(*VA: $-1$ A9 $A9)A9A9 A9  A9  A9A9H ; ;@ ;  ; 1.1.1.hRRj6,^ ""$y $y ,y y y  y  yyyy&y"yr