# Path: wimpiggy/log.py
# class Logger(object):
#     def __init__(self, base=None):
#         if base is None:
#             base = sys._getframe(1).f_globals["__name__"]
#         self._base = base
# 
#     def getLogger(self, type=None):
#         name = self._base
#         if type:
#             name += ". " + type
#         return logging.getLogger(name)
# 
#     def log(self, level, msg, *args, **kwargs):
#         if kwargs.get("exc_info") is True:
#             kwargs["exc_info"] = sys.exc_info()
#         type = None
#         if "type" in kwargs:
#             type = kwargs["type"]
#             del kwargs["type"]
#         self.getLogger(type).log(level, msg, *args, **kwargs)
# 
#     def _method_maker(level):
#         return (lambda self, msg, *args, **kwargs:
#                 self.log(level, msg, *args, **kwargs))
# 
#     debug = _method_maker(logging.DEBUG)
#     __call__ = debug
#     info = _method_maker(logging.INFO)
#     warn = _method_maker(logging.WARNING)
#     error = _method_maker(logging.ERROR)


import gobject
import gtk
    import ctypes
    import inspect
from wimpiggy.log import Logger
#
# Solution: indirection!
#
# Specifically, we keep track of the 'state' of each such nested call. Each
# call can be in one of 3 states:
#   -- done
#   -- soft timed out
#   -- hard timed out
# The soft-timeout is the maximum amount of time that this nested call can
# block other nested calls from completion. The hard-timeout is the maximum
# amount of time that we'll wait for this nested call, period. (However, this
# might be extended if this nested call ends up blocked on other calls. If the
# nested call finishes after the hard time out expires, but before we actually
# get around to processing it, then it'll still be processed as normal -- not
# as timed out.)
#
# There actually is no guarantee on how long a nested call ends up blocked,
# even in the face of soft timeouts, because new nested calls might keep
# coming in, each extending the total blocking period by their soft
# timeout. If the user ever stops pasting madly for a few seconds, though,
# then everything should have a chance to return to equilibrium...


log = Logger()

# For debugging:
def _dump_recursion_info():
    # This is how deeply nested in recursive main-loops we are:
    print "gtk depth: %s" % (gtk.main_level())
    class ThreadState(ctypes.Structure):

# Path: wimpiggy/log.py
# class Logger(object):
#     def __init__(self, base=None):
#         if base is None:
#             base = sys._getframe(1).f_globals["__name__"]
#         self._base = base
# 
#     def getLogger(self, type=None):
#         name = self._base
#         if type:
#             name += ". " + type
#         return logging.getLogger(name)
# 
#     def log(self, level, msg, *args, **kwargs):
#         if kwargs.get("exc_info") is True:
#             kwargs["exc_info"] = sys.exc_info()
#         type = None
#         if "type" in kwargs:
#             type = kwargs["type"]
#             del kwargs["type"]
#         self.getLogger(type).log(level, msg, *args, **kwargs)
# 
#     def _method_maker(level):
#         return (lambda self, msg, *args, **kwargs:
#                 self.log(level, msg, *args, **kwargs))
# 
#     debug = _method_maker(logging.DEBUG)
#     __call__ = debug
#     info = _method_maker(logging.INFO)
#     warn = _method_maker(logging.WARNING)
#     error = _method_maker(logging.ERROR)


# Path: xpra/nested_main.py
import gobject
import gtk
    import ctypes
    import inspect
from wimpiggy.log import Logger

#
# Solution: indirection!
#
# Specifically, we keep track of the 'state' of each such nested call. Each
# call can be in one of 3 states:
#   -- done
#   -- soft timed out
#   -- hard timed out
# The soft-timeout is the maximum amount of time that this nested call can
# block other nested calls from completion. The hard-timeout is the maximum
# amount of time that we'll wait for this nested call, period. (However, this
# might be extended if this nested call ends up blocked on other calls. If the
# nested call finishes after the hard time out expires, but before we actually
# get around to processing it, then it'll still be processed as normal -- not
# as timed out.)
#
# There actually is no guarantee on how long a nested call ends up blocked,
# even in the face of soft timeouts, because new nested calls might keep
# coming in, each extending the total blocking period by their soft
# timeout. If the user ever stops pasting madly for a few seconds, though,
# then everything should have a chance to return to equilibrium...


log = Logger()

# For debugging:
def _dump_recursion_info():
    # This is how deeply nested in recursive main-loops we are:
    print "gtk depth: %s" % (gtk.main_level())
    class ThreadState(ctypes.Structure):

        _fields_ = [("next", ctypes.c_voidp),