# Path: pyGBot/log.py
# def addScreenHandler(logobj, format):
# def addLogFileHandler(logobj, filename, format):


from pyGBot import log
from sys import exc_info
from traceback import extract_tb, format_tb
         assert name in self.__class__.__events__, \
                "Event '%s' is not declared" % name
      self.__dict__[name] = ev = _EventSlot(name)
      return ev
   def __repr__(self): return 'Events' + str(list(self))
   __str__ = __repr__
   def __len__(self): return NotImplemented
   def __iter__(self):
      def gen(dictitems=self.__dict__.items()):
         for attr, val in dictitems:
            if isinstance(val, _EventSlot):
               yield val
      return gen()

class _EventSlot:
   def __init__(self, name):
      self.targets = []
      self.__name__ = name
   def __repr__(self):
      return 'event ' + self.__name__
   def __call__(self, *a, **kw):
      for f in self.targets:
         # pyGBot-specific: try/except block to catch and log exceptions
         try:
            f(*a, **kw)
         except: # log exceptions in event targets
            eclass, e, etrace = exc_info()
            efile, eline, efunc, esource = extract_tb(etrace)[-1]
            log.logger.error("%s: %s raised in '%s', file '%s', line %i",\
                eclass.__name__, str(e), efunc, efile, eline)

# Path: pyGBot/log.py
# def addScreenHandler(logobj, format):
# def addLogFileHandler(logobj, filename, format):


# Path: contrib/Events.py
from pyGBot import log
from sys import exc_info
from traceback import extract_tb, format_tb

         assert name in self.__class__.__events__, \
                "Event '%s' is not declared" % name
      self.__dict__[name] = ev = _EventSlot(name)
      return ev
   def __repr__(self): return 'Events' + str(list(self))
   __str__ = __repr__
   def __len__(self): return NotImplemented
   def __iter__(self):
      def gen(dictitems=self.__dict__.items()):
         for attr, val in dictitems:
            if isinstance(val, _EventSlot):
               yield val
      return gen()

class _EventSlot:
   def __init__(self, name):
      self.targets = []
      self.__name__ = name
   def __repr__(self):
      return 'event ' + self.__name__
   def __call__(self, *a, **kw):
      for f in self.targets:
         # pyGBot-specific: try/except block to catch and log exceptions
         try:
            f(*a, **kw)
         except: # log exceptions in event targets
            eclass, e, etrace = exc_info()
            efile, eline, efunc, esource = extract_tb(etrace)[-1]
            log.logger.error("%s: %s raised in '%s', file '%s', line %i",\
                eclass.__name__, str(e), efunc, efile, eline)

            log.logger.debug("    %s", esource)