How to use the colander.Sequence function in colander

To help you get started, we’ve selected a few colander examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NOAA-ORR-ERD / PyGnome / py_gnome / gnome / environment / grid_property.py View on Github external
def __init__(self, json_='webapi', *args, **kwargs):
        if json_ == 'save':
            self.add(SchemaNode(typ=Sequence(), children=[SchemaNode(EnvProp())], name='variables'))
        super(GridVectorPropSchema, self).__init__(*args, **kwargs)
github chrisrossi / limone / limone / __init__.py View on Github external
def __init__(self):
        self.registry = {
            colander.Mapping: _MappingNodeProperty,
            colander.Sequence: _SequenceNodeProperty,
            colander.Tuple: _TupleNodeProperty,
            colander.SchemaType: _LeafNodeProperty,
        }
github Pylons / deform / deform / widget.py View on Github external
appstruct = appstruct.strip()
        return appstruct


class _FieldStorage(SchemaType):
    def deserialize(self, node, cstruct):
        if cstruct in (null, None, b""):
            return null
        # weak attempt at duck-typing
        if not hasattr(cstruct, "file"):
            raise Invalid(node, "%s is not a FieldStorage instance" % cstruct)
        return cstruct


_sequence_of_strings = SchemaNode(
    Sequence(), SchemaNode(_PossiblyEmptyString())
)


class Widget(object):
    """
    A widget is the building block for rendering logic.  The
    :class:`deform.widget.Widget` class is never instantiated
    directly: it is the abstract class from which all other widget
    types within :mod:`deform.widget` derive.  It should likely also
    be subclassed by application-developer-defined widgets.

    A widget instance is attached to a field during normal operation.
    A widget is not meant to carry any state.  Instead, widget
    implementations should use the ``field`` object passed to them
    during :meth:`deform.widget.Widget.serialize` and
    :meth:`deform.widget.Widget.deserialize` as a scratchpad for state
github voidfiles / lark / lark / redis / schemas.py View on Github external
InfotypeKeyScheam = LarkSchemaNode(LarkMappingSchema())
node(InfotypeKeyScheam, lark_string, name='infotype')
node(InfotypeKeyScheam, name_ref_type, name='key')


NameSchema = LarkSchemaNode(LarkMappingSchema())
node(NameSchema, name_ref_type, name='name')


class NamesSchemaNode(LarkSchemaNode):
    def signature_from_cstruct(self, cstruct, redis_args, redis_kwargs):
        return (cstruct['name'], {})


NamesSchema = NamesSchemaNode(LarkMappingSchema())
NamesSchema.add(LarkSchemaNode(colander.Sequence(accept_scalar=True), LarkSchemaNode(name_ref_type), name='name'))


PatternSchema = LarkSchemaNode(LarkMappingSchema())
node(PatternSchema, name_ref_type, name='pattern', missing='*')

KeySchema = LarkSchemaNode(LarkMappingSchema())
node(KeySchema, name_ref_type, name='key')


class KeySchemaNode(LarkSchemaNode):

    def signature_from_cstruct(self, cstruct, redis_args, redis_kwargs):
        return (cstruct['key'], {})


KeysSchema = KeySchemaNode(LarkMappingSchema())
github NLeSC / MAGMa / web / magmaweb / jobquery.py View on Github external
'phase1',
            'phase1_selected',
            'phase2',
            'phase2_selected',
            'glycosidase',
            'mass_filter',
            'gut'])

        scenario.add(colander.SchemaNode(colander.String(),
                                         name='type',
                                         validator=transformation_types))
        # TODO add validator for steps, but what are valid options for steps?
        scenario.add(colander.SchemaNode(colander.String(),
                                         name='steps'))

        schema.add(colander.SchemaNode(colander.Sequence(),
                                       scenario,
                                       validator=colander.Length(1),
                                       name='scenario'))
github NOAA-ORR-ERD / PyGnome / py_gnome / gnome / persist / extend_colander.py View on Github external
appstruct['value'].tolist())

        return super(DatetimeValue2dArray, self).serialize(node, series)

    def deserialize(self, node, cstruct):
        if cstruct is null:
            return null

        items = (super(DatetimeValue2dArray, self)
                 .deserialize(node, cstruct, accept_scalar=False))
        timeseries = np.array(items, dtype=gnome.basic_types.datetime_value_2d)

        return timeseries  # validator requires numpy array


class DatetimeValue1dArray(Sequence):
    """
    A subclass of :class:`colander.Sequence` that converts itself to a numpy
    array using :class:`gnome.basic_types.datetime_value_2d` as the data type.
    """
    def serialize(self, node, appstruct):
        if appstruct is null:  # colander.null
            return null

        appstruct = zip(appstruct['time'].astype(object), appstruct['value'])

        return super(DatetimeValue1dArray, self).serialize(node, appstruct)

    def deserialize(self, node, cstruct):
        if cstruct is null:
            return null
github fedora-infra / bodhi / bodhi / server / schemas.py View on Github external
nvr = colander.SchemaNode(
        colander.String(),
        location="querystring",
        missing=None,
    )

    packages = Packages(
        colander.Sequence(accept_scalar=True),
        location="querystring",
        missing=None,
        preparer=[util.splitter],
    )

    releases = Releases(
        colander.Sequence(accept_scalar=True),
        location="querystring",
        missing=None,
        preparer=[util.splitter],
    )

    updates = Updates(
        colander.Sequence(accept_scalar=True),
        location="querystring",
        missing=None,
        preparer=[util.splitter],
    )


class UpdateRequestSchema(CSRFProtectedSchema, colander.MappingSchema):
    """An API schema for bodhi.server.services.updates.set_request()."""
github Kinto / kinto / kinto / core / resource / schema.py View on Github external
def _get_node_principals(self, perm):
        principal = colander.SchemaNode(colander.String())
        return colander.SchemaNode(
            colander.Sequence(), principal, name=perm, missing=colander.drop
        )
github paasmaker / paasmaker / paasmaker / common / application / configuration.py View on Github external
description="A section describing the runtime plugin name and version for this instance."
	)
	startup = Prepares(
		title="Startup tasks",
		description="A list of plugins and parameters to run on instance startup.",
		default=[],
		missing=[]
	)
	placement = PlacementPlugin(
		title="Placement information",
		description="A section that provides hints to Paasmaker about where to place your application.",
		default=PlacementPlugin.default(),
		missing=PlacementPlugin.default()
	)
	hostnames = colander.SchemaNode(
		colander.Sequence(),
		colander.SchemaNode(colander.String()),
		title="Hostnames",
		description="A set of public hostnames that this instance will have if it is the current version of the application.",
		default=[],
		missing=[]
	)
	exclusive = colander.SchemaNode(
		colander.Boolean(),
		title="Version Exclusive",
		description="If set to true, only one version of this instance type will run at a time. This is good for background workers that you don't want overlapping.",
		default=False,
		missing=False)
	standalone = colander.SchemaNode(
		colander.Boolean(),
		title="Standalone",
		description="If true, this instance doesn't require a TCP port. Affects the startup of the application.",
github voidfiles / lark / lark / redis / schemas.py View on Github external
node(CursorMatchCountSchema, int_type, name='cursor')
node(CursorMatchCountSchema, name_ref_type, name='match')
node(CursorMatchCountSchema, int_type, name='count')


NameCursorMatchCountSchema = LarkSchemaNode(LarkMappingSchema())
node(NameCursorMatchCountSchema, name_ref_type, name='name')
node(NameCursorMatchCountSchema, int_type, name='cursor')
node(NameCursorMatchCountSchema, lark_string, name='match')
node(NameCursorMatchCountSchema, int_type, name='count')


BitOpSchema = LarkSchemaNode(LarkMappingSchema())
node(BitOpSchema, lark_string, name='operation')
node(BitOpSchema, name_ref_type, name='destkey')
BitOpSchema.add(LarkSchemaNode(colander.Sequence(), LarkSchemaNode(name_ref_type), name='key'))


NameTtlValueSchema = LarkSchemaNode(LarkMappingSchema())
node(NameTtlValueSchema, name_ref_type, name='name')
node(NameTtlValueSchema, int_type, name='ttl')
node(NameTtlValueSchema, value_type, name='key')


NameNumberSchema = LarkSchemaNode(LarkMappingSchema())
node(NameNumberSchema, name_ref_type, name='name')
node(NameNumberSchema, lark_string, name='number', missing=None)


NameMinMaxSchema = LarkSchemaNode(LarkMappingSchema())
node(NameMinMaxSchema, name_ref_type, name='name')
node(NameMinMaxSchema, lark_string, name='min')