decometaclass.py (1256B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\decometaclass\decometaclass.py 2 import blue 3 import types 4 types.BlueType = type(blue.os) 5 6 class DecoMetaclass(type): 7 8 def __new__(mcs, name, bases, dict): 9 cls = type.__new__(mcs, name, bases, dict) 10 cls.__persistvars__ = cls.CombineLists('__persistvars__') 11 cls.__nonpersistvars__ = cls.CombineLists('__nonpersistvars__') 12 return cls 13 14 def __call__(cls, inst = None, initDict = None, *args, **kwargs): 15 if not inst: 16 inst = blue.classes.CreateInstance(cls.__cid__) 17 inst.__klass__ = cls 18 if initDict: 19 for k, v in initDict.iteritems(): 20 setattr(inst, k, v) 21 22 if hasattr(inst, '__init__'): 23 inst.__init__() 24 return inst 25 26 def CombineLists(cls, name): 27 result = [] 28 for b in cls.__mro__: 29 if hasattr(b, name): 30 result += list(getattr(b, name)) 31 32 return result 33 34 subclasses = {} 35 36 37 def GetDecoMetaclassInst(cid): 38 39 class parentclass(object): 40 __metaclass__ = DecoMetaclass 41 __cid__ = cid 42 43 return parentclass 44 45 46 BlueWrappedMetaclass = DecoMetaclass 47 WrapBlueClass = GetDecoMetaclassInst