Refactor to actually use new helpers
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from .capnp.includes.capnp_cpp cimport Maybe, DynamicStruct, Request, PyPromise, VoidPromise, RemotePromise, DynamicCapability, InterfaceSchema, EnumSchema, StructSchema, DynamicValue, Capability, RpcSystem, MessageBuilder, MessageReader, TwoPartyVatNetwork
|
from .capnp.includes.capnp_cpp cimport Maybe, DynamicStruct, Request, PyPromise, VoidPromise, RemotePromise, DynamicCapability, InterfaceSchema, EnumSchema, StructSchema, DynamicValue, Capability, RpcSystem, MessageBuilder, MessageReader, TwoPartyVatNetwork, PyRestorer
|
||||||
|
|
||||||
from non_circular cimport reraise_kj_exception
|
from non_circular cimport reraise_kj_exception
|
||||||
|
|
||||||
@@ -22,8 +22,6 @@ cdef extern from "../helpers/capabilityHelper.h":
|
|||||||
PyPromise convert_to_pypromise(RemotePromise&)
|
PyPromise convert_to_pypromise(RemotePromise&)
|
||||||
|
|
||||||
cdef extern from "../helpers/rpcHelper.h":
|
cdef extern from "../helpers/rpcHelper.h":
|
||||||
cdef cppclass PyRestorer:
|
|
||||||
PyRestorer(PyObject *, StructSchema&)
|
|
||||||
Capability.Client restoreHelper(RpcSystem&, MessageBuilder&)
|
Capability.Client restoreHelper(RpcSystem&, MessageBuilder&)
|
||||||
Capability.Client restoreHelper(RpcSystem&, MessageReader&)
|
Capability.Client restoreHelper(RpcSystem&, MessageReader&)
|
||||||
RpcSystem makeRpcClientWithRestorer(TwoPartyVatNetwork&, PyRestorer&)
|
RpcSystem makeRpcClientWithRestorer(TwoPartyVatNetwork&, PyRestorer&)
|
||||||
|
|||||||
@@ -215,6 +215,10 @@ cdef extern from "capnp/capability.h" namespace " ::capnp":
|
|||||||
Client(Client&)
|
Client(Client&)
|
||||||
DynamicCapability.Client castAs"castAs< ::capnp::DynamicCapability>"(InterfaceSchema)
|
DynamicCapability.Client castAs"castAs< ::capnp::DynamicCapability>"(InterfaceSchema)
|
||||||
|
|
||||||
|
cdef extern from "../helpers/rpcHelper.h":
|
||||||
|
cdef cppclass PyRestorer:
|
||||||
|
PyRestorer(PyObject *, StructSchema&)
|
||||||
|
|
||||||
cdef extern from "capnp/rpc-twoparty.h" namespace " ::capnp":
|
cdef extern from "capnp/rpc-twoparty.h" namespace " ::capnp":
|
||||||
cdef cppclass RpcSystem" ::capnp::RpcSystem<capnp::rpc::twoparty::SturdyRefHostId>":
|
cdef cppclass RpcSystem" ::capnp::RpcSystem<capnp::rpc::twoparty::SturdyRefHostId>":
|
||||||
RpcSystem(RpcSystem&&)
|
RpcSystem(RpcSystem&&)
|
||||||
@@ -249,30 +253,6 @@ cdef extern from "capnp/any.h" namespace " ::capnp":
|
|||||||
Builder(Builder)
|
Builder(Builder)
|
||||||
DynamicStruct.Builder getAs"getAs< ::capnp::DynamicStruct>"(StructSchema)
|
DynamicStruct.Builder getAs"getAs< ::capnp::DynamicStruct>"(StructSchema)
|
||||||
|
|
||||||
cdef extern from "../helpers/fixMaybe.h":
|
|
||||||
EnumSchema.Enumerant fixMaybe(Maybe[EnumSchema.Enumerant]) except +reraise_kj_exception
|
|
||||||
char * getEnumString(DynamicStruct.Reader val)
|
|
||||||
char * getEnumString(DynamicStruct.Builder val)
|
|
||||||
char * getEnumString(Request val)
|
|
||||||
|
|
||||||
cdef extern from "../helpers/capabilityHelper.h":
|
|
||||||
# PyPromise evalLater(EventLoop &, PyObject * func)
|
|
||||||
# PyPromise there(EventLoop & loop, PyPromise & promise, PyObject * func, PyObject * error_func)
|
|
||||||
PyPromise then(PyPromise & promise, PyObject * func, PyObject * error_func)
|
|
||||||
VoidPromise then(RemotePromise & promise, PyObject * func, PyObject * error_func)
|
|
||||||
PyPromise then(VoidPromise & promise, PyObject * func, PyObject * error_func)
|
|
||||||
DynamicCapability.Client new_client(InterfaceSchema&, PyObject *)
|
|
||||||
DynamicValueForward.Reader new_server(InterfaceSchema&, PyObject *)
|
|
||||||
Capability.Client server_to_client(InterfaceSchema&, PyObject *)
|
|
||||||
PyPromise convert_to_pypromise(RemotePromise&)
|
|
||||||
|
|
||||||
cdef extern from "../helpers/rpcHelper.h":
|
|
||||||
cdef cppclass PyRestorer:
|
|
||||||
PyRestorer(PyObject *, StructSchema&)
|
|
||||||
Capability.Client restoreHelper(RpcSystem&, MessageBuilder&)
|
|
||||||
Capability.Client restoreHelper(RpcSystem&, MessageReader&)
|
|
||||||
RpcSystem makeRpcClientWithRestorer(TwoPartyVatNetwork&, PyRestorer&)
|
|
||||||
|
|
||||||
cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
||||||
cdef cppclass DynamicEnum:
|
cdef cppclass DynamicEnum:
|
||||||
uint16_t getRaw()
|
uint16_t getRaw()
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
from .capnp.includes cimport capnp_cpp as capnp
|
from .capnp.includes cimport capnp_cpp as capnp
|
||||||
from .capnp.includes cimport schema_cpp
|
from .capnp.includes cimport schema_cpp
|
||||||
from .capnp.includes.capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, InterfaceSchema as C_InterfaceSchema, DynamicStruct as C_DynamicStruct, DynamicValue as C_DynamicValue, Type as C_Type, DynamicList as C_DynamicList, fixMaybe, getEnumString, SchemaParser as C_SchemaParser, ParsedSchema as C_ParsedSchema, VOID, ArrayPtr, StringPtr, String, StringTree, DynamicOrphan as C_DynamicOrphan, AnyPointer as C_DynamicObject, DynamicCapability as C_DynamicCapability, new_client, new_server, server_to_client, Request, Response, RemotePromise, convert_to_pypromise, PyPromise, VoidPromise, CallContext, PyRestorer, RpcSystem, makeRpcServer, makeRpcClient, restoreHelper, Capability as C_Capability, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own, makeTwoPartyVatNetwork, PromiseFulfillerPair as C_PromiseFulfillerPair, copyPromiseFulfillerPair, newPromiseAndFulfiller, reraise_kj_exception
|
from .capnp.includes.capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, InterfaceSchema as C_InterfaceSchema, DynamicStruct as C_DynamicStruct, DynamicValue as C_DynamicValue, Type as C_Type, DynamicList as C_DynamicList, SchemaParser as C_SchemaParser, ParsedSchema as C_ParsedSchema, VOID, ArrayPtr, StringPtr, String, StringTree, DynamicOrphan as C_DynamicOrphan, AnyPointer as C_DynamicObject, DynamicCapability as C_DynamicCapability, Request, Response, RemotePromise, PyPromise, VoidPromise, CallContext, PyRestorer, RpcSystem, makeRpcServer, makeRpcClient, Capability as C_Capability, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own, makeTwoPartyVatNetwork, PromiseFulfillerPair as C_PromiseFulfillerPair, copyPromiseFulfillerPair, newPromiseAndFulfiller
|
||||||
from .capnp.includes.schema_cpp cimport Node as C_Node, EnumNode as C_EnumNode
|
from .capnp.includes.schema_cpp cimport Node as C_Node, EnumNode as C_EnumNode
|
||||||
from .capnp.includes.types cimport *
|
from .capnp.includes.types cimport *
|
||||||
|
from .capnp.helpers.non_circular cimport reraise_kj_exception
|
||||||
|
from .capnp.helpers cimport helpers
|
||||||
|
|
||||||
cdef class _DynamicStructReader:
|
cdef class _DynamicStructReader:
|
||||||
cdef C_DynamicStruct.Reader thisptr
|
cdef C_DynamicStruct.Reader thisptr
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ cdef public C_Capability.Client * call_py_restorer(PyObject * _restorer, C_Dynam
|
|||||||
ret = restorer.restore(reader)
|
ret = restorer.restore(reader)
|
||||||
cdef _DynamicCapabilityServer server = ret
|
cdef _DynamicCapabilityServer server = ret
|
||||||
|
|
||||||
return new C_Capability.Client(server_to_client(server.schema.thisptr, <PyObject *>server.server))
|
return new C_Capability.Client(helpers.server_to_client(server.schema.thisptr, <PyObject *>server.server))
|
||||||
|
|
||||||
cdef extern from "<kj/string.h>" namespace " ::kj":
|
cdef extern from "<kj/string.h>" namespace " ::kj":
|
||||||
String strStructReader" ::kj::str"(C_DynamicStruct.Reader)
|
String strStructReader" ::kj::str"(C_DynamicStruct.Reader)
|
||||||
@@ -544,7 +544,7 @@ cdef to_python_reader(C_DynamicValue.Reader self, object parent):
|
|||||||
elif type == capnp.TYPE_STRUCT:
|
elif type == capnp.TYPE_STRUCT:
|
||||||
return _DynamicStructReader()._init(self.asStruct(), parent)
|
return _DynamicStructReader()._init(self.asStruct(), parent)
|
||||||
elif type == capnp.TYPE_ENUM:
|
elif type == capnp.TYPE_ENUM:
|
||||||
return <char*>fixMaybe(self.asEnum().getEnumerant()).getProto().getName().cStr()
|
return <char*>helpers.fixMaybe(self.asEnum().getEnumerant()).getProto().getName().cStr()
|
||||||
elif type == capnp.TYPE_VOID:
|
elif type == capnp.TYPE_VOID:
|
||||||
return None
|
return None
|
||||||
elif type == capnp.TYPE_ANY_POINTER:
|
elif type == capnp.TYPE_ANY_POINTER:
|
||||||
@@ -576,7 +576,7 @@ cdef to_python_builder(C_DynamicValue.Builder self, object parent):
|
|||||||
elif type == capnp.TYPE_STRUCT:
|
elif type == capnp.TYPE_STRUCT:
|
||||||
return _DynamicStructBuilder()._init(self.asStruct(), parent)
|
return _DynamicStructBuilder()._init(self.asStruct(), parent)
|
||||||
elif type == capnp.TYPE_ENUM:
|
elif type == capnp.TYPE_ENUM:
|
||||||
return <char*>fixMaybe(self.asEnum().getEnumerant()).getProto().getName().cStr()
|
return <char*>helpers.fixMaybe(self.asEnum().getEnumerant()).getProto().getName().cStr()
|
||||||
elif type == capnp.TYPE_VOID:
|
elif type == capnp.TYPE_VOID:
|
||||||
return None
|
return None
|
||||||
elif type == capnp.TYPE_ANY_POINTER:
|
elif type == capnp.TYPE_ANY_POINTER:
|
||||||
@@ -598,7 +598,7 @@ cdef C_DynamicValue.Reader _extract_dynamic_client(_DynamicCapabilityClient valu
|
|||||||
return C_DynamicValue.Reader(value.thisptr)
|
return C_DynamicValue.Reader(value.thisptr)
|
||||||
|
|
||||||
cdef C_DynamicValue.Reader _extract_dynamic_server(_DynamicCapabilityServer value):
|
cdef C_DynamicValue.Reader _extract_dynamic_server(_DynamicCapabilityServer value):
|
||||||
return new_server(value.schema.thisptr, <PyObject *>value.server)
|
return helpers.new_server(value.schema.thisptr, <PyObject *>value.server)
|
||||||
|
|
||||||
cdef _setDynamicField(_DynamicSetterClasses thisptr, field, value, parent):
|
cdef _setDynamicField(_DynamicSetterClasses thisptr, field, value, parent):
|
||||||
cdef C_DynamicValue.Reader temp
|
cdef C_DynamicValue.Reader temp
|
||||||
@@ -765,7 +765,7 @@ cdef class _DynamicStructReader:
|
|||||||
|
|
||||||
:Raises: :exc:`exceptions.ValueError` if this struct doesn't contain a union
|
:Raises: :exc:`exceptions.ValueError` if this struct doesn't contain a union
|
||||||
"""
|
"""
|
||||||
cdef object which = <char*>getEnumString(self.thisptr)
|
cdef object which = <char*>helpers.getEnumString(self.thisptr)
|
||||||
if len(which) == 0:
|
if len(which) == 0:
|
||||||
raise ValueError("Attempted to call which on a non-union type")
|
raise ValueError("Attempted to call which on a non-union type")
|
||||||
|
|
||||||
@@ -953,7 +953,7 @@ cdef class _DynamicStructBuilder:
|
|||||||
|
|
||||||
:Raises: :exc:`exceptions.ValueError` if this struct doesn't contain a union
|
:Raises: :exc:`exceptions.ValueError` if this struct doesn't contain a union
|
||||||
"""
|
"""
|
||||||
cdef object which = <char*>getEnumString(self.thisptr)
|
cdef object which = <char*>helpers.getEnumString(self.thisptr)
|
||||||
if len(which) == 0:
|
if len(which) == 0:
|
||||||
raise ValueError("Attempted to call which on a non-union type")
|
raise ValueError("Attempted to call which on a non-union type")
|
||||||
|
|
||||||
@@ -1220,7 +1220,7 @@ cdef class _Promise:
|
|||||||
Py_INCREF(func)
|
Py_INCREF(func)
|
||||||
Py_INCREF(error_func)
|
Py_INCREF(error_func)
|
||||||
|
|
||||||
return _Promise()._init(capnp.then(deref(self.thisptr), <PyObject *>func, <PyObject *>error_func))
|
return _Promise()._init(helpers.then(deref(self.thisptr), <PyObject *>func, <PyObject *>error_func))
|
||||||
|
|
||||||
cdef class _VoidPromise:
|
cdef class _VoidPromise:
|
||||||
cdef VoidPromise * thisptr
|
cdef VoidPromise * thisptr
|
||||||
@@ -1252,7 +1252,7 @@ cdef class _VoidPromise:
|
|||||||
Py_INCREF(func)
|
Py_INCREF(func)
|
||||||
Py_INCREF(error_func)
|
Py_INCREF(error_func)
|
||||||
|
|
||||||
return _Promise()._init(capnp.then(deref(self.thisptr), <PyObject *>func, <PyObject *>error_func))
|
return _Promise()._init(helpers.then(deref(self.thisptr), <PyObject *>func, <PyObject *>error_func))
|
||||||
|
|
||||||
cdef class _RemotePromise:
|
cdef class _RemotePromise:
|
||||||
cdef RemotePromise * thisptr
|
cdef RemotePromise * thisptr
|
||||||
@@ -1281,7 +1281,7 @@ cdef class _RemotePromise:
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
cpdef as_pypromise(self) except +reraise_kj_exception:
|
cpdef as_pypromise(self) except +reraise_kj_exception:
|
||||||
_Promise()._init(convert_to_pypromise(deref(self.thisptr)))
|
_Promise()._init(helpers.convert_to_pypromise(deref(self.thisptr)))
|
||||||
|
|
||||||
cpdef then(self, func, error_func=None) except +reraise_kj_exception:
|
cpdef then(self, func, error_func=None) except +reraise_kj_exception:
|
||||||
if self.is_consumed:
|
if self.is_consumed:
|
||||||
@@ -1290,7 +1290,7 @@ cdef class _RemotePromise:
|
|||||||
Py_INCREF(func)
|
Py_INCREF(func)
|
||||||
Py_INCREF(error_func)
|
Py_INCREF(error_func)
|
||||||
|
|
||||||
return _VoidPromise()._init(capnp.then(deref(self.thisptr), <PyObject *>func, <PyObject *>error_func))
|
return _VoidPromise()._init(helpers.then(deref(self.thisptr), <PyObject *>func, <PyObject *>error_func))
|
||||||
|
|
||||||
cpdef _get(self, field) except +reraise_kj_exception:
|
cpdef _get(self, field) except +reraise_kj_exception:
|
||||||
cdef int type = (<C_DynamicValue.Pipeline>self.thisptr.get(field)).getType()
|
cdef int type = (<C_DynamicValue.Pipeline>self.thisptr.get(field)).getType()
|
||||||
@@ -1371,7 +1371,7 @@ cdef class _DynamicCapabilityClient:
|
|||||||
else:
|
else:
|
||||||
s = schema
|
s = schema
|
||||||
|
|
||||||
self.thisptr = new_client(s.thisptr, <PyObject *>server)
|
self.thisptr = helpers.new_client(s.thisptr, <PyObject *>server)
|
||||||
self._server = server
|
self._server = server
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@@ -1536,9 +1536,9 @@ cdef class RpcClient:
|
|||||||
reader = objectId._parent
|
reader = objectId._parent
|
||||||
|
|
||||||
if builder is not None:
|
if builder is not None:
|
||||||
return _CapabilityClient()._init(restoreHelper(deref(self.thisptr), deref(builder.thisptr)), self)
|
return _CapabilityClient()._init(helpers.restoreHelper(deref(self.thisptr), deref(builder.thisptr)), self)
|
||||||
elif reader is not None:
|
elif reader is not None:
|
||||||
return _CapabilityClient()._init(restoreHelper(deref(self.thisptr), deref(reader.thisptr)), self)
|
return _CapabilityClient()._init(helpers.restoreHelper(deref(self.thisptr), deref(reader.thisptr)), self)
|
||||||
else:
|
else:
|
||||||
raise ValueError("objectId unexpectedly was not convertible to the proper type")
|
raise ValueError("objectId unexpectedly was not convertible to the proper type")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user