OpenQuizz
Une application de gestion des contenus pédagogiques
marshmallow.utils Namespace Reference

Data Structures

class  _Missing
 

Functions

bool is_generator (obj)
 
bool is_iterable_but_not_string (obj)
 
bool is_collection (obj)
 
bool is_instance_or_subclass (val, class_)
 
bool is_keyed_tuple (obj)
 
None pprint (obj, *args, **kwargs)
 
bool is_aware (dt.datetime datetime)
 
dt.datetime from_rfc (str datestring)
 
str rfcformat (dt.datetime datetime)
 
dt.timezone get_fixed_timezone (typing.Union[int, float, dt.timedelta] offset)
 
def from_iso_datetime (value)
 
def from_iso_time (value)
 
def from_iso_date (value)
 
str isoformat (dt.datetime datetime)
 
str to_iso_time (dt.time time)
 
str to_iso_date (dt.date date)
 
str ensure_text_type (typing.Union[str, bytes] val)
 
def pluck (typing.List[typing.Dict[str, typing.Any]] dictlist, str key)
 
def get_value (obj, typing.Union[int, str] key, default=missing)
 
def set_value (typing.Dict[str, typing.Any] dct, str key, typing.Any value)
 
def callable_or_raise (obj)
 
typing.List[str] get_func_args (typing.Callable func)
 
def resolve_field_instance (cls_or_instance)
 

Variables

 EXCLUDE
 
 INCLUDE
 
 RAISE
 
 missing
 

Detailed Description

Utility methods for marshmallow.

Function Documentation

◆ callable_or_raise()

def marshmallow.utils.callable_or_raise (   obj)
Check that an object is callable, else raise a :exc:`TypeError`.

◆ ensure_text_type()

str marshmallow.utils.ensure_text_type ( typing.Union[str, bytes]  val)

◆ from_iso_date()

def marshmallow.utils.from_iso_date (   value)
Parse a string and return a datetime.date.

◆ from_iso_datetime()

def marshmallow.utils.from_iso_datetime (   value)
Parse a string and return a datetime.datetime.

This function supports time zone offsets. When the input contains one,
the output uses a timezone with a fixed offset from UTC.

◆ from_iso_time()

def marshmallow.utils.from_iso_time (   value)
Parse a string and return a datetime.time.

This function doesn't support time zone offsets.

◆ from_rfc()

dt.datetime marshmallow.utils.from_rfc ( str  datestring)
Parse a RFC822-formatted datetime string and return a datetime object.

https://stackoverflow.com/questions/885015/how-to-parse-a-rfc-2822-date-time-into-a-python-datetime  # noqa: B950

◆ get_fixed_timezone()

dt.timezone marshmallow.utils.get_fixed_timezone ( typing.Union[int, float, dt.timedelta]  offset)
Return a tzinfo instance with a fixed offset from UTC.

◆ get_func_args()

typing.List[str] marshmallow.utils.get_func_args ( typing.Callable  func)
Given a callable, return a list of argument names. Handles
`functools.partial` objects and class-based callables.

.. versionchanged:: 3.0.0a1
    Do not return bound arguments, eg. ``self``.

◆ get_value()

def marshmallow.utils.get_value (   obj,
typing.Union[int, str]  key,
  default = missing 
)
Helper for pulling a keyed value off various types of objects. Fields use
this method by default to access attributes of the source object. For object `x`
and attribute `i`, this method first tries to access `x[i]`, and then falls back to
`x.i` if an exception is raised.

.. warning::
    If an object `x` does not raise an exception when `x[i]` does not exist,
    `get_value` will never check the value `x.i`. Consider overriding
    `marshmallow.fields.Field.get_value` in this case.

◆ is_aware()

bool marshmallow.utils.is_aware ( dt.datetime  datetime)

◆ is_collection()

bool marshmallow.utils.is_collection (   obj)
Return True if ``obj`` is a collection type, e.g list, tuple, queryset.

◆ is_generator()

bool marshmallow.utils.is_generator (   obj)
Return True if ``obj`` is a generator

◆ is_instance_or_subclass()

bool marshmallow.utils.is_instance_or_subclass (   val,
  class_ 
)
Return True if ``val`` is either a subclass or instance of ``class_``.

◆ is_iterable_but_not_string()

bool marshmallow.utils.is_iterable_but_not_string (   obj)
Return True if ``obj`` is an iterable object that isn't a string.

◆ is_keyed_tuple()

bool marshmallow.utils.is_keyed_tuple (   obj)
Return True if ``obj`` has keyed tuple behavior, such as
namedtuples or SQLAlchemy's KeyedTuples.

◆ isoformat()

str marshmallow.utils.isoformat ( dt.datetime  datetime)
Return the ISO8601-formatted representation of a datetime object.

:param datetime datetime: The datetime.

◆ pluck()

def marshmallow.utils.pluck ( typing.List[typing.Dict[str, typing.Any]]  dictlist,
str  key 
)
Extracts a list of dictionary values from a list of dictionaries.
::

    >>> dlist = [{'id': 1, 'name': 'foo'}, {'id': 2, 'name': 'bar'}]
    >>> pluck(dlist, 'id')
    [1, 2]

◆ pprint()

None marshmallow.utils.pprint (   obj,
args,
**  kwargs 
)
Pretty-printing function that can pretty-print OrderedDicts
like regular dictionaries. Useful for printing the output of
:meth:`marshmallow.Schema.dump`.

.. deprecated:: 3.7.0
    marshmallow.pprint will be removed in marshmallow 4.

◆ resolve_field_instance()

def marshmallow.utils.resolve_field_instance (   cls_or_instance)
Return a Schema instance from a Schema class or instance.

:param type|Schema cls_or_instance: Marshmallow Schema class or instance.

◆ rfcformat()

str marshmallow.utils.rfcformat ( dt.datetime  datetime)
Return the RFC822-formatted representation of a datetime object.

:param datetime datetime: The datetime.

◆ set_value()

def marshmallow.utils.set_value ( typing.Dict[str, typing.Any]  dct,
str  key,
typing.Any  value 
)
Set a value in a dict. If `key` contains a '.', it is assumed
be a path (i.e. dot-delimited string) to the value's location.

::

    >>> d = {}
    >>> set_value(d, 'foo.bar', 42)
    >>> d
    {'foo': {'bar': 42}}

◆ to_iso_date()

str marshmallow.utils.to_iso_date ( dt.date  date)

◆ to_iso_time()

str marshmallow.utils.to_iso_time ( dt.time  time)

Variable Documentation

◆ EXCLUDE

EXCLUDE

◆ INCLUDE

INCLUDE

◆ missing

missing

◆ RAISE

RAISE