Current Path : /usr/lib/python2.7/dist-packages/landscape/ |
Current File : //usr/lib/python2.7/dist-packages/landscape/reactor.pyc |
Tc @ s* d Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d S( sB Extend the regular Twisted reactor with event-handling features. iN( t Failure( t ConnectError( t deferToThread( t format_objectt InvalidIDc B s e Z d Z RS( s= Raised when an invalid ID is used with reactor.cancel_call().( t __name__t __module__t __doc__( ( ( s5 /usr/lib/python2.7/dist-packages/landscape/reactor.pyR s t CallHookErrorc B s e Z d Z RS( s- Raised when hooking on a reactor incorrectly.( R R R ( ( ( s5 /usr/lib/python2.7/dist-packages/landscape/reactor.pyR s t EventIDc B s e Z d Z d Z RS( s Unique identifier for an event handler. @param event_type: Name of the event type handled by the handler. @param pair: Binary tuple C{(handler, priority)} holding the handler function and its priority. c C s | | _ | | _ d S( N( t _event_typet _pair( t selft event_typet pair( ( s5 /usr/lib/python2.7/dist-packages/landscape/reactor.pyt __init__ s ( R R R R ( ( ( s5 /usr/lib/python2.7/dist-packages/landscape/reactor.pyR s t EventHandlingReactorMixinc B s5 e Z d Z d Z d d Z d Z d Z RS( s Fire events identified by strings and register handlers for them. Note that event handlers are executed synchronously when the C{fire} method is called, so unit-tests can generally exercise events without needing to run the real Twisted reactor (except of course if the event handlers themselves contain asynchronous calls that need the Twisted reactor running). c C s t t | j i | _ d S( N( t superR R t _event_handlers( R ( ( s5 /usr/lib/python2.7/dist-packages/landscape/reactor.pyR / s i c C sN | | f } | j j | g } | j | | j d d t | | S( s Register an event handler. The handler will be invoked every time an event of the given type is fired (there's no need to re-register the handler after the event is fired). @param event_type: The name of the event type to handle. @param handler: The function handling the given event type. @param priority: The priority of the given handler function. @return: The L{EventID} of the registered handler. t keyc S s | d S( Ni ( ( R ( ( s5 /usr/lib/python2.7/dist-packages/landscape/reactor.pyt <lambda>D s ( R t setdefaultt appendt sortR ( R R t handlert priorityR t handlers( ( s5 /usr/lib/python2.7/dist-packages/landscape/reactor.pyt call_on3 s c O s t j d | g } t | j j | d } x | D] \ } } y6 t j d t | | | | j | | | Wq8 t k r t j d t | | | | | j q8 t j d t | | | | q8 Xq8 Wt j d | | S( sc Fire an event of a given type. Call all handlers registered for the given C{event_type}, in order of priority. @param event_type: The name of the event type to fire. @param args: Positional arguments to pass to the registered handlers. @param kwargs: Keyword arguments to pass to the registered handlers. s Started firing %s.s# Calling %s for %s with priority %d.sT Keyboard interrupt while running event handler %s for event type %r with args %r %r.sA Error running event handler %s for event type %r with args %r %r.s Finished firing %s.( ( t loggingt debugt listR t getR R t KeyboardInterruptt exceptiont stop( R R t argst kwargst resultsR R R ( ( s5 /usr/lib/python2.7/dist-packages/landscape/reactor.pyt fireH s( c C sC t | t k r/ | j | j j | j n t d | d S( sf Unregister an event handler. @param id: the L{EventID} of the handler to unregister. s&