Mercurial > traipse_dev
annotate orpg/tools/decorators.py @ 180:12ba14d30baa alpha
Traipse Alpha 'OpenRPG' {100115-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 (Keeping up with Beta)
New Features:
Added Bookmarks
Added 'boot' command to remote admin
Added confirmation window for sent nodes
Minor changes to allow for portability to an OpenSUSE linux OS
Miniatures Layer pop up box allows users to turn off Mini labels, from
FlexiRPG
Zoom Mouse plugin added
Images added to Plugin UI
Switching to Element Tree
Map efficiency, from FlexiRPG
Added Status Bar to Update Manager
New TrueDebug Class in orpg_log (See documentation for usage)
Portable Mercurial
Tip of the Day added, from Core and community
New Reference Syntax added for custom PC sheets
New Child Reference for gametree
New Parent Reference for gametree
New Gametree Recursion method, mapping, context sensitivity, and
effeciency..
New Features node with bonus nodes and Node Referencing help added
Dieroller structure from Core
New DieRoller portability for odd Dice
Added 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)]
New 'Mythos' System die roller added
Added new vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)].
Included for Mythos roller also
New Warhammer FRPG Die Roller (Special thanks to Puu-san for the
support)
New EZ_Tree Reference system. Push a button, Traipse the tree, get a
reference (Beta!)
Fixes:
Fix to Text based Server
Fix to Remote Admin Commands
Fix to Pretty Print, from Core
Fix to Splitter Nodes not being created
Fix to massive amounts of images loading, from Core
Fix to Map from gametree not showing to all clients
Fix to gametree about menus
Fix to Password Manager check on startup
Fix to PC Sheets from tool nodes. They now use the tabber_panel
Fix to Whiteboard ID to prevent random line or text deleting.
Fixes to Server, Remote Server, and Server GUI
Fix to Update Manager; cleaner clode for saved repositories
Fixes made to Settings Panel and now reactive settings when Ok is
pressed
Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of
a Splice
Fix to Use panel of Forms and Tabbers. Now longer enters design mode
Fix made Image Fetching. New fetching image and new failed image
Modified ID's to prevent non updated clients from ruining the fix.
default_manifest.xml renamed to default_upmana.xml
author | sirebral |
---|---|
date | Fri, 15 Jan 2010 00:09:39 -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 |