访问 Python 类的函数子集
使用具有 xmlrpc 代理作为其对象属性之一的类,
def __init__(self):
self.proxy = ServerProxy(...)
# ...
我试图简化某些代理功能的使用。应该只使用代理函数的子集,因此我想到为它们创建一组微小的包装函数,例如
def sample(self):
""" A nice docstring for a wrapper function. """
self.proxy.sample()
是否有一个好的方法来获取所有包装函数的列表?我正在考虑类似 dir() 的东西,但随后我需要过滤对象的包装函数。 xmlrpc 内省 (http://xmlrpc-c.sourceforge.net/introspection.html )也没有多大帮助,因为我不想使用/提供服务器的所有功能。
也许在包装器上设置一个属性和 @staticmethod get_wrappers() 可以解决问题。有 _wrapper 后缀不适合我的用例。类中跟踪可用的静态列表太容易出错。所以我正在寻找关于如何最好地获取包装函数列表的好主意?
Using a class that has an xmlrpc proxy as one of it's object's properties
def __init__(self):
self.proxy = ServerProxy(...)
# ...
I'm trying to ease the use of some of the proxy's functions. Only a subset of the proxy functions are supposed to be used and I thus thought of creating a set of tiny wrapper functions for them like
def sample(self):
""" A nice docstring for a wrapper function. """
self.proxy.sample()
Is there a good way of getting a list of all the wrapper functions? I'm thinking about something like dir(), but then I would need to filter for the object's wrapper functions. xmlrpc introspection (http://xmlrpc-c.sourceforge.net/introspection.html) doesn't help much either since I don't want to use/ provide all the server's functions.
Maybe setting an attribute on the wrappers together with a @staticmethod get_wrappers() would do the trick. Having a _wrapper suffix is not appropriate for my use case. A static list in the class that keeps track of the available is too error prone. So I'm looking for good ideas on how to best getting a list of the wrapper functions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定这是否是您想要的,但它有效:
然后
I'm not 100% sure if this is what you want, but it works:
Then
使用 xml-rpc 自省来获取服务器列表并将其与对象的属性相交。像这样的东西:
Use xml-rpc introspection to get the server list and intersect it with your object's properties. Something like: