How to use the colander.SchemaNode 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 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 mazvv / travelcrm / travelcrm / forms / currencies.py View on Github external
def validator(node, value):
        currency = Currency.by_iso_code(value)
        if (
            currency
            and str(currency.id) != request.params.get('id')
        ):
            raise colander.Invalid(
                node,
                _(u'Currency with the same iso code exists'),
            )
    return colander.All(colander.Length(min=3, max=3), validator,)


class _CurrencySchema(ResourceSchema):
    iso_code = colander.SchemaNode(
        colander.String(),
        validator=iso_code_validator
    )


class CurrencyForm(BaseForm):
    _schema = _CurrencySchema

    def submit(self, currency=None):
        if not currency:
            currency = Currency(
                resource=CurrenciesResource.create_resource(
                    get_auth_employee(self.request)
                )
            )
        else:
github AppEnlight / appenlight / backend / src / appenlight / validators.py View on Github external
class LogSearchSchema(colander.MappingSchema):
    def schema_type(self, **kw):
        return colander.Mapping(unknown="preserve")

    resource = colander.SchemaNode(
        StringToAppList(),
        validator=possible_applications_validator,
        missing=possible_applications,
    )

    message = colander.SchemaNode(
        colander.Sequence(accept_scalar=True),
        colander.SchemaNode(colander.String()),
        missing=None,
    )
    level = colander.SchemaNode(
        colander.Sequence(accept_scalar=True),
        colander.SchemaNode(colander.String()),
        preparer=lowercase_preparer,
        missing=None,
    )
    namespace = colander.SchemaNode(
        colander.Sequence(accept_scalar=True),
        colander.SchemaNode(colander.String()),
        missing=None,
    )
    request_id = colander.SchemaNode(
        colander.Sequence(accept_scalar=True),
        colander.SchemaNode(colander.String()),
        missing=None,
    )
    start_date = colander.SchemaNode(PermissiveDate(), missing=None)
github mazvv / travelcrm / travelcrm / forms / campaigns.py View on Github external
class _SettingsSchema(colander.Schema):
    host = colander.SchemaNode(
        colander.String(),
    )
    port = colander.SchemaNode(
        colander.String(),
    )
    username = colander.SchemaNode(
        colander.String(),
    )
    password = colander.SchemaNode(
        colander.String(),
    )
    default_sender = colander.SchemaNode(
        colander.String(),
        validators=colander.All(colander.Email())
    )


class _CampaignCoverageSchema(ResourceSchema):
    person_category_id = colander.SchemaNode(
        SelectInteger(PersonCategory),
        missing=None,
    )
    tag_id = colander.SchemaNode(
        colander.Set(),
        missing=[],
    )

    def deserialize(self, cstruct):
github rcommande / papaye / papaye / evolve / evolve3.py View on Github external
class APIOtherRelease(colander.MappingSchema):
    url = colander.SchemaNode(colander.String())
    version = colander.SchemaNode(colander.String())


class APIOtherReleases(colander.SequenceSchema):
    other_releases = APIOtherRelease()


class APIReleaseFiles(colander.SequenceSchema):
    release_files = ReleaseFile()


class Metadata(colander.MappingSchema):
    version = colander.SchemaNode(String(), missing=None)
    author = colander.SchemaNode(String(), missing=None)
    author_email = colander.SchemaNode(String(), missing=None)
    home_page = colander.SchemaNode(String(), missing=None)
    keywords = colander.SchemaNode(Tags(), default=[])
    license = colander.SchemaNode(String(), missing=None)
    summary = colander.SchemaNode(String(), missing=None)
    maintainer = colander.SchemaNode(String(), missing=None)
    maintainer_email = colander.SchemaNode(String(), missing=None)
    description = colander.SchemaNode(Description(), default=None)
    platform = colander.SchemaNode(String(), missing=None)
    classifiers = colander.SchemaNode(Classifiers(), default=[])
    name = colander.SchemaNode(String(), missing=None)


class APIMetadata(colander.MappingSchema):
    version = colander.SchemaNode(String(), missing=None)
    author = colander.SchemaNode(String(), missing=None)
github wujian16 / Cornell-MOE / moe / views / schemas / gp_next_points_pretty_view.py View on Github external
missing=[],
            )


class GpNextPointsStatus(base_schemas.StrictMappingSchema):

    """A status schema for the various subclasses of :class:`moe.views.gp_next_points_pretty_view.GpNextPointsPrettyView`; e.g., :class:`moe.views.rest.gp_next_points_epi.GpNextPointsEpi`.

    **Output fields**

    :ivar expected_improvement: (*float64 >= 0.0*) EI evaluated at ``points_to_sample`` (:class:`moe.views.schemas.base_schemas.ListOfExpectedImprovements`)
    :ivar optimizer_success: (*dict*) Whether or not the optimizer converged to an optimal set of ``points_to_sample``

    """

    expected_improvement = colander.SchemaNode(
            colander.Float(),
            validator=colander.Range(min=0.0),
            )
    optimizer_success = colander.SchemaNode(
        colander.Mapping(unknown='preserve'),
        default={'found_update': False},
    )


class GpNextPointsResponse(base_schemas.StrictMappingSchema):

    """A response colander schema for the various subclasses of :class:`moe.views.gp_next_points_pretty_view.GpNextPointsPrettyView`; e.g., :class:`moe.views.rest.gp_next_points_epi.GpNextPointsEpi`.

    **Output fields**

    :ivar endpoint: (*str*) the endpoint that was called
github Kinto / kinto / kinto / views / permissions.py View on Github external
entries,
            filters=filters,
            sorting=sorting,
            id_field="uri",
            pagination_rules=pagination_rules,
            limit=limit,
        )


class PermissionsSchema(resource.ResourceSchema):
    uri = colander.SchemaNode(colander.String())
    resource_name = colander.SchemaNode(colander.String())
    permissions = colander.Sequence(colander.SchemaNode(colander.String()))
    bucket_id = colander.SchemaNode(colander.String())
    collection_id = colander.SchemaNode(colander.String(), missing=colander.drop)
    group_id = colander.SchemaNode(colander.String(), missing=colander.drop)
    record_id = colander.SchemaNode(colander.String(), missing=colander.drop)

    class Options:
        preserve_unknown = False


@resource.register(
    name="permissions",
    description="List of user permissions",
    plural_path="/permissions",
    object_path=None,
    plural_methods=("HEAD", "GET"),
)
class Permissions(resource.Resource):

    schema = PermissionsSchema
github stefanofontanelli / ColanderAlchemy / colanderalchemy / schema.py View on Github external
name_overrides_copy = overrides.get(name, {}).copy()

            if (isinstance(prop, ColumnProperty)
                    and isinstance(prop.columns[0], Column)):
                node = self.get_schema_from_column(
                    prop,
                    name_overrides_copy
                )
            elif isinstance(prop, RelationshipProperty):
                if prop.mapper.class_ in self.parents_ and name not in includes:
                    continue
                node = self.get_schema_from_relationship(
                    prop,
                    name_overrides_copy
                )
            elif isinstance(prop, colander.SchemaNode):
                node = prop
            else:
                log.debug(
                    'Attribute %s skipped due to not being '
                    'a ColumnProperty or RelationshipProperty',
                    name
                )
                continue

            if node is not None:
                self.add(node)
github NOAA-ORR-ERD / PyGnome / py_gnome / gnome / outputters / outputter.py View on Github external
"""
import os
import copy
from datetime import timedelta

from colander import SchemaNode, MappingSchema, Bool, drop


from gnome.persist import base_schema, extend_colander, validators
from gnome.utilities.serializable import Serializable, Field


class BaseSchema(base_schema.ObjType, MappingSchema):
    'Base schema for all outputters - they all contain the following'
    on = SchemaNode(Bool(), missing=drop)
    output_zero_step = SchemaNode(Bool())
    output_last_step = SchemaNode(Bool())
    output_timestep = SchemaNode(extend_colander.TimeDelta(), missing=drop)
    output_start_time = SchemaNode(extend_colander.LocalDateTime(),
                                   validator=validators.convertible_to_seconds,
                                   missing=None)


class Outputter(Serializable):
    '''
    base class for all outputters
    Since this outputter doesn't do anything, it'll never be used as part
    of a gnome model. As such, it should never need to be serialized
    '''
    _state = copy.deepcopy(Serializable._state)
    _state += (Field('on', save=True, update=True),
               Field('output_zero_step', save=True, update=True),
github rcommande / papaye / papaye / evolve / evolve1.py View on Github external
summary = colander.SchemaNode(colander.String(), missing=None)
    maintainer = colander.SchemaNode(colander.String(), missing=None)
    maintainer_email = colander.SchemaNode(colander.String(), missing=None)
    description = colander.SchemaNode(colander.String(), missing=None)
    platform = colander.SchemaNode(colander.String(), missing=None)
    classifiers = colander.SchemaNode(Classifiers(), missing=None)
    name = colander.SchemaNode(colander.String(), missing=None)


class APIMetadata(colander.MappingSchema):
    version = colander.SchemaNode(String(), missing=None)
    author = colander.SchemaNode(String(), missing=None)
    author_email = colander.SchemaNode(String(), missing=None)
    home_page = colander.SchemaNode(String(), missing=None)
    keywords = colander.SchemaNode(Tags(), default=[])
    license = colander.SchemaNode(String(), missing=None)
    summary = colander.SchemaNode(String(), missing=None)
    maintainer = colander.SchemaNode(String(), missing=None)
    maintainer_email = colander.SchemaNode(String(), missing=None)
    description = APIDescription()
    platform = colander.SchemaNode(colander.String(), missing=None)
    classifiers = colander.SchemaNode(Classifiers(), default=[])
    name = colander.SchemaNode(colander.String(), missing=None)


@load_model('papaye.evolve.models.snapshot1')
def evolve(root, config=None):
    context = context_from_root(root)
    repository = context.get('repository', tuple())
    schema = Metadata()

    for package_name in repository: