Skip to content
This repository was archived by the owner on Mar 9, 2024. It is now read-only.

Commit 8e5bab7

Browse files
committed
Drop support for python 2.x
1 parent 78962ff commit 8e5bab7

17 files changed

+36
-95
lines changed

monero/address.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from binascii import hexlify, unhexlify
22
import re
3-
import six
43
import struct
5-
import warnings
64

75
from . import base58
86
from . import const
@@ -66,10 +64,8 @@ def __repr__(self):
6664
return base58.encode(hexlify(self._decoded))
6765

6866
def __eq__(self, other):
69-
if isinstance(other, BaseAddress):
67+
if isinstance(other, (BaseAddress, str)):
7068
return str(self) == str(other)
71-
elif isinstance(other, six.text_type) or isinstance(other, six.string_types):
72-
return str(self) == six.ensure_str(other)
7369
return super(BaseAddress, self).__eq__(other)
7470

7571
def __hash__(self):

monero/backends/jsonrpc/daemon.py

+15-31
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
from __future__ import unicode_literals
21
import binascii
32
from datetime import datetime
43
from decimal import Decimal
54
import ipaddress
65
import json
76
import logging
87
import requests
9-
import six
108

119
from ... import address
1210
from ... import exceptions
@@ -134,7 +132,7 @@ def send_transaction(self, blob, relay=True):
134132
res = self.raw_request(
135133
"/sendrawtransaction",
136134
{
137-
"tx_as_hex": six.ensure_text(binascii.hexlify(blob)),
135+
"tx_as_hex": binascii.hexlify(blob).decode(),
138136
"do_not_relay": not relay,
139137
},
140138
)
@@ -388,14 +386,11 @@ def submit_block(self, blobs):
388386
}
389387
"""
390388

391-
if isinstance(blobs, (six.binary_type,) + six.string_types):
389+
if isinstance(blobs, (bytes, str)):
392390
blobs = [blobs]
393391

394392
blobs = [
395-
binascii.hexlify(b).decode()
396-
if isinstance(b, six.binary_type)
397-
else six.ensure_text(b)
398-
for b in blobs
393+
binascii.hexlify(b).decode() if isinstance(b, bytes) else b for b in blobs
399394
]
400395

401396
return self.raw_jsonrpc_request("submit_block", params=blobs)
@@ -707,9 +702,7 @@ def set_bans(self, ip, ban, seconds=None):
707702
}
708703
"""
709704

710-
if isinstance(
711-
ip, six.string_types + six.integer_types
712-
): # If single element paramters
705+
if isinstance(ip, (str, int)): # If single element paramters
713706
user_bans = [{"ip": ip, "ban": ban, "seconds": seconds}]
714707
else: # If params are iterables, contrust the list of ban entries
715708
if not (len(ip) == len(ban) == len(seconds)):
@@ -736,7 +729,7 @@ def set_bans(self, ip, ban, seconds=None):
736729
raise ValueError('"seconds" can not be less than zero')
737730

738731
ban = {}
739-
if isinstance(curr_ip, six.integer_types):
732+
if isinstance(curr_ip, int):
740733
ban["ip"] = curr_ip
741734
else:
742735
ban["host"] = curr_ip
@@ -823,7 +816,7 @@ def get_output_histogram(
823816
"""
824817

825818
# Coerce amounts paramter
826-
if isinstance(amounts, (Decimal,) + six.integer_types):
819+
if isinstance(amounts, (Decimal, int)):
827820
amounts = [to_atomic(amounts) if isinstance(amounts, Decimal) else amounts]
828821
elif amounts is None:
829822
raise ValueError("amounts is None")
@@ -893,7 +886,7 @@ def get_fee_estimate(self, grace_blocks=None):
893886
}
894887
"""
895888

896-
if not isinstance(grace_blocks, (type(None),) + six.integer_types):
889+
if not isinstance(grace_blocks, (type(None), int)):
897890
raise TypeError("grace_blocks is not an int")
898891
elif grace_blocks is not None and grace_blocks < 0:
899892
raise ValueError("grace_blocks < 0")
@@ -1106,9 +1099,6 @@ def send_raw_transaction(self, tx_as_hex, do_not_relay=False):
11061099
"untrusted": bool; True for bootstrap mode, False for full sync mode.
11071100
}
11081101
"""
1109-
1110-
tx_as_hex = six.ensure_text(tx_as_hex)
1111-
11121102
return self.raw_request(
11131103
"/send_raw_transaction",
11141104
data={"tx_as_hex": tx_as_hex, "do_not_relay": do_not_relay},
@@ -1287,7 +1277,7 @@ def set_log_categories(self, categories=None):
12871277

12881278
if not categories:
12891279
return self.raw_request("/set_log_categories")
1290-
elif isinstance(categories, six.string_types):
1280+
elif isinstance(categories, str):
12911281
categories = categories.split(",")
12921282

12931283
# Validate categories
@@ -1489,12 +1479,10 @@ def get_outs(self, amount, index, get_txid=True):
14891479
}
14901480
"""
14911481

1492-
if isinstance(index, six.integer_types): # single element
1482+
if isinstance(index, int): # single element
14931483
outputs = [
14941484
{
1495-
"amount": amount
1496-
if isinstance(amount, six.integer_types)
1497-
else to_atomic(amount),
1485+
"amount": amount,
14981486
"index": index,
14991487
}
15001488
]
@@ -1506,9 +1494,7 @@ def get_outs(self, amount, index, get_txid=True):
15061494
for a, i in zip(amount, index):
15071495
outputs.append(
15081496
{
1509-
"amount": a
1510-
if isinstance(a, six.integer_types)
1511-
else to_atomic(a),
1497+
"amount": a if isinstance(a, int) else to_atomic(a),
15121498
"index": i,
15131499
}
15141500
)
@@ -1537,10 +1523,6 @@ def update(self, command, path=None):
15371523
"status": str; General RPC error code. "OK" means everything looks good.
15381524
}
15391525
"""
1540-
1541-
command = six.ensure_text(command)
1542-
path = six.ensure_text(path) if path is not None else None
1543-
15441526
if command not in ("check", "download"):
15451527
raise ValueError('unrecognized command: "{}"'.format(command))
15461528

@@ -1620,10 +1602,12 @@ def _validate_hashlist(self, hashes):
16201602
if not hashes:
16211603
return []
16221604
else:
1623-
if isinstance(hashes, six.string_types):
1605+
if isinstance(hashes, str):
16241606
hashes = [hashes]
16251607
else:
1626-
coerce_compatible_str = lambda s: six.ensure_text(str(s))
1608+
coerce_compatible_str = (
1609+
lambda s: s.decode() if isinstance(s, bytes) else s
1610+
)
16271611
hashes = list(map(coerce_compatible_str, hashes))
16281612

16291613
not_valid = lambda h: not self._is_valid_256_hex(h)

monero/backends/jsonrpc/wallet.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import unicode_literals
21
import binascii
32
from datetime import datetime
43
import json

monero/block.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import operator
2-
import six
32
from .transaction import Transaction
43

54

@@ -43,12 +42,12 @@ def __init__(self, **kwargs):
4342
def __eq__(self, other):
4443
if isinstance(other, Block):
4544
return self.hash == other.hash
46-
elif isinstance(other, six.string_types):
47-
return six.ensure_text(self.hash) == six.ensure_text(other)
45+
elif isinstance(other, str):
46+
return self.hash == other
4847
return super(Block, self).__eq__(other)
4948

5049
def __contains__(self, tx):
51-
if isinstance(tx, six.string_types):
50+
if isinstance(tx, str):
5251
txid = tx
5352
elif isinstance(tx, Transaction):
5453
txid = tx.hash

monero/daemon.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import six
2-
31
from .backends.jsonrpc import JSONRPCDaemon
42

53

@@ -85,6 +83,6 @@ def transactions(self, hashes):
8583
8684
:param hashes: str or list of str
8785
"""
88-
if isinstance(hashes, six.string_types):
86+
if isinstance(hashes, str):
8987
hashes = [hashes]
9088
return self._backend.transactions(hashes)

monero/numbers.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from decimal import Decimal
2-
import six
32

43
PICONERO = Decimal("0.000000000001")
54
EMPTY_KEY = "0" * 64
65

76

87
def to_atomic(amount):
98
"""Convert Monero decimal to atomic integer of piconero."""
10-
if not isinstance(amount, (Decimal, float) + six.integer_types):
9+
if not isinstance(amount, (Decimal, int, float)):
1110
raise ValueError(
1211
"Amount '{}' doesn't have numeric type. Only Decimal, int, long and "
1312
"float (not recommended) are accepted as amounts.".format(amount)
@@ -41,11 +40,9 @@ class PaymentID(object):
4140
def __init__(self, payment_id):
4241
if isinstance(payment_id, PaymentID):
4342
payment_id = int(payment_id)
44-
if isinstance(payment_id, six.text_type) or isinstance(
45-
payment_id, six.string_types
46-
):
43+
if isinstance(payment_id, str):
4744
payment_id = int(payment_id, 16)
48-
elif not isinstance(payment_id, six.integer_types):
45+
elif not isinstance(payment_id, int):
4946
raise TypeError(
5047
"payment_id must be either int or hexadecimal str or bytes, "
5148
"is {0}".format(type(payment_id))
@@ -72,8 +69,8 @@ def __int__(self):
7269
def __eq__(self, other):
7370
if isinstance(other, PaymentID):
7471
return int(self) == int(other)
75-
elif isinstance(other, six.integer_types):
72+
elif isinstance(other, int):
7673
return int(self) == other
77-
elif isinstance(other, six.text_type) or isinstance(other, six.string_types):
78-
return str(self) == six.ensure_str(other)
74+
elif isinstance(other, str):
75+
return str(self) == other
7976
return super(PaymentID, self).__eq__(other)

monero/transaction/__init__.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import itertools
33
import operator
44
import re
5-
import six
65
import struct
76
import varint
87
import warnings
@@ -461,9 +460,7 @@ def __init__(self, **filterparams):
461460
if _local_address is None:
462461
self.local_addresses = []
463462
else:
464-
if isinstance(_local_address, six.string_types) or isinstance(
465-
_local_address, six.text_type
466-
):
463+
if isinstance(_local_address, str):
467464
local_addresses = [_local_address]
468465
else:
469466
try:
@@ -475,9 +472,7 @@ def __init__(self, **filterparams):
475472
if _tx_id is None:
476473
self.tx_ids = []
477474
else:
478-
if isinstance(_tx_id, six.string_types) or isinstance(
479-
_tx_id, six.text_type
480-
):
475+
if isinstance(_tx_id, str):
481476
tx_ids = [_tx_id]
482477
else:
483478
try:
@@ -489,9 +484,7 @@ def __init__(self, **filterparams):
489484
if _payment_id is None:
490485
self.payment_ids = []
491486
else:
492-
if isinstance(_payment_id, six.string_types) or isinstance(
493-
_payment_id, six.text_type
494-
):
487+
if isinstance(_payment_id, str):
495488
payment_ids = [_payment_id]
496489
else:
497490
try:

monero/transaction/extra.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import binascii
2-
import six
32
import varint
43

54

monero/wordlists/wordlist.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import logging
55
from binascii import crc32
66

7-
from six import with_metaclass
8-
97

108
WORDLISTS = {}
119
_log = logging.getLogger(__name__)
@@ -40,7 +38,7 @@ def __new__(cls, name, bases, attrs):
4038
return new_cls
4139

4240

43-
class Wordlist(with_metaclass(WordlistType)):
41+
class Wordlist(metaclass=WordlistType):
4442
n = 1626
4543

4644
@classmethod

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ pycryptodomex~=3.14
22
pynacl~=1.4
33
pysocks~=1.7
44
requests
5-
six>=1.12.0
65
ipaddress
76
varint

setup.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
31
import codecs
42
import os
53
import re
6-
import sys
74
from distutils.core import setup
85

96
from setuptools import find_packages
@@ -33,11 +30,7 @@ def find_version(*parts):
3330
url="https://github.com/monero-ecosystem/monero-python/",
3431
long_description=open("README.rst", "rb").read().decode("utf-8"),
3532
install_requires=open("requirements.txt", "r").read().splitlines(),
36-
tests_require=open(
37-
"test_requirements_py{:d}.txt".format(sys.version_info.major), "r"
38-
)
39-
.read()
40-
.splitlines(),
33+
tests_require=open("test_requirements.txt", "r").read().splitlines(),
4134
packages=find_packages(".", exclude=["tests"]),
4235
include_package_data=True,
4336
author="Michał Sałaban",
@@ -49,7 +42,6 @@ def find_version(*parts):
4942
"License :: OSI Approved :: BSD License",
5043
"Operating System :: OS Independent",
5144
"Programming Language :: Python",
52-
"Programming Language :: Python :: 2.7",
5345
"Programming Language :: Python :: 3.6",
5446
"Programming Language :: Python :: 3.7",
5547
"Programming Language :: Python :: 3.8",
File renamed without changes.

test_requirements_py2.txt

-7
This file was deleted.

tests/test_block.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from datetime import datetime
2-
import six
32
import unittest
43

54
from monero.block import Block

tests/test_jsonrpcdaemon.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44
import os
55
import responses
6-
import six
76

87
from monero.const import NET_STAGE
98
from monero.daemon import Daemon
@@ -867,7 +866,7 @@ def test_set_bans_single(self):
867866
status=200,
868867
)
869868

870-
resp = self.backend.set_bans(six.ensure_text("188.165.17.204"), True, 3600)
869+
resp = self.backend.set_bans("188.165.17.204", True, 3600)
871870

872871
self.assertEqual(resp["status"], "OK")
873872

@@ -881,9 +880,9 @@ def test_set_bans_multiple(self):
881880
)
882881

883882
ips = [
884-
six.ensure_text("188.165.17.204"),
883+
"188.165.17.204",
885884
1466097787,
886-
six.ensure_text("87.98.224.124"),
885+
"87.98.224.124",
887886
]
888887
bans = [True, True, False]
889888
seconds = [3600, 500, 7200]

0 commit comments

Comments
 (0)