summaryrefslogtreecommitdiff
path: root/efl/utils
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2013-09-20 12:01:50 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2013-09-20 12:01:50 +0300
commit88db824a77db54a4dc75a13d0aa23c0a6da59d4c (patch)
tree2c82696c5fa7eacea69587bed8e49cb35c6a9402 /efl/utils
parentf8c332d6366149022306a84d027b1f2a29c66f97 (diff)
Change the _METHOD_DEPRECATED function into a decorator.
- move the decorator into a new package/module: utils/deprecated - simplify setup.py logic slightly, it still needs work
Diffstat (limited to 'efl/utils')
-rw-r--r--efl/utils/__init__.py0
-rw-r--r--efl/utils/deprecated.pyx45
2 files changed, 45 insertions, 0 deletions
diff --git a/efl/utils/__init__.py b/efl/utils/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/efl/utils/__init__.py
diff --git a/efl/utils/deprecated.pyx b/efl/utils/deprecated.pyx
new file mode 100644
index 0000000..908a682
--- /dev/null
+++ b/efl/utils/deprecated.pyx
@@ -0,0 +1,45 @@
1import traceback
2import types
3from functools import update_wrapper
4
5
6class DEPRECATED(object):
7
8 def __init__(self, object f):
9 self.f = f
10
11 assignments = ["__name__", "__doc__"]
12 if hasattr(f, "__module__"):
13 assignments.append("__module__")
14 update_wrapper(self, f, assigned=assignments)
15
16 #if hasattr(f, "__objclass__"):
17 #print("WARNING: method %s.%s is deprecated" % (f.__objclass__.__name__, f.__name__))
18 #else:
19 #print("WARNING: function %s is deprecated" % (f.__name__))
20
21 def __get__(self, obj, objtype):
22 return types.MethodType(self, obj, objtype)
23
24 def __call__(self, *args, **kwargs):
25 cdef:
26 object stack
27 tuple caller
28 str msg
29
30 stack = traceback.extract_stack()
31 caller = stack[-1]
32 caller_module, caller_line, caller_name, caller_code = caller
33 if caller_code is not None:
34 if hasattr(self.f, "__objclass__"):
35 msg = "WARNING: Deprecated method %s of class %s called in %s:%s %s." % \
36 (self.f.__name__, self.f.__objclass__.__name__, caller_module, caller_line, caller_code)
37 else:
38 msg = "WARNING: Deprecated function %s called in %s:%s %s." % \
39 (self.f.__name__, caller_module, caller_line, caller_code)
40 else:
41 msg = "WARNING: Deprecated function %s.%s called in %s:%s." % \
42 (self.f.__name__, caller_name, caller_module, caller_line)
43 print(msg)
44
45 return self.f(*args, **kwargs)