Last active
January 30, 2016 23:34
-
-
Save johnpauljanecek/23eb8f577350d893d97d to your computer and use it in GitHub Desktop.
Demos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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