³ò
šõÜNc        	   @€  s  d  d k  l Z d  d k Z d  d k Td  d k Td  d k l Z e i ƒ  Z d e _	 d e _
 d e _ d e _ d	 e _ h  d
 e <d e <d e <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 S(   iÿÿÿÿ(   t   with_statementN(   t   *(   t   ESEventErrors&   Eventlib - EventScripts python librarys   Eventlib Draft 14s+   http://www.eventscripts.com/pages/Eventlib/t   eventlibt   XE_ManUpt   setfloatt   setintt	   setstringt   EventContextManagerc           B€  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sC   Inspired from http://forums.eventscripts.com/viewtopic.php?p=367772c         C€  sr   t  | ƒ } t | ƒ d j o t d | d ƒ ‚ n) | i d ƒ o t d d | ƒ ‚ n t  | ƒ |  _ d  S(   Ni    s   The event name "%s" exceeds s$   the maximum length of 32 characters.t    s'   Event names are not allowed to contain s   spaces: "%s".(   t   strt   lenR   t   countt   _name(   t   selft
   event_name(    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyt   __init__&   s    
c         C€  s.   t  i d d |  i ƒ t  i d |  i ƒ |  S(   sa   Utilized when the EventContextManager is entered. Used to initialize
        the event.

        i   s   es.event('initialize', '%s')t
   initialize(   t   est   dbgmsgR   t   event(   R   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyt	   __enter__5   s    c         C€  sg   | p2 t  i d d |  i ƒ t  i d |  i ƒ t Sn t  i d d |  i ƒ t  i d |  i ƒ t S(   s  Utilized when the EventContextManager is exited. Used to fire the
        event if there were no errors while setting the values. If any
        tracebacks were generated between the entering of the
        EventContextManager and the exit, the event will be cancelled.

        i   s   es.event('fire', '%s')t   fires   es.event('cancel', '%s')t   cancel(   R   R   R   R   t   Truet   False(   R   t   exc_typet	   exc_valuet	   traceback(    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyt   __exit__>   s    c         C€  sŒ   t  | ƒ t j o% t d t  | ƒ i d d ƒ ‚ n t i d d t t  | ƒ |  i | | f ƒ t i t t  | ƒ |  i | | ƒ d S(   s:   Sets the event variable values dynamically for es.event().s   Unsupported type: %s. Expecteds    float, int, or strs    type.i   s   es.event('%s', '%s', '%s', %s)N(   t   typet	   DATATYPESR   t   __name__R   R   R   R   (   R   t   fieldt   value(    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyt   setQ   s    !(   R    t
   __module__t   __doc__R   R   R   R#   (    (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR   $   s
   				t
   QuickEventc           B€  s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   sd  Class that can be used to fire an event without any error-checking or
    restrictions. It can also be used as a context manager using the with
    statement.

    Args:
        name (str): The name of the event.

    Kwargs:
        event_var_name (str)=event_var_value (int, float, str)

    Example Usage:
        # Example 1 (using a context manager)
        with QuickEvent('player_say') as event:
            event.userid = 2
            event.text = 'This is a test.'

        # Example 2 (directly firing using keyword arguments and fire() method)
        QuickEvent('player_say', userid=2, text='This is a test.').fire()

        # Example 3 (creating an instance, then firing)
        event = QuickEvent('player_say', userid=2, text='This is a test.')
        event.fire() # Fire using the fire() method
        event() # Fire using the __call__ method

    c         K€  sZ   t  t |  ƒ i d | ƒ t i d | ƒ x* | i ƒ  D] \ } } |  i | | ƒ q6 Wd  S(   Nt   nameR   (   t   superR&   t   __setattr__R   R   t	   iteritemst   set_event_var(   R   R'   t   kwR"   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR   x   s
     c         C€  s   |  i  ƒ  d  S(   N(   R   (   R   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyt   __call__ƒ   s    c         C€  s   |  S(   s(   Utilized when the QuickEvent is entered.(    (   R   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR   †   s    c         G€  s-   t  | ƒ p |  i ƒ  t Sn |  i ƒ  t S(   s  Utilized when the QuickEvent is exited. Used to fire the event if
        there were no errors while setting the values. If any tracebacks were
        generated between the entering of the QuickEvent and the exit, the
        event will be cancelled.

        (   t   anyR   R   R   R   (   R   t   a(    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR   Š   s
    

c         C€  s   |  i  | | ƒ d  S(   N(   R+   (   R   R'   R"   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR)   ›   s    c         C€  s   |  i  | | ƒ d  S(   N(   R+   (   R   R'   R"   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyt   __setitem__Ÿ   s    c         C€  s}   t  | t ƒ o t i d |  i | | ƒ nM t  | t ƒ o t i d |  i | | ƒ n  t i d |  i | t | ƒ ƒ d S(   sr   Sets the event variable by its type. If the type is not found, the
        type is assumed to be string.

        R   R   R   N(   t
   isinstancet   intR   R   R'   t   floatR
   (   R   t   itemR"   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR+   £   s
    c         C€  s   t  i d |  i ƒ d S(   s   Cancels the event.R   N(   R   R   R'   (   R   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR   ¯   s    c         C€  s   t  i d |  i ƒ d S(   s   Fires the event.R   N(   R   R   R'   (   R   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR   ³   s    (   R    R$   R%   R   R-   R   R   R)   R0   R+   R   R   (    (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR&   ^   s   								t   EventManagerc           B€  s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         O€  s?   d |  i  j o( t i |  | | Ž |  _ g  |  i _ n |  i S(   Nt   _the_instance(   t   __dict__t   objectt   __new__R6   t
   _callbacks(   t   clsR/   R,   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR9   ¹   s    c   
      C€  s/  h  } xo |  i  i ƒ  D]^ \ } } y | i |  i | ƒ } Wn+ t j
 o t d | d d ƒ ‚ n X| | | <q WxL |  i D]A } | |   } | d j o q‚ q‚ t | ƒ t	 j o t	 Sq‚ q‚ Wt
 |  i ƒ  ƒ i } i ƒ  } z: | ~ }	 x* | i ƒ  D] \ } } |	 i | | ƒ qÿ WWd | ~ QXt S(   sý  Handles the firing of ESEvent instances by initializing the
        EventContextManager, setting the int, float, or string values, then
        firing the event if no errors are raised. If errors are raised during
        the process, the event firing will be cancelled.

        Notes:
            * Returns True if the event was successfully fired.
            * Returns False if the event was cancelled via a callback.
            * Raises an exception if the event was not fired due to an error.

        s   Instance variable "%s" must bes'   set/declared prior to using the fire() s   method.N(   t   _fieldst   itemst	   to_pythonR7   t   KeyErrorR   R:   t   Nonet   boolR   R   t   get_event_nameR   R   R#   R   (
   R   t
   field_dictR!   t   evR"   t   callbackt   continue_eventt   _[1]t   _[2]R   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR   ¿   s,     
 +  c         C€  sQ   t  | ƒ p t d | d ƒ ‚ n | |  i j o d Sn |  i i | ƒ d S(   sÝ  Registers a callback to be performed just before the event fires.

        Notes:
            * Requires the callback to accept keyword arguments (**kwargs).
            * Requires the callback to return a boolean return value.
            * If the callback returns False, it will cancel the event.
            * If the callback returns True, the event will fire.
            * If no return value is specified in the callback, the event will
              still fire.

        s!   Callback registration failed: %s s   is not callable.N(   t   callableR   R:   t   append(   R   RE   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyt   register_prefire_callbacké   s    
c         C€  s(   | |  i  j o |  i  i | ƒ n d S(   s   Unregisters a callback.N(   R:   t   remove(   R   RE   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyt   unregister_prefire_callback  s    (   R    R$   R9   R   RK   RM   (    (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR5   ¸   s   		*	t   ESEventMetac           B€  s   e  Z d  „  Z RS(   c         C€  sK   h  |  _  x; | i ƒ  D]- \ } } t | t ƒ o | |  i  | <q q Wd  S(   N(   R<   R=   R1   t
   EventField(   R;   R'   t   basest   contentst   keyR"   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR     s
    	 (   R    R$   R   (    (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyRN     s   t   ESEventc           B€  s;   e  Z e Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         K€  sX   x> | i  ƒ  D]0 \ } } | |  i j o t |  | | ƒ q q Wt t |  ƒ i ƒ  d  S(   N(   R=   R<   t   setattrR(   RS   R   (   R   R,   RR   R"   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR     s
     c         C€  sM   | |  i  j o  |  i  | } | i | ƒ } n t t |  ƒ i | | ƒ d  S(   N(   R<   R>   R(   RS   R)   (   R   RR   R"   t   evField(    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR)     s    c         C€  s   t  i |  | | ƒ d  S(   N(   R8   R)   (   R   RR   R"   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyR0   %  s    c         C€  s   t  i |  | ƒ S(   N(   R8   t   __getattribute__(   R   RR   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyt   __getitem__)  s    c         C€  s   |  i  i i ƒ  S(   s   Returns the event name.(   t	   __class__R    t   lower(   R   (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyRB   -  s    (	   R    R$   RN   t   __metaclass__R   R)   R0   RW   RB   (    (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pyRS     s   				(   t
   __future__R    R   t   fieldst   resourcet
   exceptionsR   t	   AddonInfot   infoR'   t   versiont   urlt   basenamet   authorR3   R2   R
   R   R8   R   R&   R5   R   RN   RS   (    (    (    sa   /home/saberrider/srcds/css/cstrike/addons/eventscripts/gungame51/core/events/eventlib/__init__.pys   <module>   s    

					!:ZO