Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
pyramid_rpc chaining decorators
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Vlad K.  
View profile  
 More options Aug 7 2012, 11:42 am
From: "Vlad K." <v...@haronmedia.com>
Date: Tue, 07 Aug 2012 17:42:40 +0200
Local: Tues, Aug 7 2012 11:42 am
Subject: pyramid_rpc chaining decorators

Hi all,

I have a JSON RPC API as a set of methods which all have some common
processing involved, esp. regarding exceptions. To catch those and in
turn raise proper JsonRpcError, with proper code and message, I wanted
to wrap the methods in a common decorator.

@common_rpc
@jsonrpc_method(endpoint="jsonrpc", method="blahblah")
def blahblah(request, ...params...):
     ...

But then I get "method not found", and if I swap @common_rpc with
@jsonrpc_method, of course then params are not identified by pyramid_rpc
(MapplyViewMapper).

Am I doing something wrong, perhaps missing to do something with
Venusian? Or is it impossible to chain decorators with @jsonrpc_method?

Thanks.

--

.oO V Oo.

Work Hard,
Increase Production,
Prevent Accidents,
and
Be Happy!  ;)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Merickel  
View profile  
 More options Aug 7 2012, 12:56 pm
From: Michael Merickel <mmeri...@gmail.com>
Date: Tue, 7 Aug 2012 11:56:18 -0500
Local: Tues, Aug 7 2012 12:56 pm
Subject: Re: pyramid_rpc chaining decorators
You haven't shown me the signature of your decorator or any errors.
Ignoring that, jsonrpc_method, similar to view_config in pyramid,
supports a `decorator` argument that guarantees you a common signature
for decorators:

def common_rpc(view):
    def _wrapped(context, request):
        # do stuff with request.rpc_args or whatever else
        return view(context, request)
    return _wrapped

@jsonrpc_method(endpoint="jsonrpc", method="blahblah", decorator=common_rpc)
def blahblah_view(request, .. params):
    return {}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vlad K.  
View profile  
 More options Aug 7 2012, 1:51 pm
From: "Vlad K." <v...@haronmedia.com>
Date: Tue, 07 Aug 2012 19:51:40 +0200
Local: Tues, Aug 7 2012 1:51 pm
Subject: Re: pyramid_rpc chaining decorators

On 08/07/2012 06:56 PM, Michael Merickel wrote:

> You haven't shown me the signature of your decorator or any errors.
> Ignoring that, jsonrpc_method, similar to view_config in pyramid,
> supports a `decorator` argument that guarantees you a common signature
> for decorators:

Ah, I missed to check the docs on config.add_view(). Yeah, the decorator
argument now does what I expect of the code.

The error was simple, default pyramid_jsonrpc "method not found" which
you get if you call an unregistered method, and the common_rpc()
decorator is the following:

    def common_rpc(f):
         def wrapped_rpc(*args, **kwargs):
             try:
                 return f(*args, **kwargs)
             except c.Invalid as e:
                 fields = e.asdict()
                 #log.debug(u"Invalid params: " + unicode(fields))
                 raise JsonRpcParamsInvalid(data=fields)
             except PermissionError as e:
                 raise JsonRpcError(code=e.code, message=e.message)
             except NotFoundError as e:
                 raise JsonRpcError(code=E_NOT_FOUND)

         return wrapped_rpc

Many thanks.

--

.oO V Oo.

Work Hard,
Increase Production,
Prevent Accidents,
and
Be Happy!  ;)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »