qBFj!ddlmZddlZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z mZmZddlmZgdZdejvZedd ZGd d e eZGd de dZGdde eefZeZd0dZd1dZd1dZd1dZd1dZd1dZ d1dZ!d2dZ"edZ#d3d$Z$d4d'Z%d5d)Z&ee ge'fe'fZ(d6d,Z)d7d8d/Z*dS)9) 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) covariantcNeZdZdZ ddd Zdd Zdd Zdd ZddZddZ ddZ dS)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() Nsenderrhandler Callable[[_Sender], None] | NonereturnNonec4||_g|_|||z }dSdSN)r _handlers)selfrr s BC:\PYTHON\_runtimes\venv\Lib\site-packages\prompt_toolkit/utils.py__init__zEvent.__init__Bs- :<   GODDD  c:|jD]}||jdS)z Fire event.N)r&rr'r s r(__call__zEvent.__call__Ks2~ ! !G GDK  ! !r*c|dS)z!Alias for just calling the event.Nr's r(firez Event.firePs r*Callable[[_Sender], None]c:|j|dS)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*cP||jvr|j|dSdS)z6 Remove a handler from this callback. N)r&remover,s r(remove_handlerzEvent.remove_handler]s5 dn $ $ N ! !' * * * * * % $r*Event[_Sender]c0|||S)zC `event += handler` notation for adding a handler. )r5r,s r(__iadd__zEvent.__iadd__ds !!! r*c0|||S)zE `event -= handler` notation for removing a handler. )r8r,s r(__isub__zEvent.__isub__ks G$$$ r*r%)rrr r!r"r#r"r#)r r2r"r#)r r2r"r9) __name__ __module__ __qualname____doc__r)r-r1r5r8r;r=r/r*r(r r -s*LP!!!! ''''++++r*r c"eZdZdZd dZd dZdS) rz5 (contextlib.nested is not available on Py3) r"r#cdSr%r/r0s r( __enter__zDummyContext.__enter__x r*aobjectcdSr%r/)r'rGs r(__exit__zDummyContext.__exit__{rFr*Nr>)rGrHr"r#)r?r@rArBrErJr/r*r(rrssF          r*rc4eZdZdZdZdZd fd Zd d ZxZS) _CharSizesCachez" Cache for wcwidth sizes. @r"r#cntt|_dSr%)superr)r _long_strings)r' __class__s r(r)z_CharSizesCache.__init__s+ ).r*stringstrintcxt|dkrtdt|}ntfd|D}||<t|jkrOj}||t|jkr|}|vr|=|S)Nrc3(K|] }|V dSr%r/).0cr's r( z._CharSizesCache.__missing__..s'11Qa111111r*) lenmaxr sumLONG_STRING_MIN_LENrQr4MAX_LONG_STRINGSpopleft)r'rSresult long_strings key_to_removes` r( __missing__z_CharSizesCache.__missing__s v;;!  GFOO,,FF1111&11111FV  v;;1 1 1-L    ' ' '<  4#888 , 4 4 6 6  D((]+ r*r>rSrTr"rU) r?r@rArBr_r`r)re __classcell__)rRs@r(rLrLsi111111 r*rLrSrTr"rUct|S)z? Return width of a string. Wrapper around ``wcwidth``. )_CHAR_SIZES_CACHE)rSs r(rrs V $$r*boolc,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"tjdkS)z) True when we are using Windows. win32)sysplatformr/r*r(rrs <7 ""r*cFtjdkrddlm}|SdS)zS True when we are using Windows, but VT100 escape sequences are supported. rpris_win_vt100_enabledF)rqrrprompt_toolkit.output.windows10rurts r(is_windows_vt100_supportedrws7 |wHHHHHH##%%% 5r*cjtjdko#tjdddkS)z7 True when the ConEmu Windows console is used. rp ConEmuANSIOFFON)rqrrosenvirongetr/r*r(rrs+ <7 " Rrz~~lE'J'Jd'RRr*cDtjjjdkS)z: True when the current thread is the main thread. _MainThread) threadingcurrent_threadrRr?r/r*r(rrs  # % % / 8M IIr*cntjdd}|dvS)zD True if env variable is set to true (true, TRUE, True, 1). PROMPT_TOOLKIT_BELLtrue)1r)r|r}r~lowervalues r(rrs- JNN0& 9 9E ;;==M ))r*cBtjddS)z&Return the $TERM environment variable.TERM)r|r}r~r/r*r(rrs :>>&" % %%r*_Titemslist[_T]weights list[int]Generator[_T, None, None]c#\Kt|t|ksJt|dksJg}g}t||D]5\}}|dkr*||||6|}|}|stdd|D}t|}t |}d} d} | r^d} tt |||D];\} }} || | | zt |z kr|V|| xxdz cc<d} <| ^| dz } h)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.cg|]}dS)rr/)rYis r( z&take_using_weights..s&&&1Q&&&r*TFrW)r\zipr4 ValueErrorr]rangefloat) rritems2weights2itemw already_taken item_count max_weightraddingitem_iweights r(rrs u::W % % % % u::>>>>FHug&&a q55 MM$    OOA    EG HFGGG'&&&&MUJWJ A  "F(+E*,=,=ug(N(N " "$f (1v:j8I8I+IIIJJJ!&)))Q.)))!F " Q r*rCallable[[], str] | strclt|rt|St|S)z$Turn callable or string into string.)callablerrTrs r(rr".eegg5zzr*Callable[[], int] | intclt|rt|St|S)zTurn callable or int into int.)rrrUrs r(rr*rr*rrclt|rt|St|S)z"Turn callable or float into float.)rrrrs r(rr5s0   U||r*term str | Nonec|-ttjddS|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. Nrr)dumbunknown)rr|r}r~r)rs r(rr=s; | vr : :;;; ::<<. ..r*rf)r"rj)r"rT)rrrrr"r)rrr"rT)rrr"rU)rrr"rr%)rrr"rj)+ __future__rr|rnrqr collectionsrtypingrrrrr r r r __all__modulesSPHINX_AUTODOC_RUNNINGrr rrTrUrLrirrrrwrrrrrrrrrrrrr/r*r(rs""""""    (.< ')t , , ,CCCCCGG CCCL      >$'    &&&&&d38n&&&R$O%%%%%%&&&&####    SSSSJJJJ****&&&&  WT]]3333l "e)$e+ , / / / / / / /r*