Skip to content
Myr

docs style cleanup

Before adoption: this commit came in with the history the project adopted, so no landing records it.

[ci skip]

authored by David Lord · committed by David Lord · parent ca176cb · Browse files · 2 files+34 added−28 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+34 added−28 removed

  • other:+34 added−28 removed

2 files+34 added−28 removed

modified:docs/api.rst+15 added-12 removed
169 unmodified lines
170171.. autoclass:: SessionMixin172 :members:173174.. autodata:: session_json_serializer175176 This object provides dumping and loading methods similar to simplejson177 but it also tags certain builtin Python objects that commonly appear in178 sessions. Currently the following extended values are supported in179 the JSON it dumps:180181 - :class:`~markupsafe.Markup` objects182 - :class:`~uuid.UUID` objects183 - :class:`~datetime.datetime` objects184 - :class:`tuple`\s185174.. admonition:: Notice175176 The ``PERMANENT_SESSION_LIFETIME`` config key can also be an integer177 starting with Flask 0.8. Either catch this down yourself or use
163 unmodified lines
341342.. autoclass:: JSONDecoder343 :members:344345Tagged JSON346~~~~~~~~~~~347348A compact representation for lossless serialization of non-standard JSON types.349:class:`~flask.sessions.SecureCookieSessionInterface` uses this to serialize350the session data, but it may be useful in other places.351352.. py:currentmodule:: flask.json.tag353354.. autoclass:: TaggedJSONSerializer355 :members:356357.. autoclass:: JSONTag358 :members:359360Template Rendering361------------------362363.. currentmodule:: flask
475 unmodified lines
modified:flask/json/tag.py+19 added-16 removed
11 unmodified lines
12class JSONTag(object):13 """Base class for defining type tags for :class:`TaggedJSONSerializer`."""1415 __slots__ = ('serializer',)1617 #: The tag to mark the serialized object with. If ``None``, this tag is18 #: only used as an intermediate step during tagging.19 key = None17 """The tag to mark the serialized object with. If ``None``, this tag is18 only used as an intermediate step during tagging."""2021 def __init__(self, serializer):22 """Create a tagger for the given serializer."""2223 self.serializer = serializer2425 def check(self, value):26 """Check if the given value should be tagged by this tag."""2727 raise NotImplementedError2829 def to_json(self, value):30 """Convert the Python object to an object that is a valid JSON type.31 The tag will be added later."""3332 raise NotImplementedError3334 def to_python(self, value):35 """Convert the JSON representation back to the correct type. The tag36 will already be removed."""3937 raise NotImplementedError3839 def tag(self, value):40 """Convert the value to a valid JSON type and add the tag structure41 around it."""4542 return {self.key: self.to_json(value)}434445class TagDict(JSONTag):
76 unmodified lines
122 return b64decode(value)123124125class TagMarkup(JSONTag):130 """Serialize anything matching the :class:`~markupsafe.Markup` API by126 """Serialize anything matching the :class:`~flask.Markup` API by127 having a ``__html__`` method to the result of that method. Always132 deserializes to an instance of :class:`~markupsafe.Markup`."""128 deserializes to an instance of :class:`~flask.Markup`."""129130 __slots__ = ('serializer',)131 key = ' m'132
37 unmodified lines
170171class TaggedJSONSerializer(object):172 """Serializer that uses a tag system to compactly represent objects that173 are not JSON types. Passed as the intermediate serializer to178 :class:`itsdangerous.Serializer`."""174 :class:`itsdangerous.Serializer`.175176 The following extra types are supported:177178 * :class:`dict`179 * :class:`tuple`180 * :class:`bytes`181 * :class:`~flask.Markup`182 * :class:`~uuid.UUID`183 * :class:`~datetime.datetime`184 """185186 __slots__ = ('tags', 'order')187188 #: Tag classes to bind when creating the serializer. Other tags can be189 #: added later using :meth:`~register`.190 default_tags = [191 TagDict, PassDict, TagTuple, PassList, TagBytes, TagMarkup, TagUUID,192 TagDateTime,193 ]185 """Tag classes to bind when creating the serializer. Other tags can be186 added later using :meth:`~register`."""194195 def __init__(self):196 self.tags = {}197 self.order = []
14 unmodified lines
212213 :raise KeyError: if the tag key is already registered and ``force`` is214 not true.215 """209216 tag = tag_class(self)217 key = tag.key218219 if key is not None:
8 unmodified lines
228 self.order.insert(index, tag)229230 def tag(self, value):231 """Convert a value to a tagged representation if necessary."""226232 for tag in self.order:233 if tag.check(value):234 return tag.tag(value)235236 return value237238 def untag(self, value):239 """Convert a tagged representation back to the original type."""235240 if len(value) != 1:241 return value242243 key = next(iter(value))
4 unmodified lines
248 return self.tags[key].to_python(value[key])249250 def dumps(self, value):251 """Tag the value and dump it to a compact JSON string."""248252 return dumps(self.tag(value), separators=(',', ':'))253254 def loads(self, value):255 """Load data from a JSON string and deserialized any tagged objects."""
1 unmodified line