Skip to content

Instantly share code, notes, and snippets.

@johnpauljanecek
Last active January 30, 2016 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnpauljanecek/23eb8f577350d893d97d to your computer and use it in GitHub Desktop.
Save johnpauljanecek/23eb8f577350d893d97d to your computer and use it in GitHub Desktop.
Demos
class FunctionMeta(type):
class RpcWrapper(object):
def __init__(self,name):
self.name = name
def __call__(self):
print(self.name)
def __new__(cls, clsname, superclasses,attributedict):
print("clsname: ", clsname)
print("superclasses: ", superclasses)
print("attributedict: ", attributedict)
attributedict["aaa"] = 100
for name in attributedict["wrapFunctionNames"] :
attributedict["rpc_" + name] = RpcWrapper(name)
return type.__new__(cls, clsname, superclasses, attributedict)
def X__init__(cls, clsname, superclasses,attributedict):
attributedict["aaa"] = 100
for name in cls.wrapFunctionNames :
attributedict["rpc_" + name] = RpcWrapper(name)
type.__init__(cls, clsname, superclasses, attributedict)
print("clsname: ", clsname)
print("superclasses: ", superclasses)
print("attributedict: ", attributedict)
class Foobar(object,metaclass = FunctionMeta):
wrapFunctionNames = "cls,clsname,superclasses,attributedict".split(",")
def __init__(self):
print("Foobar.__init__ %r",Foobar.__init__)
fb = Foobar()
[name for name in dir(fb) if name.startswith("rpc_")]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment