/
main.py
70 lines (45 loc) · 1.51 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
__author__ = 'Andrew Hawker <andrew.r.hawker@gmail.com>'
class Descriptor(object):
def __init__(self, name):
self.name = name
def __get__(self, instance, owner=None):
if instance is None:
return self
return '__get__'
#return instance.config.get(self.name)
class ServiceMeta(type):
def __new__(mcs, name, bases, attrs):
# for k,v in attrs.iteritems():
# if isinstance(v, Descriptor):
# print '{0}: {1}'.format(k,v.__get__(mcs))
return super(ServiceMeta, mcs).__new__(mcs, name, bases, attrs)
class Service(object):
__metaclass__ = ServiceMeta
x = Descriptor('x')
y = Descriptor('y')
def __init__(self):
self.config = {}
def func(self):
import inspect
print 'fuck'
print inspect.ismethoddescriptor(self.__class__.x)
for a in dir(self):
v = getattr(self, a)
print '{0} -- {1} -- {2}'.format(str(a), str(v), type(a))
print type(self.x)
print type(self.y)
@classmethod
def cfunc(cls):
import inspect
#for name, value in ((name, getattr(cls, name, None)) for name in dir(cls) if not name.startswith('_')):
# print ''
print inspect.ismethoddescriptor(cls.x)
for a in dir(cls):
v = getattr(cls, a)
print '{0} -- {1} -- {2}'.format(str(a), str(v), type(v))
def main():
s = Service()
s.func()
#Service.cfunc()
if __name__ == '__main__':
main()