Pylons / pyramid_rpc

RPC plugins for pyramid. XML-RPC, JSON-RPC, etc.
https://docs.pylonsproject.org/projects/pyramid-rpc/en/latest/
Other
27 stars 20 forks source link

Expose the methods of a class as view callables #12

Closed kabhinav closed 13 years ago

kabhinav commented 13 years ago
mmerickel commented 13 years ago

This patch looks really nice (tests too!!). It looks like it goes against the way that Pyramid handles class-based views, however. In Pyramid the add_view method actually supports the attr property which allows you to use a particular method of a class as the method that is called. In this way you are able to do code like the following:

class JSONRPCHandler(object):
    def __init__(self, request):
        self.request = request

    def method(self):
        return {}

config.add_view(JSONRPCHandler, name='say_hello', attr='method', ...)

This is counter to the logic in your mapper which actually scans the targeted class for possible methods based on their name . However, don't worry, the next release of pyramid_rpc will have a functional view mapper. I've actually rewritten the entire JSON RPC API and it's now using a super complicated view mapper hijacked from a different project and that view mapper will actually be enabled by default.