tcleanup six (no python2 support) - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 216e9403be1a2a5be9c0df6a4cfb4ce443677459 DIR parent f8c592f743a63e9c73c146b1811f114f7c21c301 HTML Author: ThomasV <thomasv@electrum.org> Date: Mon, 4 Sep 2017 14:43:31 +0200 cleanup six (no python2 support) Diffstat: M lib/coinchooser.py | 1 - M lib/commands.py | 6 ++---- M lib/contacts.py | 1 - M lib/daemon.py | 1 - M lib/dnssec.py | 3 +-- M lib/exchange_rate.py | 1 - M lib/i18n.py | 13 ++++--------- M lib/interface.py | 1 - M lib/mnemonic.py | 1 - M lib/msqr.py | 1 - M lib/network.py | 3 +-- M lib/old_mnemonic.py | 1 - M lib/paymentrequest.py | 7 +++---- M lib/pem.py | 1 - M lib/rsakey.py | 1 - M lib/simple_config.py | 9 +-------- M lib/synchronizer.py | 1 - M lib/transaction.py | 1 - M lib/util.py | 76 ++++++++----------------------- M lib/websockets.py | 3 +-- M lib/x509.py | 1 - 21 files changed, 33 insertions(+), 100 deletions(-) --- DIR diff --git a/lib/coinchooser.py b/lib/coinchooser.py t@@ -27,7 +27,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six from collections import defaultdict, namedtuple from math import floor, log10 DIR diff --git a/lib/commands.py b/lib/commands.py t@@ -27,7 +27,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six import os import sys import datetime t@@ -48,8 +47,7 @@ from .transaction import Transaction from .import paymentrequest from .paymentrequest import PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED from .import contacts -if six.PY3: - long = int + known_commands = {} t@@ -739,7 +737,7 @@ arg_types = { 'num': int, 'nbits': int, 'imax': int, - 'entropy': long, + 'entropy': int, 'tx': tx_from_str, 'pubkeys': json_loads, 'jsontx': json_loads, DIR diff --git a/lib/contacts.py b/lib/contacts.py t@@ -25,7 +25,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six import sys import re DIR diff --git a/lib/daemon.py b/lib/daemon.py t@@ -27,7 +27,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six import ast import os import sys DIR diff --git a/lib/dnssec.py b/lib/dnssec.py t@@ -27,7 +27,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six # Check DNSSEC trust chain. t@@ -75,7 +74,7 @@ def python_validate_rrsig(rrset, rrsig, keys, origin=None, now=None): from dns.dnssec import ValidationFailure, ECDSAP256SHA256, ECDSAP384SHA384 from dns.dnssec import _find_candidate_keys, _make_hash, _is_ecdsa, _is_rsa, _to_rdata, _make_algorithm_id - if isinstance(origin, six.text_type): + if isinstance(origin, str): origin = dns.name.from_text(origin, dns.name.root) for candidate_key in _find_candidate_keys(keys, rrsig): DIR diff --git a/lib/exchange_rate.py b/lib/exchange_rate.py t@@ -3,7 +3,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six from datetime import datetime import inspect import requests DIR diff --git a/lib/i18n.py b/lib/i18n.py t@@ -27,19 +27,14 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import gettext, os, six +import gettext, os LOCALE_DIR = os.path.join(os.path.dirname(__file__), 'locale') language = gettext.translation('electrum', LOCALE_DIR, fallback = True) -if six.PY2: - def _(x): - global language - return language.ugettext(x) -else: - def _(x): - global language - return language.gettext(x) +def _(x): + global language + return language.gettext(x) def set_language(x): global language DIR diff --git a/lib/interface.py b/lib/interface.py t@@ -27,7 +27,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six import os import re import socket DIR diff --git a/lib/mnemonic.py b/lib/mnemonic.py t@@ -27,7 +27,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six import os import hmac DIR diff --git a/lib/msqr.py b/lib/msqr.py t@@ -3,7 +3,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six # from http://eli.thegreenplace.net/2009/03/07/computing-modular-square-roots-in-python/ def modular_sqrt(a, p): DIR diff --git a/lib/network.py b/lib/network.py t@@ -25,9 +25,8 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six import time -from six.moves import queue +import queue import os import errno import sys DIR diff --git a/lib/old_mnemonic.py b/lib/old_mnemonic.py t@@ -27,7 +27,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six # list of words from http://en.wiktionary.org/wiki/Wiktionary:Frequency_lists/Contemporary_poetry DIR diff --git a/lib/paymentrequest.py b/lib/paymentrequest.py t@@ -27,7 +27,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six import hashlib import os.path import re t@@ -38,7 +37,7 @@ import traceback import json import requests -from six.moves import urllib_parse +import urllib.parse try: t@@ -78,7 +77,7 @@ PR_PAID = 3 # send and propagated def get_payment_request(url): - u = urllib_parse.urlparse(url) + u = urllib.parse.urlparse(url) error = None if u.scheme in ['http', 'https']: try: t@@ -277,7 +276,7 @@ class PaymentRequest: ref_out.script = transaction.Transaction.pay_script(TYPE_ADDRESS, refund_addr) paymnt.memo = "Paid using Electrum" pm = paymnt.SerializeToString() - payurl = urllib_parse.urlparse(pay_det.payment_url) + payurl = urllib.parse.urlparse(pay_det.payment_url) try: r = requests.post(payurl.geturl(), data=pm, headers=ACK_HEADERS, verify=ca_path) except requests.exceptions.SSLError: DIR diff --git a/lib/pem.py b/lib/pem.py t@@ -27,7 +27,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six # This module uses code from TLSLlite # TLSLite Author: Trevor Perrin) DIR diff --git a/lib/rsakey.py b/lib/rsakey.py t@@ -38,7 +38,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six import os import math import base64 DIR diff --git a/lib/simple_config.py b/lib/simple_config.py t@@ -3,7 +3,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six import ast import json import threading t@@ -257,13 +256,7 @@ def read_system_config(path=SYSTEM_CONFIG_PATH): """Parse and return the system config settings in /etc/electrum.conf.""" result = {} if os.path.exists(path): - try: - from six.moves import configparser - # import ConfigParser - except ImportError: - print("cannot parse electrum.conf. please install ConfigParser") - return - + import configparser p = configparser.ConfigParser() try: p.read(path) DIR diff --git a/lib/synchronizer.py b/lib/synchronizer.py t@@ -27,7 +27,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six from threading import Lock import hashlib DIR diff --git a/lib/transaction.py b/lib/transaction.py t@@ -41,7 +41,6 @@ import struct # Workalike python implementation of Bitcoin's CDataStream class. # import struct -from six import StringIO import random from .keystore import xpubkey_to_address, xpubkey_to_pubkey DIR diff --git a/lib/util.py b/lib/util.py t@@ -36,14 +36,9 @@ import threading from .i18n import _ -import six -from six.moves import queue, urllib_parse -try: - import urllib.parse - import urllib.request, urllib.parse, urllib.error -except ImportError: - pass +import urllib.request, urllib.parse, urllib.error +import queue base_units = {'BTC':8, 'mBTC':5, 'uBTC':2} fee_levels = [_('Within 25 blocks'), _('Within 10 blocks'), _('Within 5 blocks'), _('Within 2 blocks'), _('In the next block')] t@@ -254,18 +249,9 @@ def assert_bytes(*args): """ porting helper, assert args type """ - if six.PY2: - for x in args: - assert isinstance(x, (bytes, bytearray, str)) - return - try: - if six.PY3: - for x in args: - assert isinstance(x, (bytes, bytearray)) - else: - for x in args: - assert isinstance(x, bytearray) + for x in args: + assert isinstance(x, (bytes, bytearray)) except: print('assert bytes failed', list(map(type, args))) raise t@@ -276,7 +262,7 @@ def assert_str(*args): porting helper, assert args type """ for x in args: - assert isinstance(x, six.string_types) + assert isinstance(x, str) t@@ -310,11 +296,8 @@ def hfu(x): :param x: str :return: str """ - if six.PY3: - assert_bytes(x) - return binascii.hexlify(x) - else: - return x.encode('hex') + assert_bytes(x) + return binascii.hexlify(x) def bfh(x): t@@ -323,7 +306,7 @@ def bfh(x): :param x: str :rtype: bytes """ - if isinstance(x, six.string_types): + if isinstance(x, str): return bfh_builder(x) # TODO: check for iterator interface elif isinstance(x, (list, tuple, map)): t@@ -340,15 +323,8 @@ def bh2u(x): :param x: bytes :rtype: str """ - if six.PY3: - assert_bytes(x) - # x = to_bytes(x, 'ascii') - return binascii.hexlify(x).decode('ascii') - else: - if isinstance(x, bytearray): - return binascii.hexlify(x) - else: - return x.encode('hex') + assert_bytes(x) + return binascii.hexlify(x).decode('ascii') def user_dir(): t@@ -392,8 +368,6 @@ def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespa if whitespaces: result += " " * (decimal_point - len(fract_part)) result = " " * (15 - len(result)) + result - if six.PY2: - result = result.decode('utf8') return result def timestamp_to_datetime(timestamp): t@@ -529,7 +503,7 @@ def parse_URI(uri, on_pr=None): raise BaseException("Not a bitcoin address") return {'address': uri} - u = urllib_parse.urlparse(uri) + u = urllib.parse.urlparse(uri) if u.scheme != 'bitcoin': raise BaseException("Not a bitcoin URI") address = u.path t@@ -537,9 +511,9 @@ def parse_URI(uri, on_pr=None): # python for android fails to parse query if address.find('?') > 0: address, query = u.path.split('?') - pq = urllib_parse.parse_qs(query) + pq = urllib.parse.parse_qs(query) else: - pq = urllib_parse.parse_qs(u.query) + pq = urllib.parse.parse_qs(u.query) for k, v in pq.items(): if len(v)!=1: t@@ -560,10 +534,7 @@ def parse_URI(uri, on_pr=None): amount = Decimal(am) * COIN out['amount'] = int(amount) if 'message' in out: - if six.PY3: - out['message'] = out['message'] - else: - out['message'] = out['message'].decode('utf8') + out['message'] = out['message'] out['memo'] = out['message'] if 'time' in out: out['time'] = int(out['time']) t@@ -600,11 +571,9 @@ def create_URI(addr, amount, message): if amount: query.append('amount=%s'%format_satoshis_plain(amount)) if message: - if six.PY2 and type(message) == unicode: - message = message.encode('utf8') query.append('message=%s'%urllib.parse.quote(message)) - p = urllib_parse.ParseResult(scheme='bitcoin', netloc='', path=addr, params='', query='&'.join(query), fragment='') - return urllib_parse.urlunparse(p) + p = urllib.parse.ParseResult(scheme='bitcoin', netloc='', path=addr, params='', query='&'.join(query), fragment='') + return urllib.parse.urlunparse(p) # Python bug (http://bugs.python.org/issue1927) causes raw_input t@@ -615,14 +584,9 @@ def raw_input(prompt=None): sys.stdout.write(prompt) return builtin_raw_input() -if six.PY2: - import __builtin__ - builtin_raw_input = __builtin__.raw_input - __builtin__.raw_input = raw_input -else: - import builtins - builtin_raw_input = builtins.input - builtins.input = raw_input +import builtins +builtin_raw_input = builtins.input +builtins.input = raw_input def parse_json(message): t@@ -772,7 +736,7 @@ def check_www_dir(rdir): "https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" ] for URL in files: - path = urllib_parse.urlsplit(URL).path + path = urllib.parse.urlsplit(URL).path filename = os.path.basename(path) path = os.path.join(rdir, filename) if not os.path.exists(path): DIR diff --git a/lib/websockets.py b/lib/websockets.py t@@ -27,8 +27,7 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six -from six.moves import queue +import queue import threading, os, json, time from collections import defaultdict try: DIR diff --git a/lib/x509.py b/lib/x509.py t@@ -27,7 +27,6 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals -import six from datetime import datetime import sys from . import util