ó –ee[c@sëddlZddlZddlmZmZmZddlmZmZej e ƒZ eddddgƒZ dZ d Zd Zde fd „ƒYZdd „Zd efd„ƒYZdefd„ƒYZdefd„ƒYZdS(iÿÿÿÿN(t defaultdicttdequet namedtuple(taccepts_kwargstsixtNodeListtfirsttmiddletlastiiicBseZd„ZRS(cCsLtj|jƒ}tj|jƒ}tj|jƒ}t|||ƒ}|S(N(tcopyRRRR(tselft first_copyt middle_copyt last_copytcopied((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyt__copy__s (t__name__t __module__R(((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyRscCs-x&|D]}|ddk r|dSqW|S(sFind first non None response in a list of tuples. This function can be used to find the first non None response from handlers connected to an event. This is useful if you are interested in the returned responses from event handlers. Example usage:: print(first_non_none_response([(func1, None), (func2, 'foo'), (func3, 'bar')])) # This will print 'foo' :type responses: list of tuples :param responses: The responses from the ``EventHooks.emit`` method. This is a list of tuples, and each tuple is (handler, handler_response). :param default: If no non-None responses are found, then this default value will be returned. :return: The first non-None response in the list of tuples. iN(tNone(t responsestdefaulttresponse((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pytfirst_non_none_response%s  tBaseEventHookscBskeZd„Zded„Zded„Zded„Zd„Zdded„Z d„Z d„Z RS( cKsgS(säCall all handlers subscribed to an event. :type event_name: str :param event_name: The name of the event to emit. :type **kwargs: dict :param **kwargs: Arbitrary kwargs to pass through to the subscribed handlers. The ``event_name`` will be injected into the kwargs so it's not necesary to add this to **kwargs. :rtype: list of tuples :return: A list of ``(handler_func, handler_func_return_value)`` ((R t event_nametkwargs((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pytemitBscCs&|j|||d|jd|ƒdS(s@Register an event handler for a given event. If a ``unique_id`` is given, the handler will not be registered if a handler with the ``unique_id`` has already been registered. Handlers are called in the order they have been registered. Note handlers can also be registered with ``register_first()`` and ``register_last()``. All handlers registered with ``register_first()`` are called before handlers registered with ``register()`` which are called before handlers registered with ``register_last()``. tregister_methodtunique_id_uses_countN(t_verify_and_registert _register(R Rthandlert unique_idR((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pytregisterSs cCs&|j|||d|jd|ƒdS(sìRegister an event handler to be called first for an event. All event handlers registered with ``register_first()`` will be called before handlers registered with ``register()`` and ``register_last()``. RRN(Rt_register_first(R RRR R((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pytregister_firstfs  cCs&|j|||d|jd|ƒdS(sâRegister an event handler to be called last for an event. All event handlers registered with ``register_last()`` will be called after handlers registered with ``register_first()`` and ``register()``. RRN(Rt_register_last(R RRR R((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyt register_lastss cCs1|j|ƒ|j|ƒ|||||ƒdS(N(t_verify_is_callablet_verify_accept_kwargs(R RRR RR((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyRs  cCsdS(s÷Unregister an event handler for a given event. If no ``unique_id`` was given during registration, then the first instance of the event handler is removed (if the event handler has been registered multiple times). N((R RRR R((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyt unregister…s cCs&tj|ƒs"td|ƒ‚ndS(Ns"Event handler %s must be callable.(Rtcallablet ValueError(R tfunc((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyR&scCs<y#t|ƒs"td|ƒ‚nWntk r7tSXdS(s¸Verifies a callable accepts kwargs :type func: callable :param func: A callable object. :returns: True, if ``func`` accepts kwargs, otherwise False. s9Event handler %s must accept keyword arguments (**kwargs)N(RR*t TypeErrortFalse(R R+((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyR'”s   N( RRRRR-R!R#R%RR(R&R'(((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyRAs     tHierarchicalEmittercBs}eZd„Zed„Zd„Zd„Zd ed„Zd ed„Z ed„Z d„Z d d ed„Z d „Z RS( cCs"i|_tƒ|_i|_dS(N(t _lookup_cachet _PrefixTriet _handlerst_unique_id_handlers(R ((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyt__init__¦s  cCs½g}|jj|ƒ}|dkrF|jj|ƒ}||j|>> responses = emitter.emit( ... 'my-event.service.operation', arg1='one', arg2='two') :rtype: list :return: List of (handler, response) tuples from all processed handlers. (R;(R RR((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyRØs cKs.|j||dtƒ}|r&|dSdSdS(s÷ Emit an event by name with arguments passed as keyword args, until the first non-``None`` response is received. This method prevents subsequent handlers from being invoked. >>> handler, response = emitter.emit_until_response( 'my-event.service.operation', arg1='one', arg2='two') :rtype: tuple :return: The first (handler, response) tuple where the response is not ``None``, otherwise (``None``, ``None``). R9iÿÿÿÿN(NN(R;tTrueR(R RRR((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pytemit_until_responseås cCs |j||||dtƒdS(Ntsection(t_register_sectiont_MIDDLE(R RRR R((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyRøscCs |j||||dtƒdS(NR>(R?t_FIRST(R RRR R((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyR"ýscCs |j||||dtƒdS(NR>(R?t_LAST(R RRR R((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyR$scCsù|dk rÓ||jkrŠ|j|jddƒ}|rm|sStd|ƒ‚q†|j|dcd7R(RR2R4R*R1t append_itemR/(R RRR RR>RCtunique_id_handler_item((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyR?s,     cCs|dk rØy|j|jddƒ}Wntk r=dSX|r¦|dkrctd|ƒ‚qÕ|dkrˆ|jj|ƒd}qÕ|j|dcd8 bar -> baz Wildcard support just means that having a key such as 'foo.bar.*.baz' will be matched with a call to ``get_items(key='foo.bar.ANYTHING.baz')``. You can think of this prefix trie as the equivalent as defaultdict(list), except that it can do prefix searches: foo.bar.baz -> A foo.bar -> B foo -> C Calling ``get_items('foo.bar.baz')`` will return [A + B + C], from most specific to least specific. cCs"idd6id6dd6|_dS(Ntchunktchildrentvalues(Rt_root(R ((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyR3pscCs»|jdƒ}|j}x^|D]V}||dkrgi|d6dd6id6}||d|<|}q|d|}qW|ddkr¢tgggƒ|dt key_partstcurrenttpartt new_child((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyRDxs   cCs;tƒ}|jdƒ}|j}|j|||dƒ|S(sÖCollect all items that are prefixes of key. Prefix in this case are delineated by '.' characters so 'foo.bar.baz' is a 3 chunk sequence of 3 "prefixes" ( "foo", "bar", and "baz"). RQi(RRRRPt _get_items(R RSt collectedRURV((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyR5‹s   cCs||fg}t|ƒ}xæ|r|jƒ\}}|drw|d} | j| j| j} |jt| ƒƒn||ks|d} | j||ƒ} | jdƒ} |d}| dk rÛ|j | |fƒn| dk r|j | |fƒqqqWdS(NRORNt*i( tlenRGRRRt extendlefttreversedR4RR8(R t starting_nodeRURZtstarting_indextstackt key_parts_lent current_nodetindext node_listtcomplete_orderRNtdirectstwildcardt next_index((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyRY™s$           cCs5|jdƒ}|j}|j|||ddƒdS(sÞRemove an item associated with a key. If the value is not associated with the key a ``ValueError`` will be raised. If the key does not exist in the trie, a ``ValueError`` will be raised. RQRdiN(RRRPt _remove_item(R RSRTRURV((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyRH¸s cCs3|dkrdS|t|ƒkr/|dj||ƒ}|dk r|j||||dƒ|t|ƒdkrè|d}||jkr¡|jj|ƒqè||jkrÃ|jj|ƒqè||jkrè|jj|ƒqèn|d r,|d r,|d||=q,q/tddj |ƒƒ‚ndS(NRNiROskey is not in trie: %sRQ( RR\R4RjRtremoveRRR*tjoin(R RcRURTRdt next_nodeRe((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyRjÄs$   cCs+|jƒ}|j|jƒ}||_|S(N(RIt_recursive_copyRJ(R tnew_copyt copied_attrs((s2/tmp/pip-install-xdEqop/botocore/botocore/hooks.pyRÝs  cCs{i}xn|jƒD]`\}}t|tƒrDtj|ƒ|| s   dµ