ó U!¶\c@sddlZddlZddlmZmZmZddlmZmZddl m Z ej e ƒZ eddddgƒZd Zd Zd Zdefd „ƒYZdd „Zdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdS(iÿÿÿÿN(t defaultdicttdequet namedtuple(taccepts_kwargstsix(t EVENT_ALIASEStNodeListtfirsttmiddletlastiiicBseZd„ZRS(cCsLtj|jƒ}tj|jƒ}tj|jƒ}t|||ƒ}|S(N(tcopyRRR R(tselft first_copyt middle_copyt last_copytcopied((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyt__copy__s (t__name__t __module__R(((s2/tmp/pip-install-usGedi/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-usGedi/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-usGedi/botocore/botocore/hooks.pytemitCscCs&|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-usGedi/botocore/botocore/hooks.pytregisterTs 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 RR R!R((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pytregister_firstgs  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 RR R!R((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyt register_lastts cCs1|j|ƒ|j|ƒ|||||ƒdS(N(t_verify_is_callablet_verify_accept_kwargs(R RR R!RR((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyR€s  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 RR R!R((s2/tmp/pip-install-usGedi/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-usGedi/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-usGedi/botocore/botocore/hooks.pyR(•s   N( RRRRR.R"R$R&RR)R'R((((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyRBs     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-usGedi/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-usGedi/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``). R:iÿÿÿÿN(NN(R<tTrueR(R RRR((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pytemit_until_responseæs cCs |j||||dtƒdS(Ntsection(t_register_sectiont_MIDDLE(R RR R!R((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyRùscCs |j||||dtƒdS(NR?(R@t_FIRST(R RR R!R((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyR#þscCs |j||||dtƒdS(NR?(R@t_LAST(R RR R!R((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyR%scCsù|dk rÓ||jkrŠ|j|jddƒ}|rm|sStd|ƒ‚q†|j|dcd7RRR#R%R@R)R(((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyR/¦s (     ( !t EventAliasercBs€eZd d„Zd„Zd„Zd ed„Zd ed„Zd ed„Z d d ed„Z d„Z d„Z d „Z RS( cCs.||_|dkr!t|_n||_dS(N(t_event_aliasesRRt_emitter(R t event_emittert event_aliases((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyR4\s   cKs"|j|ƒ}|jj||S(N(t_alias_event_nameRPR(R RRtaliased_event_name((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyRbscKs"|j|ƒ}|jj||S(N(RSRPR>(R RRRT((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyR>fscCs(|j|ƒ}|jj||||ƒS(N(RSRPR"(R RR R!RRT((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyR"js cCs(|j|ƒ}|jj||||ƒS(N(RSRPR$(R RR R!RRT((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyR$qs cCs(|j|ƒ}|jj||||ƒS(N(RSRPR&(R RR R!RRT((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyR&xs cCs(|j|ƒ}|jj||||ƒS(N(RSRPR)(R RR R!RRT((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyR)s cCsËxÄ|jjƒD]³\}}|jdƒ}d|krhy|||j|ƒR.R"R$R&R)RSRYR(((s2/tmp/pip-install-usGedi/botocore/botocore/hooks.pyRN[s        R1cBsYeZdZd„Zed„Zd„Zd„Zd„Zd„Z d„Z d„Z RS( sjSpecialized prefix trie that handles wildcards. The prefixes in this case are based on dot separated names so 'foo.bar.baz' is:: foo -> 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-usGedi/botocore/botocore/hooks.pyR4ÊscCs»|jdƒ}|j}x^|D]V}||dkrgi|d6dd6id6}||d|<|}q|d|}qW|ddkr¢tgggƒ|d s   dµY