Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_can_use_full_module_path_to_class():
from .foo_serializer import FooSerializer as FooSerializer1 # noqa
# Using full paths is ok
class Schema1(Schema):
foo = fields.Nested('tests.foo_serializer.FooSerializer')
sch = Schema1()
# Note: The arguments here don't matter. What matters is that no
# error is raised
assert sch.dump({'foo': {'_id': 42}}).data
class Schema2(Schema):
foo = fields.Nested('tests.test_registry.FooSerializer')
sch = Schema2()
assert sch.dump({'foo': {'_id': 42}}).data
avatar_url = fields.String()
gravatar_id = fields.String()
id = fields.Integer()
login = fields.String()
url = fields.String()
class Comment(Schema):
body = fields.String()
class CommentBody(Schema):
body = fields.String(required=True)
class CommentsItem(Schema):
body = fields.String()
created_at = fields.String(description='ISO 8601.')
id = fields.Integer()
url = fields.String()
user = fields.Nested('CommentsItemUser')
class CommentsItemUser(Schema):
avatar_url = fields.String()
gravatar_id = fields.String()
id = fields.Integer()
login = fields.String()
url = fields.String()
class Commit(Schema):
class MallTransactionRefundRequestSchema(Schema):
amount = fields.Float()
commerce_code = fields.Str()
buy_order = fields.Str()
class TransactionRefundResponseSchema(Schema):
error_message = fields.Str()
amount = fields.Float()
type = fields.Str()
balance = fields.Float()
authorization_code = fields.Str()
response_code = fields.Int()
authorization_date = fields.Str()
nullified_amount = fields.Float()
class DeferredTransactionResponseSchema(Schema):
authorization_code = fields.Str()
authorization_date = fields.Str()
captured_amount = fields.Float()
response_code = fields.Int()
class MallDetailsSchema(Schema):
amount = fields.Float()
commerce_code = fields.Str()
buy_order = fields.Str()
status = fields.Str()
authorization_code = fields.Str()
payment_type_code = fields.Str()
response_code = fields.Int()
installments_number = fields.Int()
_jsonschema_type_mapping = doc.get_jsonschema_type_mapping("string")
class ArgumentNameField(marshmallow.fields.Field):
# pylint: disable=redefined-outer-name
def _deserialize(self, value, attr, data, **kwargs):
return [value]
_jsonschema_type_mapping = doc.get_jsonschema_type_mapping("string")
class AnyField(marshmallow.fields.Field):
_jsonschema_type_mapping = doc.get_jsonschema_type_mapping("string")
class OptionSchema(marshmallow.Schema):
"""A command line named option for a new command."""
param_decls = OptionNameField(
data_key="name",
metadata={"description": "Name of the option. Usually prefixed with - or --."},
)
type = TypeField(
metadata={"description": f'Name of the type. {", ".join(TYPES)} accepted.'}
)
is_flag = fields.Boolean(
default=False, metadata={"description": "Whether the option is a boolean flag."}
)
help = fields.String(
default=None, metadata={"description": "Documentation for the option."}
)
hidden = fields.Boolean(
elif param.annotation in QUERY_SCHEMA_MAPPING:
if param.annotation in (OptInt, OptFloat, OptBool, OptStr) or param.default is not param.empty:
required = False
kwargs = {"missing": param.default if param.default is not param.empty else None}
else:
required = True
kwargs = {"required": True}
query_fields[name] = Field(
name=name,
location=FieldLocation.query,
schema=QUERY_SCHEMA_MAPPING[param.annotation](**kwargs),
required=required,
)
# Body params
elif inspect.isclass(param.annotation) and issubclass(param.annotation, marshmallow.Schema):
body_field = Field(name=name, location=FieldLocation.body, schema=param.annotation())
output_field = inspect.signature(handler).return_annotation
return query_fields, path_fields, body_field, output_field
from marshmallow import fields, Schema
from .base import BaseHolder, HolderError
from ..messaging.valid import (
INDY_CRED_DEF_ID,
INDY_REV_REG_ID,
INDY_SCHEMA_ID,
INDY_WQL,
NATURAL_NUM,
WHOLE_NUM,
UUIDFour,
)
from ..wallet.error import WalletNotFoundError
class RawEncCredAttrSchema(Schema):
"""Credential attribute schema."""
raw = fields.Str(description="Raw value", example="Alex")
encoded = fields.Str(
description="(Numeric string) encoded value",
example="412821674062189604125602903860586582569826459817431467861859655321",
)
class RevRegSchema(Schema):
"""Revocation registry schema."""
accum = fields.Str(
description="Revocation registry accumulator state",
example="21 136D54EA439FC26F03DB4b812 21 123DE9F624B86823A00D ...",
)
from __future__ import absolute_import
from marshmallow import fields, post_load, Schema
from invenio_jsonschemas import current_jsonschemas
from ....deposit.api import Project, deposit_video_resolver
from .common import \
AccessSchema, BucketSchema, ContributorSchema, \
DepositSchema, ExternalSystemIdentifiersField, LicenseSchema, \
OaiSchema, StrictKeysSchema, TitleSchema, \
TranslationsSchema, KeywordsSchema
from .doi import DOI
class _CDSSSchema(Schema):
"""CDS private metadata."""
state = fields.Raw()
modified_by = fields.Int()
class ProjectDepositSchema(DepositSchema):
"""Project Deposit Schema."""
id = fields.Str(required=True)
class FileSchema(StrictKeysSchema):
"""File schema."""
bucket = fields.Str()
nested="commercetools.schemas._customer.CustomerSchema",
unknown=marshmallow.EXCLUDE,
allow_none=True,
missing=None,
)
class Meta:
unknown = marshmallow.EXCLUDE
@marshmallow.post_load
def post_load(self, data, **kwargs):
del data["type_id"]
return types.CustomerReference(**data)
class CustomerResetPasswordSchema(marshmallow.Schema):
"Marshmallow schema for :class:`commercetools.types.CustomerResetPassword`."
token_value = marshmallow.fields.String(allow_none=True, data_key="tokenValue")
new_password = marshmallow.fields.String(allow_none=True, data_key="newPassword")
version = marshmallow.fields.Integer(allow_none=True, missing=None)
class Meta:
unknown = marshmallow.EXCLUDE
@marshmallow.post_load
def post_load(self, data, **kwargs):
return types.CustomerResetPassword(**data)
class CustomerResourceIdentifierSchema(ResourceIdentifierSchema):
"Marshmallow schema for :class:`commercetools.types.CustomerResourceIdentifier`."
class RequestedPredicate(Schema):
"""RequestedPredicate model."""
name = fields.Str(required=True)
p_type = fields.Str(required=True)
p_value = fields.Str(required=True)
restrictions = fields.List(fields.Dict(), required=False)
connection_id = fields.Str(required=True)
name = fields.String(required=True)
version = fields.String(required=True)
requested_attributes = fields.Nested(RequestedAttribute, many=True)
requested_predicates = fields.Nested(RequestedPredicate, many=True)
class SendPresentationRequestSchema(Schema):
"""Request schema for sending a presentation."""
self_attested_attributes = fields.Dict(required=True)
requested_attributes = fields.Dict(required=True)
requested_predicates = fields.Dict(required=True)
@docs(tags=["presentation_exchange"], summary="Fetch all presentation exchange records")
@response_schema(PresentationExchangeListSchema(), 200)
async def presentation_exchange_list(request: web.BaseRequest):
"""
Request handler for searching presentation exchange records.
Args:
request: aiohttp request object
def cast_arg(arg, kind: Optional = None):
# fields.Integer()
if isinstance(kind, fields.Field):
arg = kind.deserialize(arg)
# arg: fields.Integer
elif isclass(kind) and issubclass(kind, fields.Field):
arg = kind().deserialize(arg)
# arg: RequestSchema
elif isclass(kind) and issubclass(kind, Schema):
arg = kind(many=False).load(arg) # $strict=True, .marshmallow 3.0 compatibility
# RequestSchema()
elif isinstance(kind, Schema):
kind.strict = True
arg = kind.load(arg) # .data marshmallow 3.0 compatibility
# int, string
elif callable(kind):
arg = kind(arg)
return arg