)L i!ddlmZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z mZmZddlmZgdZdej$vZedd ZGd d e eZGd de dZGdde eefZeZddZd dZd dZd dZd dZd dZ d dZ!d!dZ"edZ# d"dZ$d#dZ%d$dZ&ee ge'fe'fZ(d%dZ)d&d'dZ*y)() annotationsN)deque)CallableContextManagerDict GeneratorGenericTypeVarUnion)wcwidth)Event DummyContext get_cwidthsuspend_to_background_supportedis_conemu_ansi is_windowsin_main_threadget_bell_environment_variableget_term_environment_variabletake_using_weightsto_strto_intAnyFloatto_floatis_dumb_terminalzsphinx.ext.autodoc_SenderT) covariantcVeZdZdZ d d dZd dZd dZd dZd dZddZ dd Z y)r a Simple event to which event handlers can be attached. For instance:: class Cls: def __init__(self): # Define event. The first parameter is the sender. self.event = Event(self) obj = Cls() def handler(sender): pass # Add event handler by using the += operator. obj.event += handler # Fire event. obj.event() Nc0||_g|_|||z }yyN)sender _handlers)selfr!handlers Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/utils.py__init__zEvent.__init__Bs& :<   GOD cJ|jD]}||jy)z Fire event.N)r"r!r#r$s r%__call__zEvent.__call__Ks!~~ !G DKK  !r'c|y)z!Alias for just calling the event.Nr#s r%firez Event.firePs r'c:|jj|y)z Add another handler to this callback. (Handler should be a callable that takes exactly one parameter: the sender object.) N)r"appendr)s r% add_handlerzEvent.add_handlerTs g&r'cX||jvr|jj|yy)z6 Remove a handler from this callback. N)r"remover)s r%remove_handlerzEvent.remove_handler]s' dnn $ NN ! !' * %r'c(|j||S)zC `event += handler` notation for adding a handler. )r1r)s r%__iadd__zEvent.__iadd__ds ! r'c(|j||S)zE `event -= handler` notation for removing a handler. )r4r)s r%__isub__zEvent.__isub__ks G$ r'r )r!rr$z Callable[[_Sender], None] | NonereturnNoner9r:)r$Callable[[_Sender], None]r9r:)r$r<r9zEvent[_Sender]) __name__ __module__ __qualname____doc__r&r*r.r1r4r6r8r,r'r%r r -sI*LP(H ! '+r'r c eZdZdZddZddZy)rz5 (contextlib.nested is not available on Py3) cyr r,r-s r% __enter__zDummyContext.__enter__x r'cyr r,)r#as r%__exit__zDummyContext.__exit__{rDr'Nr;)rFobjectr9r:)r=r>r?r@rCrGr,r'r%rrss  r'rc4eZdZdZdZdZdfd ZddZxZS)_CharSizesCachez" Cache for wcwidth sizes. @c@t|t|_yr )superr&r _long_strings)r# __class__s r%r&z_CharSizesCache.__init__s ).r'cJt|dk(rtdt|}ntfd|D}||<t|jkDrLj }|j |t|jkDr|j}|vr|=|S)Nrc3(K|] }| ywr r,).0cr#s r% z._CharSizesCache.__missing__..s1Qa1s) lenmaxr sumLONG_STRING_MIN_LENrOr0MAX_LONG_STRINGSpopleft)r#stringresult long_strings key_to_removes` r% __missing__z_CharSizesCache.__missing__s v;! GFO,F1&11FV  v;11 1--L    '< 4#8#88 , 4 4 6  D(]+ r'r;r]strr9int) r=r>r?r@rZr[r&ra __classcell__)rPs@r%rJrJs 1 r'rJct|S)z? Return width of a string. Wrapper around ``wcwidth``. )_CHAR_SIZES_CACHE)r]s r%rrs V $$r'c"ttdS)z Returns `True` when the Python implementation supports suspend-to-background. This is typically `False' on Windows systems. SIGTSTP)hasattrsignalr,r'r%rrs 69 %%r'c(tjdk(S)z) True when we are using Windows. win32)sysplatformr,r'r%rrs <<7 ""r'cDtjdk(r ddlm}|Sy)zS True when we are using Windows, but VT100 escape sequences are supported. rmris_win_vt100_enabledF)rnroprompt_toolkit.output.windows10rrrqs r%is_windows_vt100_supportedrts ||wH#%% r'crtjdk(xr#tjj dddk(S)z7 True when the ConEmu Windows console is used. rm ConEmuANSIOFFON)rnroosenvirongetr,r'r%rrs, <<7 " Rrzz~~lE'Jd'RRr'cXtjjjdk(S)z: True when the current thread is the main thread. _MainThread) threadingcurrent_threadrPr=r,r'r%rrs$  # # % / / 8 8M IIr'cftjjdd}|jdvS)zD True if env variable is set to true (true, TRUE, True, 1). PROMPT_TOOLKIT_BELLtrue)1r)ryrzr{lowervalues r%rrs* JJNN0& 9E ;;=M ))r'cBtjjddS)z&Return the $TERM environment variable.TERM)ryrzr{r,r'r%rrs ::>>&" %%r'_Tc# Kt|t|k(sJt|dkDsJg}g}t||D]-\}}|dkDs |j||j|/|}|}|s td|Dcgc]}d}}t|}t |} d} d} | rOd} tt |||D]1\} }} || || zt | z ks||| xxdz cc<d} 3| rO|dz }Ycc}ww)a Generator that keeps yielding items from the items list, in proportion to their weight. For instance:: # Getting the first 70 items from this generator should have yielded 10 # times A, 20 times B and 40 times C, all distributed equally.. take_using_weights(['A', 'B', 'C'], [5, 10, 20]) :param items: List of items to take from. :param weights: Integers representing the weight. (Numbers have to be integers, not floats.) rz+Did't got any items with a positive weight.TFrR)rWzipr0 ValueErrorrXrangefloat) itemsweightsitems2weights2itemwi already_taken item_count max_weightaddingitem_iweights r%rrs? u:W %% % u:>>FHug&a q5 MM$  OOA  EG FGG!&&1Q&M&UJWJ A F(+E*,=ug(N "$f (1v:j8I+IIJ!&)Q.)!F  " Q  's%AD9D C> AD D8 DcNt|rt|St|S)z$Turn callable or string into string.)callablerrcrs r%rr"eg5zr'cNt|rt|St|S)zTurn callable or int into int.)rrrdrs r%rr*rr'cNt|rt|St|S)z"Turn callable or float into float.)rrrrs r%rr5s   U|r'c||)ttjjddS|j dvS)z True if this terminal type is considered "dumb". If so, we should fall back to the simplest possible form of line editing, without cursor positioning and color support. rr)dumbunknown)rryrzr{r)terms r%rr=s5 | vr :;; ::<. ..r'rb)r9bool)r9rc)rzlist[_T]rz list[int]r9zGenerator[_T, None, None])rzCallable[[], str] | strr9rc)rzCallable[[], int] | intr9rd)rrr9rr )rz str | Noner9r)+ __future__rryrkrnr~ collectionsrtypingrrrrr r r r __all__modulesSPHINX_AUTODOC_RUNNINGrr rrcrdrJrgrrrrtrrrrrrrrrrrrr,r'r%rs"  (.< )t ,CGG CL  >$'  &d38n&R$%%&# SJ*&  T]3 3'33l "e)$e+ , /r'