Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class GeneralMetricPermanentSchema(GeneralMetricSchema):
"""
Validates universal metric schema
"""
timestamp = colander.SchemaNode(NonTZDate(), missing=deferred_utcnow)
class GeneralMetricsListSchema(colander.SequenceSchema):
metric = GeneralMetricSchema()
validator = colander.Length(1)
class GeneralMetricsPermanentListSchema(colander.SequenceSchema):
metric = GeneralMetricPermanentSchema()
validator = colander.Length(1)
class MetricsListSchema(colander.SequenceSchema):
"""
Validates list of metrics objects ie:
[{server/time object}, ] part
"""
metric = ViewMetricSchema()
validator = colander.Length(1)
def body(node, kwargs):
resource = kwargs.get("object")["data"]
datalist = colander.MappingSchema()
datalist["data"] = colander.SequenceSchema(resource, missing=[])
return datalist
permission_name = value[0]
if permission_name not in registry.content.permissions():
msg = 'No such permission: {0}'.format(permission_name)
raise colander.Invalid(node, msg, value=permission_name)
def validate_actions_names(node, value):
for action in value[1:]:
if action not in [security.Allow, security.Deny, None]:
msg = 'Invalid action: {0}'.format(action)
raise colander.Invalid(node, msg, value=action)
return colander.All(validate_permission_name,
validate_actions_names)
class ACMPrincipals(colander.SequenceSchema):
"""ACM Principals."""
principal = ACEPrincipal()
default = []
missing = []
class ACMPermissions(colander.SequenceSchema):
"""ACM Permissions."""
row = ACMRow()
default = []
missing = []
missing=None,
)
# Although the default value of the enforce_scope property is True,
# we need to allow the unchecking of the checkbox that represents it,
# which means that empty values should be treated as False.
enforce_scope = colander.SchemaNode(
colander.Boolean(),
hint=_(
"Only allow annotations for documents within this group's defined scopes"
),
widget=CheckboxWidget(css_class="form-checkbox--inline"),
missing=False,
)
scopes = colander.SequenceSchema(
colander.Sequence(),
colander.SchemaNode(
colander.String(), name="scope", validator=url_with_origin_validator
),
title=_("Scopes"),
hint=_(
"Define where this group appears. A document's URL must start with one or more"
" of the entered scope strings (e.g. 'http://www.example.com')"
),
widget=SequenceWidget(add_subitem_text_template=_("Add scope"), min_len=1),
validator=colander.Length(
min=1, min_err=_("At least one scope must be specified")
),
)
members = colander.SequenceSchema(
build = colander.SchemaNode(colander.String())
class Packages(colander.SequenceSchema):
"""A SequenceSchema to validate a list of Package objects."""
package = colander.SchemaNode(colander.String())
class Users(colander.SequenceSchema):
"""A SequenceSchema to validate a list of User objects."""
user = colander.SchemaNode(colander.String())
class Releases(colander.SequenceSchema):
"""A SequenceSchema to validate a list of Release objects."""
release = colander.SchemaNode(colander.String())
class ReleaseIds(colander.SequenceSchema):
"""A SequenceSchema to validate a list of Release ID objects."""
release_id = colander.SchemaNode(colander.Integer())
class Groups(colander.SequenceSchema):
"""A SequenceSchema to validate a list of Group objects."""
group = colander.SchemaNode(colander.String())
class ACEPrincipal(colander.SchemaNode):
"""Adhocracy :term:`role` or pyramid system principal."""
schema_type = ACEPrincipalType
class ACMCell(colander.SchemaNode):
"""ACM Cell."""
schema_type = colander.String
missing = None
class ACMRow(colander.SequenceSchema):
"""ACM Row."""
item = ACMCell()
@colander.deferred
def validator(node, kw):
registry = kw.get('registry')
def validate_permission_name(node, value):
permission_name = value[0]
if permission_name not in registry.content.permissions():
msg = 'No such permission: {0}'.format(permission_name)
raise colander.Invalid(node, msg, value=permission_name)
def validate_actions_names(node, value):
widget=TextAreaWidget(rows=3, max_length=GROUP_DESCRIPTION_MAX_LENGTH),
missing=None
)
origins = colander.SequenceSchema(
colander.Sequence(),
colander.SchemaNode(colander.String(),
name='origin',
validator=colander.url),
title=_('Scope Origins'),
hint=_('Origins where this group appears (e.g. "https://example.com")'),
widget=SequenceWidget(add_subitem_text_template=_('Add origin'), min_len=1),
validator=colander.Length(min=1, min_err=_('At least one origin must be specified'))
)
members = colander.SequenceSchema(
colander.Sequence(),
colander.SchemaNode(colander.String(),
name='member',
validator=member_exists_validator),
title=_('Members'),
hint=_('Add more members by their username to this group'),
widget=SequenceWidget(add_subitem_text_template=_('Add member')),
missing=None
)
return np.where((velocities == v).all(axis=1))
def rewind(self):
'remove previously written files'
super(CurrentJsonOutput, self).rewind()
def current_movers_to_dict(self):
'''
a dict containing 'obj_type' and 'id' for each object in
list/collection
'''
return self._collection_to_dict(self.current_movers)
class IceJsonSchema(BaseOutputterSchema):
ice_movers = SequenceSchema(
GeneralGnomeObjectSchema(
acceptable_schemas=[IceMoverSchema]
),
save=True, update=True, save_reference=True
)
class IceJsonOutput(Outputter):
'''
Class that outputs GNOME ice property results for each ice mover
in a raw JSON format. The output contains a dict keyed by mover id.
Each value item in the dict contains a list of feature data.
Each feature item contains the ice fraction and thickness, and polyonal
coordinate data.
Following is the output format.