#NEWLINE# def jrpc( signature , describe = True , summary = None , idempotent = False , docs = None ) : #NEWLINE# #INDENT# "\n    Use to wrap methods that belong to a ``service.JSONRPCService``. Methods\n    which are wrapped in this decorator will be added to the service for access\n    via JSON-RPC.\n\n    Usage::\n\n        # Inside of ``JSONRPCService`` sub-class\n        @jrpc('get_sum(a=<num>, b=<num>?) -> <num>')\n            def named_whatevs(self, a, b=1):\n                return a + b\n\n    " #NEWLINE# if callable ( signature ) : #NEWLINE# #INDENT# raise TypeError ( 'The ``jrpc`` decorator must be provided with a method signature' ) #NEWLINE# #UNINDENT# def decorator( method ) : #NEWLINE# #INDENT# '\n        Adds a ``rpc_method_name`` attribute to methods decorated, giving\n        the method json-rpc method name (this is used by ``JSONRPCServiceMeta``\n        to register this method as a supported method. This requires a\n        ``JSONRPCService`` to register available methods on class creation,\n        instead of instantiation. Use ``describe=False`` to hide a method from\n        the service description.\n        ' #NEWLINE# method . rpc_method_name = name_from_signature ( signature ) #NEWLINE# method . rpc_params = [ { #NEWLINE# #INDENT# 'name' : p [ 0 ] , #NEWLINE# 'type' : p [ 1 ] , #NEWLINE# 'optional' : p [ 2 ] , #NEWLINE# #UNINDENT# } for p in params_from_signature ( signature ) ] #NEWLINE# method . describe = describe #NEWLINE# method . return_type = return_type_from_signature ( signature ) #NEWLINE# method . description = { #NEWLINE# #INDENT# 'name' : method . rpc_method_name , #NEWLINE# 'summary' : summary , #NEWLINE# 'help' : docs , #NEWLINE# 'idempotent' : idempotent , #NEWLINE# 'params' : method . rpc_params , #NEWLINE# 'return' : method . return_type , #NEWLINE# #UNINDENT# } #NEWLINE# @ wraps ( method ) #NEWLINE# def wrapper( * args , **kwargs ) : #NEWLINE# #INDENT# '\n            Returns the value returned by calling the actual method.\n            ' #NEWLINE# return method ( * args , ** kwargs ) #NEWLINE# #UNINDENT# return wrapper #NEWLINE# #UNINDENT# return decorator