commit 216e9403be1a2a5be9c0df6a4cfb4ce443677459
parent f8c592f743a63e9c73c146b1811f114f7c21c301
Author: ThomasV <thomasv@electrum.org>
Date: Mon, 4 Sep 2017 14:43:31 +0200
cleanup six (no python2 support)
Diffstat:
21 files changed, 33 insertions(+), 100 deletions(-)
diff --git a/lib/coinchooser.py b/lib/coinchooser.py
@@ -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
diff --git a/lib/commands.py b/lib/commands.py
@@ -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
@@ -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 = {}
@@ -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,
diff --git a/lib/contacts.py b/lib/contacts.py
@@ -25,7 +25,6 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
-import six
import sys
import re
diff --git a/lib/daemon.py b/lib/daemon.py
@@ -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
diff --git a/lib/dnssec.py b/lib/dnssec.py
@@ -27,7 +27,6 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
-import six
# Check DNSSEC trust chain.
@@ -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):
diff --git a/lib/exchange_rate.py b/lib/exchange_rate.py
@@ -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
diff --git a/lib/i18n.py b/lib/i18n.py
@@ -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
diff --git a/lib/interface.py b/lib/interface.py
@@ -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
diff --git a/lib/mnemonic.py b/lib/mnemonic.py
@@ -27,7 +27,6 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
-import six
import os
import hmac
diff --git a/lib/msqr.py b/lib/msqr.py
@@ -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):
diff --git a/lib/network.py b/lib/network.py
@@ -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
diff --git a/lib/old_mnemonic.py b/lib/old_mnemonic.py
@@ -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
diff --git a/lib/paymentrequest.py b/lib/paymentrequest.py
@@ -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
@@ -38,7 +37,7 @@ import traceback
import json
import requests
-from six.moves import urllib_parse
+import urllib.parse
try:
@@ -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:
@@ -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:
diff --git a/lib/pem.py b/lib/pem.py
@@ -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)
diff --git a/lib/rsakey.py b/lib/rsakey.py
@@ -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
diff --git a/lib/simple_config.py b/lib/simple_config.py
@@ -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
@@ -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)
diff --git a/lib/synchronizer.py b/lib/synchronizer.py
@@ -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
diff --git a/lib/transaction.py b/lib/transaction.py
@@ -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
diff --git a/lib/util.py b/lib/util.py
@@ -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')]
@@ -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
@@ -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)
@@ -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):
@@ -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)):
@@ -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():
@@ -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):
@@ -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
@@ -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:
@@ -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'])
@@ -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
@@ -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):
@@ -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):
diff --git a/lib/websockets.py b/lib/websockets.py
@@ -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:
diff --git a/lib/x509.py b/lib/x509.py
@@ -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