Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except TypeError as te:
raise ValidationError(str(te))
@post_load
def make_user(self, data, **kwargs):
return User(**data)
class UserMetaSchema(Schema):
"""The equivalent of the UserSchema, using the ``fields`` option."""
uppername = Uppercased(attribute="name", dump_only=True)
balance = fields.Decimal()
is_old = fields.Method("get_is_old")
lowername = fields.Function(get_lowername)
species = fields.String(attribute="SPECIES")
homepage = fields.Url()
email = fields.Email()
various_data = fields.Dict()
def get_is_old(self, obj):
if obj is None:
return missing
if isinstance(obj, dict):
age = obj.get("age")
else:
age = obj.age
try:
return age > 80
except TypeError as te:
raise ValidationError(str(te))
module = fields.String()
enabled = fields.Boolean()
settings = fields.String()
class NzbSearchResultSchema(Schema):
title = fields.String()
link = fields.String()
epoch = fields.Integer()
pubdate_utc = fields.String()
age = fields.String()
age_days = fields.Integer()
age_precise = fields.Boolean()
indexer = fields.String()
indexerscore = fields.String()
searchResultId = fields.String()
indexerguid = fields.String()
size = fields.Integer()
category = fields.String()
has_nfo = fields.Integer()
details_link = fields.String()
hash = fields.Integer()
dbsearchid = fields.Integer()
downloadType = fields.String()
comments = fields.Integer()
grabs = fields.Integer()
files = fields.Integer()
class IndexerApiAccessSchema(Schema):
indexer = fields.Nested(IndexerSchema, only="name")
time = fields.DateTime()
description="Sender identifier",
)
message = fields.Dict(description="Message payload, can hold other keys")
@marshmallow.post_load()
def _add_unknown(self, data):
data["edited"] = None
return data
class MessageEditBodySchema(MessageBodySchema):
uuid = fields.UUID(
required=True, description="Identifier of message that is being edited"
)
timestamp = fields.DateTime()
user = fields.String(validate=validate.Length(min=1, max=512))
message = fields.Dict()
edited = fields.DateTime(missing=lambda: datetime.utcnow().isoformat())
@marshmallow.post_load()
def _add_unknown(self, data):
return data
class MessagesDeleteBodySchema(PayloadDeliveryInfo, ChannelstreamSchema):
uuid = fields.UUID(
required=True,
description="Identifier of message that should be deleted from history",
)
class DisconnectBodySchema(ChannelstreamSchema):
class ErrorByExtensionSchema(marshmallow.Schema):
"Marshmallow schema for :class:`commercetools.types.ErrorByExtension`."
id = marshmallow.fields.String(allow_none=True)
key = marshmallow.fields.String(allow_none=True, missing=None)
class Meta:
unknown = marshmallow.EXCLUDE
@marshmallow.post_load
def post_load(self, data, **kwargs):
return types.ErrorByExtension(**data)
class ErrorObjectSchema(marshmallow.Schema):
"Marshmallow schema for :class:`commercetools.types.ErrorObject`."
code = marshmallow.fields.String(allow_none=True)
message = marshmallow.fields.String(allow_none=True)
class Meta:
unknown = marshmallow.EXCLUDE
@marshmallow.post_load
def post_load(self, data, **kwargs):
del data["code"]
return types.ErrorObject(**data)
class ErrorResponseSchema(marshmallow.Schema):
"Marshmallow schema for :class:`commercetools.types.ErrorResponse`."
status_code = marshmallow.fields.Integer(allow_none=True, data_key="statusCode")
message = marshmallow.fields.String(allow_none=True)
error = marshmallow.fields.String(allow_none=True, missing=None)
class V1ObjectMetaSchema(Schema):
annotations = fields.Dict(required=False, allow_none=True, missing=None)
cluster_name = fields.String(required=False, allow_none=True, missing=None, dump_to='clusterName', load_from='clusterName')
creation_timestamp = fields.DateTime(required=False, allow_none=True, missing=None, dump_to='creationTimestamp', load_from='creationTimestamp')
deletion_grace_period_seconds = fields.Int(required=False, allow_none=True, missing=None, dump_to='deletionGracePeriodSeconds', load_from='deletionGracePeriodSeconds')
deletion_timestamp = fields.DateTime(required=False, allow_none=True, missing=None, dump_to='deletionTimestamp', load_from='deletionTimestamp')
finalizers = fields.List(fields.String, required=False, allow_none=True, missing=None)
generate_name = fields.String(required=False, allow_none=True, missing=None, dump_to='generateName', load_from='generateName')
generation = fields.Int(required=False, allow_none=True, missing=None)
initializers = fields.Dict(required=False, allow_none=True, missing=None) # V1Initializers
labels = fields.Dict(required=False, allow_none=True, missing=None)
name = fields.String(required=True, allow_none=False)
namespace = fields.String(required=True, allow_none=False)
owner_references = fields.List(fields.Dict, required=False, allow_none=True, missing=None, dump_to='ownerReferences', load_from='ownerReferences') # list[V1OwnerReference]
resource_version = fields.String(required=False, allow_none=True, missing=None, dump_to='resourceVersion', load_from='resourceVersion')
self_link = fields.String(required=False, allow_none=True, missing=None, dump_to='selfLink', load_from='selfLink')
uid = fields.String(required=False, allow_none=True, missing=None)
@post_load
def make_V1ObjectMeta(self, data):
return client.V1ObjectMeta(**data)
@post_dump
def remove_none_value_fields(self, data):
result = data.copy()
for key in filter(lambda key: data[key] is None, data):
del result[key]
return result
@validates('name')
def validate_name(self, name: str):
from flask import make_response
from marshmallow import Schema, fields
from requests import HTTPError
from xivo_ctid_ng.auth import Unauthorized
from xivo_ctid_ng.rest_api import ErrorCatchingResource
class BaseSchema(Schema):
class Meta:
strict = True
class MessageRequestSchema(BaseSchema):
author = fields.String(required=True)
server = fields.String()
receiver = fields.String(required=True)
message = fields.String(required=True)
class MessageCallbackResource(ErrorCatchingResource):
def __init__(self, message_callback_service):
self._message_callback_service = message_callback_service
def post(self):
request_body = MessageRequestSchema().load(request.form).data
self._message_callback_service.send_message(request_body)
return '', 204
# -*- coding: utf-8 -*-
import marshmallow
class ErrorResponseSchema(marshmallow.Schema):
message = marshmallow.fields.String(required=True)
details = marshmallow.fields.Dict(required=True)
class HelloResponseSchema(marshmallow.Schema):
sentence = marshmallow.fields.String(required=True)
name = marshmallow.fields.String(required=True)
color = marshmallow.fields.String(required=False)
class HelloPathSchema(marshmallow.Schema):
name = marshmallow.fields.String(required=True, validate=marshmallow.validate.Length(min=3))
class HelloQuerySchema(marshmallow.Schema):
alive = marshmallow.fields.Boolean(required=False)
class HelloJsonSchema(marshmallow.Schema):
color = marshmallow.fields.String(required=True, validate=marshmallow.validate.Length(min=3))
class HelloFileSchema(marshmallow.Schema):
name = 'showtime'
id = fields.Integer()
theatre_id = fields.Integer()
hall_id = fields.Integer()
technology_id = fields.Integer()
date_time = fields.DateTime()
order_url = fields.Url()
class TheatreSchema(NamespacedSchema):
class Meta:
name = 'theatre'
id = fields.Integer()
name = fields.String()
en_name = fields.String()
url_code = fields.String()
st_url_code = fields.String()
class TechnologySchema(NamespacedSchema):
class Meta:
name = 'technology'
plural_name = 'technologies'
id = fields.Integer()
code = fields.String()
name = fields.String()
"""A category of collections, e.g. leaks, court cases, sanctions list."""
def _validate(self, value):
if value not in Collection.CATEGORIES.keys():
raise ValidationError('Invalid category.')
class Language(String):
"""A valid language code."""
def _validate(self, value):
if not registry.language.validate(value):
raise ValidationError('Invalid language code.')
class Country(String):
"""A valid country code."""
def _validate(self, value):
if not registry.country.validate(value):
raise ValidationError('Invalid country code: %s' % value)
class PartialDate(String):
"""Any valid prefix of an ISO 8601 datetime string."""
def _validate(self, value):
if not registry.date.validate(value):
raise ValidationError('Invalid date: %s' % value)
class SchemaName(String):
latitude = fields.Float(allow_none=True)
is_reservable = fields.Boolean(allow_none=True)
reservations_need_confirmation = fields.Boolean(allow_none=True)
notification_emails = fields.List(fields.Email())
notification_before_days = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
notification_before_days_weekly = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
notification_before_days_monthly = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
notifications_enabled = fields.Boolean()
end_notification_daily = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
end_notification_weekly = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
end_notification_monthly = fields.Int(validate=lambda x: 1 <= x <= 30, allow_none=True)
end_notifications_enabled = fields.Boolean()
booking_limit_days = fields.Int(validate=lambda x: x >= 1, allow_none=True)
owner = Principal(validate=lambda x: x is not None, allow_none=True)
key_location = fields.String()
telephone = fields.String()
capacity = fields.Int(validate=lambda x: x >= 1)
division = fields.String(allow_none=True)
surface_area = fields.Int(validate=lambda x: x >= 0, allow_none=True)
max_advance_days = fields.Int(validate=lambda x: x >= 1, allow_none=True)
comments = fields.String()
acl_entries = PrincipalPermissionList(RoomPrincipal)
protection_mode = EnumField(ProtectionMode)
class RoomEquipmentSchema(mm.ModelSchema):
class Meta:
model = Room
fields = ('available_equipment',)
class MapAreaSchema(mm.ModelSchema):