wL idZddlmZddlZddlZddlmZddlmZddlm Z ddl m Z m Z Gdd e Z dd Z d dd Zddd Zddd Zy)zToken-related utilities) annotationsN)StringIO) iskeyword) TokenInfo) Generator NamedTuplec@eZdZUded<ded<ded<ded<ded<y) TokeninttokenstrtextstartendlineN)__name__ __module__ __qualname____annotations__]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/IPython/utils/tokenutil.pyr r s J I J H Irr c#~K tj|Ed{y7#tj$rYywxYww)z'wrap generate_tkens to catch EOF errorsN)tokenizegenerate_tokens TokenError)readlines rrrs6++H555   s(=$"$=$:=:=c# Kgd}|t|tsJ||xsgz}g} tj|D]}|j ||y#tj $r} t fd|Dr^|r6|djd|djdf}|}|dj}ndx}}d}ttjd|||nYd yd wwxYww)N)zunterminated string literalzinvalid non-printable characterz!after line continuation characterc3@K|]}|jdvyw)rN)args).0errorexcs r z/generate_tokens_catch_errors..1sAu #Asr)r) isinstancelistrrappendranyrrrr ERRORTOKEN) rextra_errors_to_catchdefault_errors_to_catcherrors_to_catchtokensr rrrr#s @rgenerate_tokens_catch_errorsr1 s ! (J7Ld,SS S-1F1L"MO F--h7 E MM% K      AA Ar ((+VBZ^^A->>bz$$H//UCF F  G s/$C+/AC+C(+A3C#C+#C((C+cd}|jd}|D]2}|t|z}|jds|dz }||kDr||fS|}4d}||fS)aReturn the line in a cell at a given cursor position Used for calling line-based APIs that don't support multi-line input, yet. Parameters ---------- cell : str multiline block of text cursor_pos : integer the cursor position Returns ------- (line, offset): (string, integer) The line with the current cursor, and the character offset of the start of the line. rT r&r') splitlineslenendswith)cell cursor_posoffsetlinesr next_offsets rline_at_cursorr<?s{"F OOD !E s4y( }}T" 1 K  #  <  <rcg}g}d}d}ddi}d}d}tt|jD cgc] } t|  } } | syt dg| zt j | dgzD]\} \} } | j\}}| j\}}|dz|vrN| jjd}t||dzD]!\}}||vs ||dz t|z||<#d}||}||z|kDrng| jtjk(xrt!| j" x}r|rF| rD| jtj$k(r'| j"dk(r|dd| j"|d<n|j'| j"| ?| jtj$k(r"| j"d k(r|j)dd}|so|r|dnd}ne| jtj$k(rH| j"d k(r|r|j'|dn"| j"d k(r|r|j)d}|||z|kDs|||z|k}n|r|r|dS|r|S|r|dS|r|S|r|dSycc} w) avGet the token at a given cursor Used for introspection. Function calls are prioritized, so the token for the callable will be returned if the cursor is anywhere inside the call. Parameters ---------- cell : str A block of Python code cursor_pos : int The location of the cursor in the block where the token should be found Nr&rFr'T.r%=())rrrr zip itertoolspairwiserrrr4 enumerater5r rNAMErrOPr*pop)r7r8names call_namesclosing_call_namemost_recent_outer_nameoffsetsintersects_with_cursorcur_token_is_nametupr0prev_toktoknext_tok start_line start_colend_lineend_colr:linenorr9s rtoken_at_cursorrYasEJ$()-!fG".x~/F/FG"s "F" %( ++FdVO<&5!/3!$  IGG' ar`sN#(J9=%5>Dfr