Exemplo n.º 1
0
 def __init__(
     self, only=None, exclude=(), prefix='', many=False,
     context=None, load_only=(), dump_only=(), partial=False,
     unknown=None,
 ):
     # Raise error if only or exclude is passed as string, not list of strings
     if only is not None and not is_collection(only):
         raise StringNotCollectionError('"only" should be a list of strings')
     if exclude is not None and not is_collection(exclude):
         raise StringNotCollectionError('"exclude" should be a list of strings')
     # copy declared fields from metaclass
     self.declared_fields = copy.deepcopy(self._declared_fields)
     self.many = many
     self.only = only
     self.exclude = exclude
     self.prefix = prefix
     self.ordered = self.opts.ordered
     self.load_only = set(load_only) or set(self.opts.load_only)
     self.dump_only = set(dump_only) or set(self.opts.dump_only)
     self.partial = partial
     self.unknown = unknown or self.opts.unknown
     #: Dictionary mapping field_names -> :class:`Field` objects
     self.fields = self.dict_class()
     self.context = context or {}
     self._normalize_nested_options()
     self._types_seen = set()
     self._update_fields(many=many)
Exemplo n.º 2
0
 def __init__(
     self, only=None, exclude=(), many=False, context=None,
     load_only=(), dump_only=(), partial=False, unknown=None,
 ):
     # Raise error if only or exclude is passed as string, not list of strings
     if only is not None and not is_collection(only):
         raise StringNotCollectionError('"only" should be a list of strings')
     if exclude is not None and not is_collection(exclude):
         raise StringNotCollectionError('"exclude" should be a list of strings')
     # copy declared fields from metaclass
     self.declared_fields = copy.deepcopy(self._declared_fields)
     self.many = many
     self.only = only
     self.exclude = exclude
     self.ordered = self.opts.ordered
     self.load_only = set(load_only) or set(self.opts.load_only)
     self.dump_only = set(dump_only) or set(self.opts.dump_only)
     self.partial = partial
     self.unknown = unknown or self.opts.unknown
     self.context = context or {}
     self._normalize_nested_options()
     #: Dictionary mapping field_names -> :class:`Field` objects
     self.fields = self._init_fields()
     messages = {}
     messages.update(self._default_error_messages)
     for cls in reversed(self.__class__.__mro__):
         messages.update(getattr(cls, 'error_messages', {}))
     messages.update(self.error_messages or {})
     self.error_messages = messages
Exemplo n.º 3
0
 def __init__(
         self,
         candidates: typing.Iterable[typing.Tuple[object,
                                                  typing.Union[SchemaABC,
                                                               type, str]]],
         *,
         default: typing.Any = missing_,
         only: types.StrSequenceOrSet = None,
         exclude: types.StrSequenceOrSet = (),
         many: bool = False,
         unknown: str = None,
         **kwargs):
     # Raise error if only or exclude is passed as string, not list of
     # strings
     if only is not None and not is_collection(only):
         raise StringNotCollectionError(
             '"only" should be a collection of strings.')
     if exclude is not None and not is_collection(exclude):
         raise StringNotCollectionError(
             '"exclude" should be a collection of strings.')
     self.candidates = candidates
     self.only = only
     self.exclude = exclude
     self.many = many
     self.unknown = unknown
     self._schemas = None  # Cached Schema instance
     super().__init__(default=default, **kwargs)
Exemplo n.º 4
0
 def __init__(
     self,
     *,
     only: typing.Optional[types.StrSequenceOrSet] = None,
     exclude: types.StrSequenceOrSet = (),
     many: bool = False,
     context: typing.Optional[typing.Dict] = None,
     load_only: types.StrSequenceOrSet = (),
     dump_only: types.StrSequenceOrSet = (),
     partial: typing.Union[bool, types.StrSequenceOrSet] = False,
     unknown: typing.Optional[str] = None,
 ):
     # Raise error if only or exclude is passed as string, not list of strings
     if only is not None and not is_collection(only):
         raise StringNotCollectionError(
             '"only" should be a list of strings')
     if not is_collection(exclude):
         raise StringNotCollectionError(
             '"exclude" should be a list of strings')
     # copy declared fields from metaclass
     self.declared_fields = copy.deepcopy(self._declared_fields)
     self.many = many
     self.only = only
     self.exclude = set(self.opts.exclude) | set(exclude)
     self.ordered = self.opts.ordered
     self.load_only = set(load_only) or set(self.opts.load_only)
     self.dump_only = set(dump_only) or set(self.opts.dump_only)
     self.partial = partial
     self.unknown = unknown or self.opts.unknown
     self.context = context or {}
     self._normalize_nested_options()
     #: Dictionary mapping field_names -> :class:`Field` objects
     self.fields = {}  # type: typing.Dict[str, ma_fields.Field]
     self.load_fields = {}  # type: typing.Dict[str, ma_fields.Field]
     self.dump_fields = {}  # type: typing.Dict[str, ma_fields.Field]
     self._init_fields()
     messages = {}
     messages.update(self._default_error_messages)
     for cls in reversed(self.__class__.__mro__):
         messages.update(getattr(cls, "error_messages", {}))
     messages.update(self.error_messages or {})
     self.error_messages = messages
 def __init__(self,
              default=missing_,
              exclude=tuple(),
              only=None,
              discriminator_field=None,
              discriminator_schemas=None,
              **kwargs):
     # Raise error if only or exclude is passed as string, not list of strings
     if only is not None and not is_collection(only):
         raise StringNotCollectionError(
             '"only" should be a list of strings')
     if exclude is not None and not is_collection(exclude):
         raise StringNotCollectionError(
             '"exclude" should be a list of strings')
     self.only = only
     self.exclude = exclude
     self.many = kwargs.get("many", False)
     self.unknown = kwargs.get("unknown", RAISE)
     self.discriminator_field = discriminator_field
     self.discriminator_schemas = discriminator_schemas
     self.__updated_fields = False
     super().__init__(default=default, **kwargs)