How to use colander - 10 common examples

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 Pylons / colander / colander / tests.py View on Github external
def _makeSchema(self, name='schema'):
        import colander

        integer = colander.SchemaNode(
            colander.Integer(),
            name='int',
            validator=colander.Range(0, 10)
            )

        ob = colander.SchemaNode(
            colander.GlobalObject(package=colander),
            name='ob',
            )

        tup = colander.SchemaNode(
            colander.Tuple(),
            colander.SchemaNode(
                colander.Integer(),
                name='tupint',
                ),
github stefanofontanelli / ColanderAlchemy / tests / test_schema.py View on Github external
def generate_colander():
            class User(colander.MappingSchema):
                id = colander.SchemaNode(colander.Integer(),
                                         missing=colander.drop)
                email = colander.SchemaNode(colander.String(),
                                            validator=colander.Email())
                second_email = colander.SchemaNode(colander.String(),
                                                   validator=colander.Email(),
                                                   missing=colander.null)

            return User()
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / websockets / test_schemas.py View on Github external
def test_deserialize_invalid_action(self):
        inst = self._make_one()
        with pytest.raises(colander.Invalid):
            inst.deserialize({'action': 'blah', 'resource': self.request.application_url + '/child'})
github Cornices / cornice / tests / validationapp.py View on Github external
    @foobar.post(schema=RequestSchema(), validators=(colander_validator,))
    def foobar_post(request):
        return {"test": "succeeded"}

    class StringSequence(SequenceSchema):
        _ = SchemaNode(String())

    class ListQuerystringSequence(MappingSchema):
        field = StringSequence()

        def deserialize(self, cstruct):
            if 'field' in cstruct and not isinstance(cstruct['field'], list):
                cstruct['field'] = [cstruct['field']]
            return MappingSchema.deserialize(self, cstruct)

    class QSSchema(MappingSchema):
        querystring = ListQuerystringSequence()


    @foobaz.get(schema=QSSchema(), validators=(colander_validator,))
    def foobaz_get(request):
        return {"field": request.validated['querystring']['field']}

    class NewsletterSchema(MappingSchema):
        email = SchemaNode(String(), validator=Email(), missing=drop)

    class RefererSchema(MappingSchema):
        ref = SchemaNode(Integer(), missing=drop)

    class NewsletterPayload(MappingSchema):
        body = NewsletterSchema()
        querystring = RefererSchema()
github Pylons / colander / colander / tests.py View on Github external
def test_deserialize_null(self):
        import colander
        typ = self._makeOne()
        node = DummySchemaNode(None)
        result = typ.deserialize(node, colander.null)
        self.assertEqual(result, colander.null)
github Pylons / colander / colander / tests.py View on Github external
def _makeOne(self, min=None, max=None):
        from colander import Length
        return Length(min=min, max=max)
github chrisrossi / limone / limone / tests.py View on Github external
def setUp(self):
        import colander
        import limone

        class NSAData(colander.Schema):
            serialnum = colander.SchemaNode(colander.Str('UTF-8'))
            date_of_contact = colander.SchemaNode(colander.Date())

        class PersonalData(colander.Schema):
            nsa_data = NSAData()
            n_arrests = colander.SchemaNode(colander.Int())

        class PersonSchema(colander.Schema):
            name = colander.SchemaNode(colander.Str('UTF-8'))
            age = colander.SchemaNode(colander.Integer(), default=500)
            personal = PersonalData()

        self.content_type = limone.make_content_type(PersonSchema, 'Person')
github Pylons / colander / colander / tests.py View on Github external
def _makeOne(self, wrapped):
        from colander import deferred
        return deferred(wrapped)
github Cornices / cornice.ext.swagger / tests / converters / test_schema.py View on Github external
def schema_type():
                return colander.Mapping(unknown='preserve')
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / sheets / test_init.py View on Github external
def sheet_meta(sheet_meta):
    from adhocracy_core.sheets import AnnotationStorageSheet
    from adhocracy_core.interfaces import ISheet
    class SheetASchema(colander.MappingSchema):
        count = colander.SchemaNode(colander.Int(),
                                    missing=colander.drop,
                                    default=0)
    meta = sheet_meta._replace(isheet=ISheet,
                               schema_class=SheetASchema,
                               sheet_class=AnnotationStorageSheet,
                               readable=True,
                               editable=True,
                               creatable=True)
    return meta