|
OpenQuizz
Une application de gestion des contenus pédagogiques
|
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 | |
Utility methods for marshmallow.
| def marshmallow.utils.callable_or_raise | ( | obj | ) |
Check that an object is callable, else raise a :exc:`TypeError`.
| str marshmallow.utils.ensure_text_type | ( | typing.Union[str, bytes] | val | ) |
| def marshmallow.utils.from_iso_date | ( | value | ) |
Parse a string and return a datetime.date.
| 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.
| def marshmallow.utils.from_iso_time | ( | value | ) |
Parse a string and return a datetime.time. This function doesn't support time zone offsets.
| 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
| dt.timezone marshmallow.utils.get_fixed_timezone | ( | typing.Union[int, float, dt.timedelta] | offset | ) |
Return a tzinfo instance with a fixed offset from UTC.
| 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``.
| 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.
| bool marshmallow.utils.is_aware | ( | dt.datetime | datetime | ) |
| bool marshmallow.utils.is_collection | ( | obj | ) |
Return True if ``obj`` is a collection type, e.g list, tuple, queryset.
| bool marshmallow.utils.is_generator | ( | obj | ) |
Return True if ``obj`` is a generator
| bool marshmallow.utils.is_instance_or_subclass | ( | val, | |
| class_ | |||
| ) |
Return True if ``val`` is either a subclass or instance of ``class_``.
| bool marshmallow.utils.is_iterable_but_not_string | ( | obj | ) |
Return True if ``obj`` is an iterable object that isn't a string.
| bool marshmallow.utils.is_keyed_tuple | ( | obj | ) |
Return True if ``obj`` has keyed tuple behavior, such as namedtuples or SQLAlchemy's KeyedTuples.
| str marshmallow.utils.isoformat | ( | dt.datetime | datetime | ) |
Return the ISO8601-formatted representation of a datetime object. :param datetime datetime: The datetime.
| 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]
| 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.
| 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.
| str marshmallow.utils.rfcformat | ( | dt.datetime | datetime | ) |
Return the RFC822-formatted representation of a datetime object. :param datetime datetime: The datetime.
| 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}}
| str marshmallow.utils.to_iso_date | ( | dt.date | date | ) |
| str marshmallow.utils.to_iso_time | ( | dt.time | time | ) |
| EXCLUDE |
| INCLUDE |
| missing |
| RAISE |