ó h'dWc@s3dZddlmZmZmZmZdefd„ƒYZeƒZ defd„ƒYZ e j e ƒdefd„ƒYZ e j e ƒd efd „ƒYZ e j e ƒd efd „ƒYZe j eƒd efd„ƒYZe j eƒdefd„ƒYZe j eƒdefd„ƒYZdS(s AI Events Mechanism iÿÿÿÿ(t AIServerErrort ERROR_TYPEt LOGGING_LEVELtCLIENT_STATUS_TYPEt EventTypecBs/eZdZd„Zed„ƒZd„ZRS(söThe EventType is a base-class for all events in the AI server system. Each sub-class will add any data they wish to provide to this class, which should provide sufficient information that a handler is able to act upon the event. cCs ||_dS(scInitialises the EventType with the minimum set of information needed for any event. Parameters object_ref: object This should be a reference to the object that the event occurred upon. A value or None indicates Server object type Return Value None N(t _object_ref(tselft object_ref((s events.pyt__init__'scCs|jS(s?Read-only accessor to the object that this event occurred upon.(R(R((s events.pyR7scCsd|jjt|jƒfS(Ns%s: object_ref: %s(t __class__t__name__tstrR(R((s events.pyt__str__<s (R t __module__t__doc__RtpropertyRR (((s events.pyRs t CreatedEventcBseZdZd„ZRS(sKEvent that is dispatched whenever a new object is created on AI server cCstt|ƒj|ƒdS(N(tsuperRR(RR((s events.pyRHs(R R RR(((s events.pyREst DeletedEventcBseZdZd„ZRS(sJEvent that is dispatched whenever an object is deleted from AI server cCstt|ƒj|ƒdS(N(RRR(RR((s events.pyRRs(R R RR(((s events.pyROstObjectChangedEventcBseZdZd„ZRS(sQEvent that is dispatched whenever an object has changed on the AI server cCstt|ƒj|ƒdS(N(RRR(RR((s events.pyR]s(R R RR(((s events.pyRYstClientStatusEventcBsGeZdZdd„Zed„ƒZed„ƒZed„ƒZRS(sEvent that is dispatched whenever there is a change in a client's status If the reason_type use PROGRESS_UPDATE, then the percentage of progress should be specified, otherwise this value cannot be relied upon. A reason should be specified where possible. cCs©tt|ƒj|ƒ|tjƒkrMttjtdƒt |ƒƒ‚n||_ ||_ d|_ |tjkr¥d|koŽdkns™t‚||_ ndS(NsUnexpected status-type : %siid(RRRRtvaluesRRt INVALID_VALUEt_R t _status_typet_reasontNonet _percentagetPROGRESS_UPDATEtAssertionError(RRt status_typetreasont percentage((s events.pyRls     "cCs|jS(sRead-only status-stype(R(R((s events.pyR}scCs|jS(sRead-only reason message(R(R((s events.pyR‚scCs|jS(s]Read-only progress percentage, only valid if status_type is PROGRESS_UPDATE. (R(R((s events.pyR ‡sN( R R RRRRRRR (((s events.pyRds  tServerStatusEventcBs&eZdZd„Zed„ƒZRS(sLEvent that is dispatched whenever there is a change in a servers status cCs#tt|ƒj|ƒ||_dS(N(RR!Rt _status_info(RRt status_info((s events.pyR•scCs|jS(sRead-only attribute status_info(R"(R((s events.pyR#™s(R R RRRR#(((s events.pyR!’s t LoggingEventcBsGeZdZdd„Zed„ƒZed„ƒZed„ƒZRS(süEvent that is dispatched whenever there is a message to be passed to the client for consumption by user The log_level is based on the LOGGING_LEVEL enum. The log_percent value is only valid for LOGGING_LEVEL.PROGRESS events. cCsqtt|ƒj|ƒ||_||_d|_|dksR|tjksRt ‚|tjkrm||_ndS(N( RR$Rt _log_levelt _log_messageRt _log_percentRtPROGRESSR(RRt log_levelt log_messaget log_percent((s events.pyR«s   !cCs|jS(sRead-only attribute log_level(R%(R((s events.pyR)·scCs|jS(sRead-only attribute log_message(R&(R((s events.pyR*¼scCs|jS(sRead-only attribute log_percent(R'(R((s events.pyR+ÁsN( R R RRRRR)R*R+(((s events.pyR$¢s  tEventsGeneratorcBs–eZdZdefd„ƒYZd d„Zed„ƒZd„Z e d„ƒZ e ƒd d„Z e ƒd d„Ze ƒd d „Zd „ZRS( sñThis class is the base of any other AI server related class that can possibly generate events to API consumers. Consumers can use the methods in this class to register an interest in any events that can occur on an object. t _EventHandlercBs2eZdZd„Zd„Zd„Zd„ZRS(sWSimplistic internal container for the event handler and the user_data. cCsQ|dkst|dƒ r;ttjtdƒ|ƒ‚n||_||_dS(Nt__call__sHandler is not callable: (RthasattrRRRRthandlert user_data(RR0R1((s events.pyR×s   cCs|j||jƒS(s1Dispatch an event of event_type to handler method(R0R1(Rt event_type((s events.pytdispatch_eventßscCsK|j|jkrG|jdks0|jdkr4tS|j|jkSntS(N(R0R1RtTruetFalse(Rtother((s events.pyt__eq__ãs cCsd|j|jfS(Ns-[_EventHandler: handler = %s, user_data = %s](R0R1(R((s events.pyR ðs(R R RRR3R7R (((s events.pyR-Ós    cCsÌd|_|dk r›t|jtƒrvt|jƒjt|ƒƒrQ||_q˜tt j t dƒ|jj ƒ‚q›tt j t dƒ|jj ƒ‚nt ƒ|_x|D]}tƒ|j|tkeysR (Rt event_typestevt((s events.pyt__check_known_event_types6s     3     cCs|jS(s*Read-only access to event_handler_registry(R>(R((s events.pyR;OscCsW|j|ƒ}|j|ƒtj||ƒ}x"|D]}|j|j|ƒq5WdS(séUse this method to register a new callback method for specified event types. Parameters event_handler: Method reference This should be a reference to a static Python method that will be called when the event occurs. The signature of this method should look like: @staticmethod def event_handler(event_type, user_data): ... The method may return a value if this value evaluates to True then this will cause further dispatching of the event. The @staticmethod may be omitted if the method is not a member of a class. event_types: Iterable This should be a list/tuple of known event type classes that you wish to receive events on. user_data: any type This is a value that will be passed on to any event handler. N(t!_EventsGenerator__ensure_iterablet)_EventsGenerator__check_known_event_typesR,R-R>tappend(Rt event_handlerRNR1tehR2((s events.pytadd_event_handlerTs   cCsƒ|s|j}n|j|ƒ}|j|ƒtj||ƒ}x<|D]4}x+||j|krz|j|j|ƒqPWqGWdS(s9Use this method to remove an already registered callback method for specified event types and user_data. This removal will be done on a best-match, meaning that the more parameters specified the more targeted the removal will be. If you specify an event_handler, event_type and user_data then only a very specific match will be removed. In comparision if you only specify the event_handler, then all instances of that event_handler on this object will be removed, regardless of the event type. N(R>RQRRR,R-tremove(RRTRNR1RUR2((s events.pytremove_event_handlerxs   cCsl|s|j}n|j|ƒ}|j|ƒtj||ƒ}x%|D]}||j|krGtSqGWtS(s¥Use this method to check if a callback method for specified event types and user_data exists. Returns: True if match found, otherwise False (R>RQRRR,R-R4R5(RRTRNR1RUR2((s events.pythandler_exists•s   cCs|j|ƒ}|jg|D]}t|ƒ^qƒx?|D]7}x.|jt|ƒD]}|j|ƒrVPqVqVWq<W|jdk r™|jj|ƒndS(s*Dispatches the event_types to the handlersN(RQRRttypeR>R3R8Rtdispatch_events(RRNtetR2RU((s events.pyR[«s&  N(R R RtobjectR-RRt classmethodRQRRRR;ttupleRVRXRYR[(((s events.pyR,Ês! 8  #  N(Rtsolaris_install.ai.serverRRRRR]RR?RKRRSRRRR!R$R,(((s events.pyts "#    +  %