annotate orpg/tools/decorators.py @ 245:682032381be8 beta

Traipse Beta 'OpenRPG' {101130-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Closing/Closed) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order New to Server GUI, can now clear log New Earthdawn Dieroller New IronClaw roller, sheet, and image Updates: Update to Warhammer PC Sheet. Rollers set as macros. Should work with little maintanence. Update to Browser Server window. Display rooms with ' " & cleaner Update to Server. Handles ' " & cleaner Update to Dieroller. Cleaner, more effecient expression system Update to Hidden Die plugin, allows for non standard dice rolls Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to metaservers.xml file not being created Fix to Single and Double quotes in Whiteboard text Fix to Background images not showing when using the Image Server Fix to Duplicate chat names appearing Fix to Server GUI's logging output Fix to FNB.COLORFUL_TABS bug Fix to Gametree for XSLT Sheets Fix to Gametree for locating gametree files Fix to Send to Chat from Gametree Fix to Gametree, renaming and remapping operates correctly Fix to aliaslib, prevents error caused when SafeHTML is sent None
author sirebral
date Tue, 30 Nov 2010 02:34:58 -0600
parents 37a11fea3304
children
rev   line source
72
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
1 import warnings
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
2 import functools
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
3
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
4 from orpg.orpgCore import *
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
5
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
6 def deprecated(msg=None):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
7 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
8 This is a decorator which can be used to mark functions
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
9 as deprecated. It will result in a warning being emitted
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
10 when the function is used.
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
11 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
12 def wrap(func):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
13 @functools.wraps(func)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
14 def new_func(*args, **kwargs):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
15 out = msg
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
16 if not out:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
17 out = "Call to deprecated function %s."
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
18 else:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
19 out = "Call to deprecated function %s.\n" + out
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
20
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
21 warnings.warn_explicit(
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
22 out % (func.__name__),
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
23 category=DeprecationWarning,
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
24 filename=func.func_code.co_filename,
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
25 lineno=func.func_code.co_firstlineno + 1
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
26 )
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
27 return func(*args, **kwargs)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
28 return new_func
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
29 return wrap
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
30
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
31 def pending_deprecation(msg=None):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
32 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
33 This is a decorator which can be used to mark functions
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
34 as deprecated. It will result in a warning being emitted
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
35 when the function is used.
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
36 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
37 def wrap(func):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
38 @functools.wraps(func)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
39 def new_func(*args, **kwargs):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
40 out = msg
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
41 if not out:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
42 out = "%s is Pending Deprecation."
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
43 else:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
44 out = "%s is Pending Deprecation.\n" + out
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
45
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
46 warnings.warn_explicit(
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
47 out % (func.__name__),
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
48 category=PendingDeprecationWarning,
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
49 filename=func.func_code.co_filename,
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
50 lineno=func.func_code.co_firstlineno + 1
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
51 )
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
52 return func(*args, **kwargs)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
53 return new_func
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
54 return wrap
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
55
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
56 def synchronized(lock):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
57 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
58 Synchronization decorator.
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
59 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
60
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
61 @functools.wraps(func)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
62 def new_func(*args, **kwargs):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
63 lock.acquire()
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
64 try:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
65 return func(*args, **kwargs)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
66 finally:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
67 lock.release()
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
68 return new_func
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
69
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
70 class memoized(object):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
71 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
72 Decorator that caches a function's return value each time it is called.
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
73 If called later with the same arguments, the cached value is returned, and
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
74 not re-evaluated.
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
75 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
76 def __init__(self, func):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
77 self.func = func
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
78 self.cache = {}
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
79
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
80 def __call__(self, *args, **kwargs):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
81 try:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
82 return self.cache[args + kwargs.values()]
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
83 except KeyError:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
84 self.cache[args] = value = self.func(*args, **kwargs)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
85 return value
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
86 except TypeError:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
87 # uncachable -- for instance, passing a list as an argument.
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
88 # Better to not cache than to blow up entirely.
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
89 return self.func(*args)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
90 def __repr__(self):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
91 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
92 Return the function's docstring.
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
93 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
94 return self.func.__doc__
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
95
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
96 def debugging(func):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
97 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
98 Decorator to print Enter/Exit debugging info
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
99 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
100
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
101 @functools.wraps(func)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
102 def new_func(*args, **kwargs):
76
37a11fea3304 More clean up. Images now posts a Chat Info post if image doesn't load.
sirebral
parents: 72
diff changeset
103 from orpg_log import logger
72
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
104
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
105 if not ORPG_DEBUG & logger.log_level:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
106 return func(*args, **kwargs)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
107
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
108 if str(args[0].__class__).startswith('<class'):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
109 cls = args[0].__class__.__name__
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
110 args_s = "self"
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
111 if len(args) > 1:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
112 args_s += ', ' + ', '.join([str(attr) for attr in args[1:]])
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
113 kwargs_s = ""
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
114 for k,v in kwargs.iteritems():
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
115 kwargs_s += ', ' + k + '=' + str(v)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
116
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
117 call_str = '%(cls)s->%(fnc)s(%(args)s%(kwargs)s)' % {
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
118 'cls':cls,
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
119 'fnc':func.__name__,
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
120 'args':args_s,
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
121 'kwargs':kwargs_s}
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
122 try:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
123 logger.debug("Enter " + call_str)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
124 return func(*args, **kwargs)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
125 finally:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
126 logger.debug("Exit " + call_str)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
127 else:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
128 try:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
129 logger.debug("Enter " + func.__name__)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
130 return func(*args, **kwargs)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
131 finally:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
132 logger.debug("Exit " + func.__name__)
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
133 return new_func
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
134
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
135 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
136 Cannot use this decorator till we stop supporting py2.5
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
137 as class decorators did not land till py2.6 I am just adding it here
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
138 So when we do we can convert all singleton classes to use it
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
139 """
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
140 def singleton(cls):
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
141 instances = {}
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
142 def getinstance():
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
143 if cls not in instances:
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
144 instances[cls] = cls()
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
145 return instances[cls]
8bc955faf819 Fixing a few mistakes from the last update. When Controls is finished I will be happy because users won't miss an file change due to these small updates.
sirebral
parents:
diff changeset
146 return getinstance