L i  ddlZddlZddlZddlmZmZmZddlmZmZddl m Z m Z m Z m Z mZmZmZmZddlmZedZedZdefd Zd e ed e efd Zd edej2d e eeffdZde ed e e eeffdZded efdZeeddZdeeefd efdZdeeefd e eeeffdZ deeefd e eeffdZ!de edeegefd eee effdZ"Gdde#Z$dZ%d"d Z&d!Z'y)#N) OrderedDictCounter defaultdict) FrameType TracebackType)IteratorListTupleIterableCallableUnionTypeVarMapping)ASTTextTR max_lengthct||kDr1|t|z dz}|t|z |z }|d||z|| dz}|S)N)len)seqrmiddlerightlefts V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/stack_data/utils.pytruncatersV 3x*c&k)a/CK'%/%4j6!CL0 Jitreturnc>ttj|SN)listrfromkeys)rs runique_in_orderr$s  $$R( ))ratoknodect|ttddr9t||j\}}t||j d\}}||fS|j |d\\}}\}}||dzfS)z Returns a pair of numbers representing a half open range (i.e. suitable as arguments to the `range()` builtin) of line numbers of the given AST nodes. match_caseF)padded) isinstancegetattrast line_rangepatternbodyget_text_positions)r%r&start_end_startend_s rr0r0s} $\267 t||4 t tyy}5 cz#66tE6J HS!cAg~rlstc#xKt|tj|fdD]\}|rWtdgt zfd}t D])|fd |fd|fd+ntj dtEd{y7w) Nc|dkDS)Nr))xcountss rz"highlight_unique../sQrkeyFc@ |}d|<|S#t$rYywxYw)NT) ValueError)fi highlighteds rhighlight_indexz)highlight_unique..highlight_index4s3 A"& A"  s  c&jSr!indexgroupitemsrr?z"highlight_unique..=s D0Arc.jdzSNr,rI)firstrLrMsrr?z"highlight_unique..?sEKKeai,Hrc8ddddjz S)Nr*rIrKsrr?z"highlight_unique..@sU4R4[->->t-D(DrT)r itertoolsgroupbyr"rsetrepeatzip)r9 is_commonrGr>rPrLrFrMs @@@@@rhighlight_uniquerX,s S\F%--c7NO+ 5 KE 'CJ.K E  F'(AB$#$HI DE  F $**40Kuk***++* +sB)B:0B81B:r=c|Sr!r))r=s ridentityrZGs Hr)mapperrAc#4Ktt||}tjt |t |dD]O\}}t |\}}|rt||Ed{(t |\} } |t|t| Qy70w)Nc|ddSrOr))ts rr?z#collapse_repeated..Os!A$q'rr@)r"maprRrSrVrX) r9 collapserr[rAkeyedis_highlightedrLoriginal_grouphighlighted_group keyed_groupr8s rcollapse_repeatedrfKs S# E!*!2!2 %e, -!" E-0K)) 6>2 2 2 "34NKD0${2CD D E 3sA#B%B&1B frame_or_tbctt|tjtjft|tjfSr!)assert_r-typesrrrgs ris_framerlYs4 J{U__e6I6I$J KL kEOO#5 66rc#lK|}|r,|t|r |j}n |j}|r+yywr!)rlf_backtb_next)rgcurrents r iter_stackrq^s25@G  G nnGooG s/44cdt|r||jfS|j|jfSr!)rlf_linenotb_frame tb_linenorks rframe_and_linenorvhs2 K0000##[%:%:::riterablekey_funccftt}|D]}|||j||S)a Create a dictionary from an iterable such that the keys are the result of evaluating a key function on elements of the iterable and the values are lists of elements all of which correspond to the key. >>> def si(d): return sorted(d.items()) >>> si(group_by_key_func("a bb ccc d ee fff".split(), len)) [(1, ['a', 'd']), (2, ['bb', 'ee']), (3, ['ccc', 'fff'])] >>> si(group_by_key_func([-1, 0, 1, 3, 6, 8, 9, 2], lambda x: x % 2)) [(0, [0, 6, 8, 2]), (1, [-1, 1, 3, 9])] )rr"append)rwrxresultrMs rgroup_by_key_funcr|os9 F,x~%%d+, Mrc eZdZdZdZdZeZy)cached_propertyz A property that is only computed once per instance and then replaces itself with an ordinary attribute. Deleting the attribute resets the property. Based on https://github.com/pydanny/cached-property/blob/master/cached_property.py c4|j|_||_yr!)__doc__func)selfrs r__init__zcached_property.__init__s||  rcv||S|j|x}|j|jj<|Sr!)r__dict____name__)robj_clsvalues rcached_property_wrapperz'cached_property.cached_property_wrappers6 ;K3799S>A TYY//0 rN)r __module__ __qualname__rrr__get__r)rrr~r~s&Grr~c ddl}ddlm}Gfddt|d}|d} |j |||}|j S#t $r|}Y|j SwxYw)Nr)get_lexer_by_namec"eZdZfdZxZS)'_pygmented_with_ranges..MyLexerc3Kdt||D]9\}}tfdDr |j}t |z ||f;yw)Nrc3DK|]\}}|cxkxr|kncywr!r)).0r4r7lengths r zE_pygmented_with_ranges..MyLexer.get_tokens..s"Fu,,,Fs )super get_tokensany ExecutingNoder)rtextttyperr __class__rangess @rrz2_pygmented_with_ranges..MyLexer.get_tokenssZF % 24 8 # uFvFF!//E#e*$Ul"  #sAA)rrrr __classcell__)rrs@rMyLexerrs  # #rrpython3F)stripnl)pygmentspygments.lexersrtype highlight Exception splitlines) formattercoderrrrlexerrFs ` r_pygmented_with_rangesrs{1#$(34# E "E((ui@   ! ! ##   ! ! ##sA A21A2cB|st|tr t|}|yr!)r-strAssertionError) conditionerrors rriris#  eS !"5)E  rcX t|S#dt|jzcYSxYw)Nz)rrr)rs rsome_strrs/@5z@(4;+?+???s )))(r/rRrj collectionsrrrrrtypingrr r r r r rr asttokensrrrintrr$ASTr0boolrXrZrfrlrqrvr|objectr~rrirr)rrrs  99*  CL CLc* *Q* W CGG c3h +$q'+huQW~&>+6  a 19h E7% = 897d7 &E)]":;&yZgOgIh@i&;% =(@"A;eIWZNF[; xQ7GGTUW[\]W^T^L_$&f&,$,@r