From c01716a6c07cd04ca74daed1b6cfc863667977b2 Mon Sep 17 00:00:00 2001 From: hackrush Date: Sat, 21 Jul 2018 22:42:23 +0530 Subject: [PATCH] Using simplejson and fixed some encodes and decodes --- build/upload_assets.py | 2 +- lbrynet/conf.py | 2 +- lbrynet/core/StreamDescriptor.py | 2 +- lbrynet/core/client/ClientProtocol.py | 2 +- lbrynet/core/server/ServerRequestHandler.py | 2 +- lbrynet/core/system_info.py | 2 +- lbrynet/core/utils.py | 2 +- lbrynet/daemon/Daemon.py | 2 +- lbrynet/daemon/DaemonCLI.py | 2 +- lbrynet/daemon/ExchangeRateManager.py | 2 +- lbrynet/daemon/auth/client.py | 2 +- lbrynet/daemon/auth/server.py | 2 +- lbrynet/daemon/auth/util.py | 2 +- lbrynet/database/migrator/migrate5to6.py | 2 +- lbrynet/database/storage.py | 5 +++-- lbrynet/lbry_file/client/EncryptedFileDownloader.py | 2 +- lbrynet/reflector/client/blob.py | 2 +- lbrynet/reflector/client/client.py | 2 +- lbrynet/reflector/server/server.py | 2 +- scripts/download_blobs_from_reflector.py | 2 +- scripts/migrate_lbryum_to_lbrycrd.py | 2 +- scripts/reseed_file.py | 2 +- scripts/seed_node.py | 2 +- setup.py | 3 ++- tests/unit/lbrynet_daemon/test_Daemon.py | 2 +- tests/unit/test_conf.py | 2 +- 26 files changed, 29 insertions(+), 27 deletions(-) diff --git a/build/upload_assets.py b/build/upload_assets.py index b33ff9f31..5ba6d6b89 100644 --- a/build/upload_assets.py +++ b/build/upload_assets.py @@ -1,5 +1,5 @@ import glob -import json +import simplejson as json import os import subprocess import sys diff --git a/lbrynet/conf.py b/lbrynet/conf.py index 01b3f22f7..e9ae8acec 100644 --- a/lbrynet/conf.py +++ b/lbrynet/conf.py @@ -1,5 +1,5 @@ import base58 -import json +import simplejson as json import logging import os import re diff --git a/lbrynet/core/StreamDescriptor.py b/lbrynet/core/StreamDescriptor.py index 0d0b2a4c2..a18ef7d02 100644 --- a/lbrynet/core/StreamDescriptor.py +++ b/lbrynet/core/StreamDescriptor.py @@ -1,6 +1,6 @@ import binascii from collections import defaultdict -import json +import simplejson as json import logging from twisted.internet import threads, defer diff --git a/lbrynet/core/client/ClientProtocol.py b/lbrynet/core/client/ClientProtocol.py index 755f6194e..3844bcb7a 100644 --- a/lbrynet/core/client/ClientProtocol.py +++ b/lbrynet/core/client/ClientProtocol.py @@ -1,4 +1,4 @@ -import json +import simplejson as json import logging from decimal import Decimal from twisted.internet import error, defer diff --git a/lbrynet/core/server/ServerRequestHandler.py b/lbrynet/core/server/ServerRequestHandler.py index 3ed65023e..8c46170b9 100644 --- a/lbrynet/core/server/ServerRequestHandler.py +++ b/lbrynet/core/server/ServerRequestHandler.py @@ -1,4 +1,4 @@ -import json +import simplejson as json import logging from twisted.internet import defer diff --git a/lbrynet/core/system_info.py b/lbrynet/core/system_info.py index 9725f3c7f..b2c9092cb 100644 --- a/lbrynet/core/system_info.py +++ b/lbrynet/core/system_info.py @@ -1,7 +1,7 @@ from __future__ import print_function import platform -import json +import simplejson as json import subprocess import os diff --git a/lbrynet/core/utils.py b/lbrynet/core/utils.py index 72eacee55..6abb9f713 100644 --- a/lbrynet/core/utils.py +++ b/lbrynet/core/utils.py @@ -4,7 +4,7 @@ import datetime import random import socket import string -import json +import simplejson as json import traceback import functools import logging diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index b3a0c22f5..dfe496f41 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -3,7 +3,7 @@ import mimetypes import os import requests import urllib -import json +import simplejson as json import textwrap import signal from binascii import hexlify, unhexlify, b2a_hex diff --git a/lbrynet/daemon/DaemonCLI.py b/lbrynet/daemon/DaemonCLI.py index 3cecc7c42..6ad7405f9 100644 --- a/lbrynet/daemon/DaemonCLI.py +++ b/lbrynet/daemon/DaemonCLI.py @@ -1,4 +1,4 @@ -import json +import simplejson as json import os import sys import colorama diff --git a/lbrynet/daemon/ExchangeRateManager.py b/lbrynet/daemon/ExchangeRateManager.py index acafe77d4..0c0b9ab84 100644 --- a/lbrynet/daemon/ExchangeRateManager.py +++ b/lbrynet/daemon/ExchangeRateManager.py @@ -1,6 +1,6 @@ import time import logging -import json +import simplejson as json import treq from twisted.internet import defer diff --git a/lbrynet/daemon/auth/client.py b/lbrynet/daemon/auth/client.py index 6c81eb686..588ec9d56 100644 --- a/lbrynet/daemon/auth/client.py +++ b/lbrynet/daemon/auth/client.py @@ -1,5 +1,5 @@ import os -import json +import simplejson as json import urlparse import requests from requests.cookies import RequestsCookieJar diff --git a/lbrynet/daemon/auth/server.py b/lbrynet/daemon/auth/server.py index 74766e262..980af9524 100644 --- a/lbrynet/daemon/auth/server.py +++ b/lbrynet/daemon/auth/server.py @@ -1,6 +1,6 @@ import logging from six.moves.urllib import parse as urlparse -import json +import simplejson as json import inspect import signal diff --git a/lbrynet/daemon/auth/util.py b/lbrynet/daemon/auth/util.py index 3e12d2b51..35ac1e464 100644 --- a/lbrynet/daemon/auth/util.py +++ b/lbrynet/daemon/auth/util.py @@ -3,7 +3,7 @@ import hmac import hashlib import yaml import os -import json +import simplejson as json import logging log = logging.getLogger(__name__) diff --git a/lbrynet/database/migrator/migrate5to6.py b/lbrynet/database/migrator/migrate5to6.py index 82518e81c..8ffef1765 100644 --- a/lbrynet/database/migrator/migrate5to6.py +++ b/lbrynet/database/migrator/migrate5to6.py @@ -1,6 +1,6 @@ import sqlite3 import os -import json +import simplejson as json import logging from lbryschema.decode import smart_decode from lbrynet import conf diff --git a/lbrynet/database/storage.py b/lbrynet/database/storage.py index da724d2e1..2e80ed6e0 100644 --- a/lbrynet/database/storage.py +++ b/lbrynet/database/storage.py @@ -268,7 +268,7 @@ class SQLiteStorage(WalletDatabase): blob_hashes = yield self.run_and_return_list( "select blob_hash from blob where status='finished'" ) - defer.returnValue([blob_hash.decode('hex') for blob_hash in blob_hashes]) + defer.returnValue([bytes.fromhex(blob_hash).decode('latin-1') for blob_hash in blob_hashes]) def count_finished_blobs(self): return self.run_and_return_one_or_none( @@ -492,7 +492,8 @@ class SQLiteStorage(WalletDatabase): @defer.inlineCallbacks def save_downloaded_file(self, stream_hash, file_name, download_directory, data_payment_rate): # touch the closest available file to the file name - file_name = yield open_file_for_writing(download_directory.decode('hex'), file_name.decode('hex')) + file_name = yield open_file_for_writing(bytes.fromhex(download_directory).decode(), + bytes.fromhex(file_name).decode()) result = yield self.save_published_file( stream_hash, file_name.encode('hex'), download_directory, data_payment_rate ) diff --git a/lbrynet/lbry_file/client/EncryptedFileDownloader.py b/lbrynet/lbry_file/client/EncryptedFileDownloader.py index 4a4ff5de6..a0507cda5 100644 --- a/lbrynet/lbry_file/client/EncryptedFileDownloader.py +++ b/lbrynet/lbry_file/client/EncryptedFileDownloader.py @@ -181,7 +181,7 @@ class EncryptedFileSaver(EncryptedFileDownloader): class EncryptedFileSaverFactory(EncryptedFileDownloaderFactory): def __init__(self, peer_finder, rate_limiter, blob_manager, storage, wallet, download_directory): EncryptedFileDownloaderFactory.__init__(self, peer_finder, rate_limiter, blob_manager, storage, wallet) - self.download_directory = binascii.hexlify(download_directory) + self.download_directory = binascii.hexlify(download_directory.encode()) def _make_downloader(self, stream_hash, payment_rate_manager, stream_info): stream_name = stream_info.raw_info['stream_name'] diff --git a/lbrynet/reflector/client/blob.py b/lbrynet/reflector/client/blob.py index d2533cb02..1c2d02dab 100644 --- a/lbrynet/reflector/client/blob.py +++ b/lbrynet/reflector/client/blob.py @@ -1,4 +1,4 @@ -import json +import simplejson as json import logging from twisted.protocols.basic import FileSender diff --git a/lbrynet/reflector/client/client.py b/lbrynet/reflector/client/client.py index 1dd33144e..c1fe6f4c9 100644 --- a/lbrynet/reflector/client/client.py +++ b/lbrynet/reflector/client/client.py @@ -1,4 +1,4 @@ -import json +import simplejson as json import logging from twisted.internet.error import ConnectionRefusedError diff --git a/lbrynet/reflector/server/server.py b/lbrynet/reflector/server/server.py index c2ac4a3b6..21bf5fa53 100644 --- a/lbrynet/reflector/server/server.py +++ b/lbrynet/reflector/server/server.py @@ -1,5 +1,5 @@ import logging -import json +import simplejson as json from twisted.python import failure from twisted.internet import error, defer from twisted.internet.protocol import Protocol, ServerFactory diff --git a/scripts/download_blobs_from_reflector.py b/scripts/download_blobs_from_reflector.py index 19a0ac219..68d8b05f6 100644 --- a/scripts/download_blobs_from_reflector.py +++ b/scripts/download_blobs_from_reflector.py @@ -1,7 +1,7 @@ """A test script that downloads blobs from a reflector server""" import argparse import itertools -import json +import simplejson as json import random import subprocess import sys diff --git a/scripts/migrate_lbryum_to_lbrycrd.py b/scripts/migrate_lbryum_to_lbrycrd.py index fdafacd6e..69cf03199 100644 --- a/scripts/migrate_lbryum_to_lbrycrd.py +++ b/scripts/migrate_lbryum_to_lbrycrd.py @@ -1,6 +1,6 @@ import argparse import hashlib -import json +import simplejson as json import subprocess import sys diff --git a/scripts/reseed_file.py b/scripts/reseed_file.py index 0068ce5c8..9e21155d3 100644 --- a/scripts/reseed_file.py +++ b/scripts/reseed_file.py @@ -7,7 +7,7 @@ the new blobs to the manager. import argparse import binascii import logging -import json +import simplejson as json import os import sys diff --git a/scripts/seed_node.py b/scripts/seed_node.py index c94d55de0..4cbed1a9a 100644 --- a/scripts/seed_node.py +++ b/scripts/seed_node.py @@ -1,5 +1,5 @@ import struct -import json +import simplejson as json import logging import argparse import hashlib diff --git a/setup.py b/setup.py index e10622e83..4eac34939 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,8 @@ requires = [ 'colorama==0.3.7', 'six', 'pyopenssl', - 'service-identity' + 'service-identity', + 'simplejson' ] console_scripts = [ diff --git a/tests/unit/lbrynet_daemon/test_Daemon.py b/tests/unit/lbrynet_daemon/test_Daemon.py index 31bf90407..77b4ed0b7 100644 --- a/tests/unit/lbrynet_daemon/test_Daemon.py +++ b/tests/unit/lbrynet_daemon/test_Daemon.py @@ -1,5 +1,5 @@ import mock -import json +import simplejson as json import random from os import path diff --git a/tests/unit/test_conf.py b/tests/unit/test_conf.py index 4675cc8e7..2044dd988 100644 --- a/tests/unit/test_conf.py +++ b/tests/unit/test_conf.py @@ -1,5 +1,5 @@ import os -import json +import simplejson as json import sys import tempfile from unittest import skipIf