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
Provenance
- Commit
bbd15d5- Tree
85d25e8- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
ca176cb
2 files changed+34 added−28 removed
modified:docs/api.rst+15 added-12 removed
169 unmodified lines170 171 .. autoclass:: SessionMixin172 :members:173 174-.. autodata:: session_json_serializer175-176- 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:180-181- - :class:`~markupsafe.Markup` objects182- - :class:`~uuid.UUID` objects183- - :class:`~datetime.datetime` objects184- - :class:`tuple`\s185-174 .. admonition:: Notice175 176 The ``PERMANENT_SESSION_LIFETIME`` config key can also be an integer177 starting with Flask 0.8. Either catch this down yourself or use163 unmodified lines341 342 .. autoclass:: JSONDecoder343 :members:344 345+Tagged JSON346+~~~~~~~~~~~347+348+A compact representation for lossless serialization of non-standard JSON types.349+:class:`~flask.sessions.SecureCookieSessionInterface` uses this to serialize350+the session data, but it may be useful in other places.351+352+.. py:currentmodule:: flask.json.tag353+354+.. autoclass:: TaggedJSONSerializer355+ :members:356+357+.. autoclass:: JSONTag358+ :members:359+360 Template Rendering361 ------------------362 363 .. currentmodule:: flask475 unmodified linesmodified:flask/json/tag.py+19 added-16 removed
11 unmodified lines12 class JSONTag(object):13 """Base class for defining type tags for :class:`TaggedJSONSerializer`."""14 15 __slots__ = ('serializer',)16+17+ #: 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."""20 21 def __init__(self, serializer):22 """Create a tagger for the given serializer."""22-23 self.serializer = serializer24 25 def check(self, value):26 """Check if the given value should be tagged by this tag."""27-27 raise NotImplementedError28 29 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."""33-32 raise NotImplementedError33 34 def to_python(self, value):35 """Convert the JSON representation back to the correct type. The tag36 will already be removed."""39-37 raise NotImplementedError38 39 def tag(self, value):40 """Convert the value to a valid JSON type and add the tag structure41 around it."""45-42 return {self.key: self.to_json(value)}43 44 45 class TagDict(JSONTag):76 unmodified lines122 return b64decode(value)123 124 125 class 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`."""129 130 __slots__ = ('serializer',)131 key = ' m'132 37 unmodified lines170 171 class 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`.175 176+ The following extra types are supported:177+178+ * :class:`dict`179+ * :class:`tuple`180+ * :class:`bytes`181+ * :class:`~flask.Markup`182+ * :class:`~uuid.UUID`183+ * :class:`~datetime.datetime`184+ """185+186 __slots__ = ('tags', 'order')187+188+ #: 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`."""194 195 def __init__(self):196 self.tags = {}197 self.order = []14 unmodified lines212 213 :raise KeyError: if the tag key is already registered and ``force`` is214 not true.215 """209-216 tag = tag_class(self)217 key = tag.key218 219 if key is not None:8 unmodified lines228 self.order.insert(index, tag)229 230 def tag(self, value):231 """Convert a value to a tagged representation if necessary."""226-232 for tag in self.order:233 if tag.check(value):234 return tag.tag(value)235 236 return value237 238 def untag(self, value):239 """Convert a tagged representation back to the original type."""235-240 if len(value) != 1:241 return value242 243 key = next(iter(value))4 unmodified lines248 return self.tags[key].to_python(value[key])249 250 def dumps(self, value):251 """Tag the value and dump it to a compact JSON string."""248-252 return dumps(self.tag(value), separators=(',', ':'))253 254 def loads(self, value):255 """Load data from a JSON string and deserialized any tagged objects."""1 unmodified line