-
Notifications
You must be signed in to change notification settings - Fork 0
/
footest.py
49 lines (39 loc) · 1.42 KB
/
footest.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
__author__ = 'Administrator'
import time
def cleanup():
time.sleep(10)
print "in foo hahha"
def upper_attr(future_class_name, future_class_parents,future_class_attr):
print future_class_name, future_class_parents,future_class_attr
uppercase_attr = {}
for name, val in future_class_attr.items():
if not name.startswith("__"):
uppercase_attr[name.upper()] = val
else:
uppercase_attr[name] = val
return type(future_class_name, future_class_parents, uppercase_attr)
class UpperAttrMetaClass(type):
def __new__(cls,clsname,bases,attrs):
print cls,clsname,bases,attrs
uppercase_attr = {}
for name,val in attrs.items():
if not name.startswith("__"):
uppercase_attr[name.upper()] = val
else:
uppercase_attr[name] = val
return super(UpperAttrMetaClass,cls).__new__(cls,clsname, bases, uppercase_attr)
def __init__(self,clsname,bases,attrs):
print self,clsname,bases,attrs
super(UpperAttrMetaClass,self).__init__(clsname,bases,attrs)
class FOO1(object):
def __new__(cls, *args, **kwargs):
print cls == FOO1
return super(FOO1,cls).__new__(cls)
def __init__(self,name,age):
super(FOO1,self).__init__()
__metaclass__ = UpperAttrMetaClass
myfoo = FOO1('huang',24)
class Foo():
bar = 'bip'
print(hasattr(Foo,'bar'))
print(hasattr(Foo,'BAR'))