summaryrefslogtreecommitdiff
path: root/requests_cache/serializers
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2021-07-16 13:02:02 -0500
committerJordan Cook <jordan.cook@pioneer.com>2021-08-03 06:33:49 -0500
commit714a32e122a370e0bd460c6d48dbe4687428997c (patch)
tree2d27cfdf0db615492b1a57313e1cddc317cf17d6 /requests_cache/serializers
parentaf4a6fe0933dc988706eb1ee2b1c864396dbdd39 (diff)
downloadrequests-cache-714a32e122a370e0bd460c6d48dbe4687428997c.tar.gz
Pretty-print JSON by default
Diffstat (limited to 'requests_cache/serializers')
-rw-r--r--requests_cache/serializers/preconf.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/requests_cache/serializers/preconf.py b/requests_cache/serializers/preconf.py
index 0642220..275ec53 100644
--- a/requests_cache/serializers/preconf.py
+++ b/requests_cache/serializers/preconf.py
@@ -11,6 +11,7 @@ class that raises an ``ImportError`` at initialization time instead of at import
Requires python 3.7+.
"""
import pickle
+from functools import partial
from cattr.preconf import bson as bson_preconf
from cattr.preconf import json as json_preconf
@@ -33,6 +34,7 @@ ujson_preconf_stage = CattrStage(ujson.make_converter)
# Pickle serializer that uses the cattrs base converter
pickle_serializer = SerializerPipeline([base_stage, pickle])
+
# Pickle serializer with an additional stage using itsdangerous
try:
from itsdangerous import Signer
@@ -51,6 +53,7 @@ except ImportError as e:
signer_stage = get_placeholder_class(e)
safe_pickle_serializer = get_placeholder_class(e)
+
# BSON serializer using either PyMongo's bson.json_util if installed, otherwise standalone bson codec
try:
try:
@@ -62,6 +65,7 @@ try:
except ImportError as e:
bson_serializer = get_placeholder_class(e)
+
# JSON serailizer using ultrajson if installed, otherwise stdlib json
try:
import ujson as json
@@ -72,7 +76,10 @@ except ImportError:
converter = json_preconf_stage
-json_serializer = SerializerPipeline([converter, json])
+json_stage = Stage(json)
+json_stage.dumps = partial(json.dumps, indent=2)
+json_serializer = SerializerPipeline([converter, json_stage])
+
# YAML serializer using pyyaml
try: