Add ListSchema class
Return it whenever the appropriate Type is converted to a Schema
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from capnp.includes cimport capnp_cpp as capnp
|
||||
from capnp.includes cimport schema_cpp
|
||||
from capnp.includes.capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, InterfaceSchema as C_InterfaceSchema, EnumSchema as C_EnumSchema, 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, PyArray, DynamicStruct_Builder
|
||||
from capnp.includes.capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, InterfaceSchema as C_InterfaceSchema, EnumSchema as C_EnumSchema, ListSchema as C_ListSchema, 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, PyArray, DynamicStruct_Builder
|
||||
from capnp.includes.schema_cpp cimport Node as C_Node, EnumNode as C_EnumNode
|
||||
from capnp.includes.types cimport *
|
||||
from capnp.helpers.non_circular cimport reraise_kj_exception
|
||||
|
||||
@@ -2419,6 +2419,19 @@ cdef class _StructSchema:
|
||||
def __repr__(self):
|
||||
return '<schema for %s>' % self.node.displayName
|
||||
|
||||
cdef typeAsSchema(capnp.SchemaType fieldType):
|
||||
# TODO(soon): make sure this is memory safe
|
||||
if fieldType.isInterface():
|
||||
return _InterfaceSchema()._init(fieldType.asInterface())
|
||||
elif fieldType.isStruct():
|
||||
return _StructSchema()._init(fieldType.asStruct())
|
||||
elif fieldType.isEnum():
|
||||
return _EnumSchema()._init(fieldType.asEnum())
|
||||
elif fieldType.isList():
|
||||
return ListSchema()._init(fieldType.asList())
|
||||
else:
|
||||
raise ValueError("Schema type is unknown")
|
||||
|
||||
cdef class _StructSchemaField:
|
||||
cdef _init(self, C_StructSchema.Field other, parent=None):
|
||||
self.thisptr = other
|
||||
@@ -2433,17 +2446,7 @@ cdef class _StructSchemaField:
|
||||
property schema:
|
||||
"""The schema of this field, or None if it's a type without a schema"""
|
||||
def __get__(self):
|
||||
cdef capnp.SchemaType fieldType = self.thisptr.getType()
|
||||
|
||||
# TODO(soon): make sure this is memory safe
|
||||
if fieldType.isInterface():
|
||||
return _InterfaceSchema()._init(fieldType.asInterface())
|
||||
elif fieldType.isStruct():
|
||||
return _StructSchema()._init(fieldType.asStruct())
|
||||
elif fieldType.isEnum():
|
||||
return _EnumSchema()._init(fieldType.asEnum())
|
||||
else:
|
||||
return None
|
||||
return typeAsSchema(self.thisptr.getType())
|
||||
|
||||
def __repr__(self):
|
||||
return '<field schema for %s>' % self.proto.name
|
||||
@@ -2563,6 +2566,18 @@ cdef class _EnumSchema:
|
||||
def __get__(self):
|
||||
return _DynamicStructReader()._init(self.thisptr.getProto(), self)
|
||||
|
||||
cdef class ListSchema:
|
||||
cdef C_ListSchema thisptr
|
||||
|
||||
cdef _init(self, C_ListSchema other):
|
||||
self.thisptr = other
|
||||
return self
|
||||
|
||||
property elementType:
|
||||
"""The schema of the element type of this list"""
|
||||
def __get__(self):
|
||||
return typeAsSchema(self.thisptr.getElementType())
|
||||
|
||||
cdef class _ParsedSchema(_Schema):
|
||||
cdef C_ParsedSchema thisptr_child
|
||||
cdef _init_child(self, C_ParsedSchema other):
|
||||
|
||||
Reference in New Issue
Block a user