replace json.dumps with direct calls to JSONEncoder.encode

This commit is contained in:
Mike Fährmann
2023-02-09 15:50:55 +01:00
parent dd884b02ee
commit 5503ac4d5e
5 changed files with 19 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2019-2022 Mike Fährmann
# Copyright 2019-2023 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -9,7 +9,7 @@
"""Extractors for https://500px.com/"""
from .common import Extractor, Message
import json
from .. import util
BASE_PATTERN = r"(?:https?://)?(?:web\.)?500px\.com"
@@ -86,7 +86,7 @@ class _500pxExtractor(Extractor):
}
data = {
"operationName": opname,
"variables" : json.dumps(variables),
"variables" : util.json_dumps(variables),
"query" : QUERIES[opname],
}
return self.request(

View File

@@ -12,7 +12,6 @@ from .common import Extractor, Message
from .. import text, util, exception
from ..cache import cache
import itertools
import json
BASE_PATTERN = r"(?:https?://)?(?:\w+\.)?pinterest\.[\w.]+"
@@ -504,7 +503,10 @@ class PinterestAPI():
"username_or_email": username,
"password" : password,
}
data = {"data": json.dumps({"options": options}), "source_url": ""}
data = {
"data" : util.json_dumps({"options": options}),
"source_url": "",
}
try:
response = self.extractor.request(
@@ -523,7 +525,10 @@ class PinterestAPI():
def _call(self, resource, options):
url = "{}/resource/{}Resource/get/".format(self.root, resource)
params = {"data": json.dumps({"options": options}), "source_url": ""}
params = {
"data" : util.json_dumps({"options": options}),
"source_url": "",
}
response = self.extractor.request(
url, params=params, headers=self.headers,

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2021-2022 Mike Fährmann
# Copyright 2021-2023 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@@ -9,13 +9,11 @@
"""String formatters"""
import os
import json
import time
import string
import _string
import datetime
import operator
import functools
from . import text, util
NONE = util.NONE
@@ -399,7 +397,7 @@ _CONVERSIONS = {
"u": str.upper,
"c": str.capitalize,
"C": string.capwords,
"j": functools.partial(json.dumps, default=str),
"j": util.json_dumps,
"t": str.strip,
"T": util.datetime_to_timestamp_string,
"d": text.parse_timestamp,

View File

@@ -7,7 +7,6 @@
# published by the Free Software Foundation.
import sys
import json
import errno
import logging
import functools
@@ -711,17 +710,19 @@ class InfoJob(Job):
def _print_multi(self, title, *values):
stdout_write("{}\n {}\n\n".format(
title, " / ".join(json.dumps(v) for v in values)))
title, " / ".join(map(util.json_dumps, values))))
def _print_config(self, title, optname, value):
optval = self.extractor.config(optname, util.SENTINEL)
if optval is not util.SENTINEL:
stdout_write(
"{} (custom):\n {}\n{} (default):\n {}\n\n".format(
title, json.dumps(optval), title, json.dumps(value)))
title, util.json_dumps(optval),
title, util.json_dumps(value)))
elif value:
stdout_write(
"{} (default):\n {}\n\n".format(title, json.dumps(value)))
"{} (default):\n {}\n\n".format(
title, util.json_dumps(value)))
class DataJob(Job):

View File

@@ -205,6 +205,7 @@ def datetime_to_timestamp_string(dt):
json_loads = json._default_decoder.decode
json_dumps = json.JSONEncoder(default=str).encode
def dump_json(obj, fp=sys.stdout, ensure_ascii=True, indent=4):