prpc.method_locator¶
Method locator interface, default implementation and support tools.
Note
While locator is not strictly required abstraction, it is created
to factor this code out of already complicated
Connection
class.
-
prpc.method_locator.
method
(*args, expand_args=True)¶ Mark function as an public RPC method and optionally apply decorators.
May be uses both with and without arguments, e.g.:
@prpc.method async def foo(ctx, arg1, arg2): "Args are expanded to fit the signature." @prpc.method(expand_args=False) async def bar(ctx): "All args are passed in ctx object."
Can be applied to instance/class methods:
class Service(object): @prpc.method async def foo(self, ctx): "Works fine."
-
class
prpc.method_locator.
AbstractMethodLocator
¶ Method locator interface definition.
-
resolve
(method_name, call_type, connection)¶ Resolve a method given call context.
Parameters: - method_name – Method name as a string.
- call_type – Call type (unary, istream, etc).
- connection – Connection object related.
Returns: method as an async callable expecting a single argument (CallContext)
-
-
class
prpc.method_locator.
TreeMethodLocator
(methods, collect_all=False, separator=’.’)¶ Default method locator implementation.
Allows to use multiple objects and free functions as united ‘RPC service’.
- Allowed method formats (foo - function, obj - object instance):
- foo
- obj
- {“func_name”: foo, “service_name”: obj}
- {“group_name”: dict}
Note
By default, only methods marked by
method()
decorator are exposed.-
_decorate_method
(method)¶ Decorate found method (hook for subclasses).
-
resolve
(method_name, call_type, connection)¶ Resolve implementation, see
AbstractMethodLocator
.