From 631c64ca6cf054c965c82b9b78a156713bb5b300 Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Thu, 14 Sep 2017 11:18:39 +0200 Subject: [PATCH] zulip: Move from simplejson to json. This removes the simplejson dependency. --- zulip/README.md | 1 - zulip/integrations/zephyr/sync-public-streams | 4 ++-- zulip/integrations/zephyr/zephyr_mirror_backend.py | 11 ++++------- zulip/setup.py | 6 ------ zulip/zulip/__init__.py | 6 +++--- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/zulip/README.md b/zulip/README.md index 91935b6..cffd204 100644 --- a/zulip/README.md +++ b/zulip/README.md @@ -4,7 +4,6 @@ The [Zulip API](https://zulipchat.com/api) Python bindings require the following Python libraries: * requests (version >= 0.12.1) -* simplejson * six * typing (version >= 3.5.2.2) diff --git a/zulip/integrations/zephyr/sync-public-streams b/zulip/integrations/zephyr/sync-public-streams index 0971dcd..26441db 100755 --- a/zulip/integrations/zephyr/sync-public-streams +++ b/zulip/integrations/zephyr/sync-public-streams @@ -4,7 +4,7 @@ import os import logging import optparse import time -import simplejson +import json import subprocess import unicodedata @@ -68,7 +68,7 @@ if __name__ == "__main__": continue f = open("/home/zulip/public_streams.tmp", "w") - f.write(simplejson.dumps(list(public_streams)) + "\n") + f.write(json.dumps(list(public_streams)) + "\n") f.close() subprocess.call(["mv", "/home/zulip/public_streams.tmp", "/home/zulip/public_streams"]) diff --git a/zulip/integrations/zephyr/zephyr_mirror_backend.py b/zulip/integrations/zephyr/zephyr_mirror_backend.py index 785ca93..8162aab 100755 --- a/zulip/integrations/zephyr/zephyr_mirror_backend.py +++ b/zulip/integrations/zephyr/zephyr_mirror_backend.py @@ -27,10 +27,7 @@ from types import FrameType import sys from six.moves import map from six.moves import range -try: - import simplejson -except ImportError: - import json as simplejson # type: ignore +import json import re import time import subprocess @@ -205,7 +202,7 @@ def update_subscriptions(): # type: () -> None try: f = open(options.stream_file_path, "r") - public_streams = simplejson.loads(f.read()) + public_streams = json.loads(f.read()) f.close() except Exception: logger.exception("Error reading public streams:") @@ -447,7 +444,7 @@ def process_notice(notice, log): logger.info("Received a message on %s/%s from %s..." % (zephyr_class, notice.instance, notice.sender)) if log is not None: - log.write(simplejson.dumps(zeph) + '\n') + log.write(json.dumps(zeph) + '\n') log.flush() if os.fork() == 0: @@ -552,7 +549,7 @@ def zephyr_to_zulip(options): with open(options.logs_to_resend, 'r') as log: for ln in log: try: - zeph = simplejson.loads(ln) + zeph = json.loads(ln) # New messages added to the log shouldn't have any # elements of type str (they should already all be # unicode), but older messages in the log are diff --git a/zulip/setup.py b/zulip/setup.py index 42f179b..4122a21 100755 --- a/zulip/setup.py +++ b/zulip/setup.py @@ -65,7 +65,6 @@ package_info = dict( setuptools_info = dict( install_requires=['requests>=0.12.1', - 'simplejson', 'six', 'typing>=3.5.2.2', ], @@ -80,11 +79,6 @@ except ImportError: from distutils.core import setup from distutils.version import LooseVersion # Manual dependency check - try: - import simplejson - except ImportError: - print("simplejson is not installed", file=sys.stderr) - sys.exit(1) try: import requests assert(LooseVersion(requests.__version__) >= LooseVersion('0.12.1')) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index e6bcb96..be474e5 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -23,7 +23,7 @@ from __future__ import print_function from __future__ import absolute_import from __future__ import division -import simplejson +import json import requests import time import traceback @@ -434,7 +434,7 @@ class Client(object): if isinstance(val, str) or isinstance(val, Text): request[key] = val else: - request[key] = simplejson.dumps(val) + request[key] = json.dumps(val) for f in files: req_files.append((f.name, f)) @@ -459,7 +459,7 @@ class Client(object): else: sys.stdout.write(".") sys.stdout.flush() - query_state["request"]["dont_block"] = simplejson.dumps(True) + query_state["request"]["dont_block"] = json.dumps(True) time.sleep(1) query_state["failures"] += 1 return True