How to use the colander.Int 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 liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / rest / test_views.py View on Github external
def test_get_sheets_with_field(self, request_, context, sheet_meta):
        class SchemaF(colander.MappingSchema):
            test = colander.SchemaNode(colander.Int())
        sheet_meta = sheet_meta._replace(schema_class=SchemaF)
        request_.registry.content.sheets_meta[ISheet] = sheet_meta
        inst = self.make_one(request_, context)

        response = inst.get()['sheets'][ISheet.__identifier__]

        assert len(response['fields']) == 1
        field_metadata = response['fields'][0]
        assert field_metadata['create_mandatory'] is False
        assert field_metadata['readable'] is True
        assert field_metadata['editable'] is True
        assert field_metadata['creatable'] is True
        assert field_metadata['name'] == 'test'
        assert 'valuetype' in field_metadata
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / schema / test_init.py View on Github external
def make_one(self, **kwargs):
        from . import SequenceSchema

        class AdhocracySequenceExample(SequenceSchema):
            child1 = colander.Schema(typ=colander.Int())
        return AdhocracySequenceExample(**kwargs).bind()
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / rest / test_views.py View on Github external
from adhocracy_core.interfaces import ISheet
from adhocracy_core.interfaces import IResource
from adhocracy_core.testing import register_sheet


class IResourceX(IResource):
    pass


class ISheetB(ISheet):
    pass


class CountSchema(colander.MappingSchema):

    count = colander.SchemaNode(colander.Int(),
                                default=0,
                                missing=colander.drop)


@fixture
def mock_authpolicy(registry):
    from pyramid.interfaces import IAuthenticationPolicy
    from adhocracy_core.authentication import TokenHeaderAuthenticationPolicy
    policy = Mock(spec=TokenHeaderAuthenticationPolicy)
    registry.registerUtility(policy, IAuthenticationPolicy)
    return policy


@fixture
def mock_password_sheet(registry_with_content, sheet_meta):
    from adhocracy_core.sheets.principal import IPasswordAuthentication
github NOAA-ORR-ERD / PyGnome / py_gnome / gnome / utilities / projections.py View on Github external
"a (lon, lat, depth) triple\n"
                         "a Nx2 array-like object of (lon, lat)\n"
                         "a Nx3 array-like object of (lon, lat, depth)\n"
                         )


class ProjectionSchema(ObjTypeSchema):
    bounding_box = TupleSchema(
        missing=drop, save=True, update=False,
        children=[TupleSchema(children=[SchemaNode(Float()),
                                        SchemaNode(Float())]),
                  TupleSchema(children=[SchemaNode(Float()),
                                        SchemaNode(Float())])
                  ])
    image_size = TupleSchema(save=True, update=True, missing=drop,
                             children=[SchemaNode(Int()), SchemaNode(Int())])


class NoProjection(GnomeId):
    """
    This is do-nothing projection class -- returns what it gets.

    It optionally rounds down to integer (pixel) coordinates

    used for testing, primarily, and as a definition of the interface
    """
    _schema = ProjectionSchema

    def set_scale(self, bounding_box, image_size=None):
        """
        Does nothing
        """
github NOAA-ORR-ERD / PyGnome / py_gnome / gnome / spill / initializers.py View on Github external
class WindageSchema(TupleSchema):
    min_windage = SchemaNode(Float(), validator=Range(0, 1.0),
                             default=0.01)
    max_windage = SchemaNode(Float(), validator=Range(0, 1.0),
                             default=0.04)


class InitWindagesSchema(base_schema.ObjTypeSchema):
    """
    windages initializer values
    """
    windage_range = WindageSchema(
        save=True, update=True,
    )
    windage_persist = SchemaNode(
        Int(), default=900, save=True, update=True,
    )


class InitWindages(InitBaseClass):
    _schema = InitWindagesSchema

    def __init__(self, windage_range=(0.01, 0.04), windage_persist=900, name='windages', *args, **kwargs):
        """
        Initializes the windages, windage_range, windage_persist data arrays.
        Initial values for windages use infinite persistence. These are updated
        by the WindMover for particles with non-zero persistence.

        Optional arguments:

        :param windage_range=(0.01, 0.04): the windage range of the elements
            default is (0.01, 0.04) from 1% to 4%.
github wujian16 / Cornell-MOE / moe / views / schemas / bandit_pretty_view.py View on Github external
**Required fields**

    :ivar epsilon: (*0.0 <= float64 <= 1.0*) epsilon value for epsilon-first bandit. This strategy pulls the optimal arm
      (best expected return) with if it is in exploitation phase (number sampled > epsilon * total_samples). Otherwise a random arm is pulled (exploration).
    :ivar total_samples: (*int >= 0*) total number of samples for epsilon-first bandit. total_samples is T from :doc:`bandit`.

    """

    epsilon = colander.SchemaNode(
            colander.Float(),
            validator=colander.Range(min=0.0, max=1.0),
            missing=DEFAULT_EPSILON,
            )

    total_samples = colander.SchemaNode(
            colander.Int(),
            validator=colander.Range(min=0),
            missing=DEFAULT_TOTAL_SAMPLES,
            )


class BanditEpsilonGreedyHyperparameterInfo(base_schemas.StrictMappingSchema):

    """The hyperparameter info needed for every  Bandit Epsilon request.

    **Required fields**

    :ivar epsilon: (*0.0 <= float64 <= 1.0*) epsilon value for epsilon-greedy bandit. This strategy pulls the optimal arm
      (best expected return) with probability 1-epsilon. With probability epsilon a random arm is pulled.

    """
github eea / eea.corpus / src / eea.corpus / eea / corpus / processing / noun_chunks.py View on Github external
default=MODES[0][0],
        missing=MODES[0][0],
        title="Operating mode",
        widget=deform.widget.RadioChoiceWidget(values=MODES)
    )

    drop_determiners = colander.SchemaNode(
        colander.Bool(),
        default=True,
        missing=False,
        label="Determiners are leading word particles (ex: the)",
        title='Drop determiners',
    )

    min_freq = colander.SchemaNode(
        colander.Int(),
        title="Minimum frequency count",
        description="""Ignore phrases with lower count then given number""",
        default=1,
    )


@pipeline_component(schema=NounChunks,
                    title="Find and process noun chunks")
def process(content, env, **settings):
    """ Noun Chunks processing
    """

    mode = settings.get('mode', 'tokenize')

    drop_deter = settings['drop_determiners']
    min_freq = int(settings['min_freq'])
github Pylons / substanced / substanced / locking / __init__.py View on Github external
""" Raised when a lock cannot be removed

    This may be because the owner suplied in the unlock request does not
    match the owner of the lock, or becaues the lock no longer exists.

    Instances of this class have a ``lock`` attribute which is a
    :class:`substanced.locking.Lock` object, representing the conflicting lock,
    or ``None`` if there was no lock to unlock.
    """

def now():
    return datetime.datetime.utcnow().replace(tzinfo=pytz.UTC)

class LockOwnerSchema(colander.SchemaNode):
    title = 'Owner'
    schema_type = colander.Int

    @property
    def widget(self):
        context = self.bindings['context']
        principals = find_service(context, 'principals')
        if principals is None:
            values = [] # fbo dump/load
        else:
            values = [(get_oid(group), name) for name, group in
                      principals['users'].items()]
        return deform.widget.Select2Widget(values=values)

    def validator(self, node, value):
        context = self.bindings['context']
        objectmap = find_objectmap(context)
        if not value in objectmap.objectid_to_path:
github NOAA-ORR-ERD / PyGnome / py_gnome / gnome / spill / release.py View on Github external
)
    start_position = WorldPoint(
        save=True, update=True
    )
    end_position = WorldPoint(
        missing=drop, save=True, update=True
    )
    _next_release_pos = WorldPointNumpy(
        missing=drop, save=True, read_only=True
    )
    end_release_time = SchemaNode(
        LocalDateTime(), missing=drop,
        validator=convertible_to_seconds,
        save=True, update=True
    )
    num_elements = SchemaNode(Int())
    num_per_timestep = SchemaNode(
        Int(), missing=drop, save=True, update=True
    )
    description = 'ContinuousRelease object schema'


class StartPositions(SequenceSchema):
    start_position = WorldPoint()


class SpatialReleaseSchema(BaseReleaseSchema):
    '''
    Contains properties required by UpdateWindMover and CreateWindMover
    TODO: also need a way to persist list of element_types
    '''
    description = 'SpatialRelease object schema'