Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Commit 10f3f41

Browse files
committed
Remove PY2 compatibility code
Python 2 is no longer supported in PyOTA. Remove glue code that made it possible to run the same code on both versions, as it is no longer needed. Changes: - Remove imports from `six` package - Remove imports from `__future__` package - Add some Py3 syntax - Remove encoding spec from files as PY3's default is utf-8 - Update setup.py, simplify dependencies, include metadata in the built sdist and wheel about supported python version - Remove `noinspection` comments
1 parent 25d3914 commit 10f3f41

File tree

156 files changed

+191
-1147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+191
-1147
lines changed

examples/address_generator.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
# coding=utf-8
21
"""
32
Generates a shiny new IOTA address that you can use for transfers!
43
"""
54

6-
from __future__ import absolute_import, division, print_function, \
7-
unicode_literals
8-
95
from argparse import ArgumentParser
106
from getpass import getpass as secure_input
117
from sys import argv
128
from typing import Optional, Text
139

14-
from six import binary_type, moves as compat, text_type
15-
1610
from iota import Iota, __version__
1711
from iota.crypto.addresses import AddressGenerator
1812
from iota.crypto.types import Seed
@@ -38,13 +32,13 @@ def main(uri, index, count, security, checksum):
3832
# Here's where all the magic happens!
3933
api_response = api.get_new_addresses(index, count, security, checksum)
4034
for addy in api_response['addresses']:
41-
print(binary_type(addy).decode('ascii'))
35+
print(bytes(addy).decode('ascii'))
4236

4337
print('')
4438

4539

4640
def get_seed():
47-
# type: () -> binary_type
41+
# type: () -> bytes
4842
"""
4943
Prompts the user securely for their seed.
5044
"""
@@ -66,18 +60,18 @@ def output_seed(seed):
6660
'WARNING: Anyone who has your seed can spend your IOTAs! '
6761
'Clear the screen after recording your seed!'
6862
)
69-
compat.input('')
63+
input('')
7064
print('Your seed is:')
7165
print('')
72-
print(binary_type(seed).decode('ascii'))
66+
print(bytes(seed).decode('ascii'))
7367
print('')
7468

7569
print(
7670
'Clear the screen to prevent shoulder surfing, '
7771
'and press return to continue.'
7872
)
7973
print('https://en.wikipedia.org/wiki/Shoulder_surfing_(computer_security)')
80-
compat.input('')
74+
input('')
8175

8276

8377
if __name__ == '__main__':
@@ -88,7 +82,7 @@ def output_seed(seed):
8882

8983
parser.add_argument(
9084
'--uri',
91-
type=text_type,
85+
type=str,
9286
default='http://localhost:14265/',
9387

9488
help=(

examples/hello_world.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
# coding=utf-8
21
"""
32
Simple "Hello, world!" example that sends a `getNodeInfo` command to
43
your friendly neighborhood node.
54
"""
65

7-
from __future__ import absolute_import, division, print_function, \
8-
unicode_literals
9-
106
from argparse import ArgumentParser
117
from pprint import pprint
128
from sys import argv
139
from typing import Text
1410
from httpx.exceptions import NetworkError
15-
from six import text_type
1611

1712
from iota import BadApiResponse, StrictIota, __version__
1813

@@ -44,7 +39,7 @@ def main(uri):
4439

4540
parser.add_argument(
4641
'--uri',
47-
type=text_type,
42+
type=str,
4843
default='http://localhost:14265/',
4944

5045
help=(

examples/local_pow.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from __future__ import absolute_import, division, print_function, \
2-
unicode_literals
3-
41
import iota
52
from pprint import pprint
63

examples/mam_js_send.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# coding=utf-8
2-
from __future__ import absolute_import, division, print_function, \
3-
unicode_literals
41

52
import codecs
63
import json
@@ -10,7 +7,6 @@
107
from typing import List, Optional, Text
118

129
import filters as f
13-
from six import binary_type, text_type
1410

1511
from iota import Bundle, Iota, TransactionTrytes
1612
from iota.bin import IotaCommandLineApp
@@ -71,14 +67,14 @@ def execute(self, api, **arguments):
7167
mam_encrypt_path,
7268

7369
# Required arguments
74-
binary_type(api.seed),
70+
bytes(api.seed),
7571
message,
7672

7773
# Options
78-
'--channel-key-index', text_type(channel_key_index),
79-
'--start', text_type(start),
80-
'--count', text_type(count),
81-
'--security-level', text_type(security_level),
74+
'--channel-key-index', str(channel_key_index),
75+
'--start', str(start),
76+
'--count', str(count),
77+
'--security-level', str(security_level),
8278
],
8379

8480
check=True,

examples/multisig.py

-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding=utf-8
21
"""
32
Example of how to use PyOTA's multisig feature.
43
@@ -10,9 +9,6 @@
109
- https://github.com/iotaledger/wiki/blob/master/multisigs.md
1110
"""
1211

13-
from __future__ import absolute_import, division, print_function, \
14-
unicode_literals
15-
1612
from typing import List
1713

1814
from iota import Address, Bundle, BundleValidator, ProposedTransaction, Tag, \
@@ -35,7 +31,6 @@
3531
##
3632
# Create digest 1 of 3.
3733
#
38-
# noinspection SpellCheckingInspection
3934
api_1 = MultisigIota(
4035
adapter='http://localhost:14265',
4136

@@ -64,7 +59,6 @@
6459
##
6560
# Create digest 2 of 3.
6661
#
67-
# noinspection SpellCheckingInspection
6862
api_2 = MultisigIota(
6963
adapter='http://localhost:14265',
7064

@@ -83,7 +77,6 @@
8377
##
8478
# Create digest 3 of 3.
8579
#
86-
# noinspection SpellCheckingInspection
8780
api_3 = MultisigIota(
8881
adapter='http://localhost:14265',
8982

@@ -128,7 +121,6 @@
128121
the change from the transaction!
129122
"""
130123

131-
# noinspection SpellCheckingInspection
132124
pmt_result = api_1.prepare_multisig_transfer(
133125
# These are the transactions that will spend the IOTAs.
134126
# You can divide up the IOTAs to send to multiple addresses if you

examples/routingwrapper_pow.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding=utf-8
21
"""
32
Simple example using the RoutingWrapper to route API requests to
43
different nodes.
@@ -18,7 +17,6 @@
1817
api = Iota(router, seed=b'SEED9GOES9HERE')
1918

2019
# Example of sending a transfer using the adapter.
21-
# noinspection SpellCheckingInspection
2220
bundle = api.send_transfer(
2321
depth=3,
2422

examples/send_transfer.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding=utf-8
21
"""
32
Example script that shows how to use PyOTA to send a transfer to an address.
43
"""
@@ -13,7 +12,6 @@
1312
Tag,
1413
TryteString,
1514
)
16-
from six import text_type
1715
from address_generator import get_seed, output_seed
1816

1917

@@ -60,7 +58,7 @@ def main(address, depth, message, tag, uri, value):
6058

6159
parser.add_argument(
6260
'--address',
63-
type=text_type,
61+
type=str,
6462
default=b'RECEIVINGWALLETADDRESSGOESHERE9WITHCHECKSUMANDSECURITYLEVELB999999999999999999999999999999',
6563
help=
6664
'Receiving address'
@@ -78,7 +76,7 @@ def main(address, depth, message, tag, uri, value):
7876

7977
parser.add_argument(
8078
'--message',
81-
type=text_type,
79+
type=str,
8280
default='Hello World!',
8381
help=
8482
'Transfer message.'
@@ -87,7 +85,7 @@ def main(address, depth, message, tag, uri, value):
8785

8886
parser.add_argument(
8987
'--tag',
90-
type=text_type,
88+
type=str,
9189
default=b'EXAMPLE',
9290
help=
9391
'Transfer tag'
@@ -96,7 +94,7 @@ def main(address, depth, message, tag, uri, value):
9694

9795
parser.add_argument(
9896
'--uri',
99-
type=text_type,
97+
type=str,
10098
default='http://localhost:14265/',
10199
help=
102100
'URI of the node to connect to.'

iota/__init__.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# coding=utf-8
2-
from __future__ import absolute_import, division, print_function, \
3-
unicode_literals
41

52
# Define a few magic constants.
63
DEFAULT_PORT = 14265

iota/adapter/__init__.py

+7-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# coding=utf-8
2-
from __future__ import absolute_import, division, print_function, \
3-
unicode_literals
41

52
import json
63
from abc import ABCMeta, abstractmethod as abstract_method
@@ -11,8 +8,6 @@
118
from typing import Container, Dict, List, Optional, Text, Tuple, Union
129
from httpx import AsyncClient, Response, codes, auth
1310
import asyncio
14-
from six import PY2, binary_type, iteritems, moves as compat, text_type, \
15-
add_metaclass
1611

1712
from iota.exceptions import with_context
1813
from iota.json import JsonEncoder
@@ -28,13 +23,6 @@
2823
'resolve_adapter',
2924
]
3025

31-
if PY2:
32-
# Fix an error when importing this package using the ``imp`` library
33-
# (note: ``imp`` is deprecated since Python 3.4 in favor of
34-
# ``importlib``).
35-
# https://docs.python.org/3/library/imp.html
36-
# https://travis-ci.org/iotaledger/iota.py/jobs/191974244
37-
__all__ = map(binary_type, __all__)
3826

3927
API_VERSION = '1'
4028
"""
@@ -52,12 +40,7 @@
5240
"""
5341

5442
# Load SplitResult for IDE type hinting and autocompletion.
55-
if PY2:
56-
# noinspection PyCompatibility,PyUnresolvedReferences
57-
from urlparse import SplitResult
58-
else:
59-
# noinspection PyCompatibility,PyUnresolvedReferences
60-
from urllib.parse import SplitResult
43+
from urllib.parse import SplitResult, urlsplit
6144

6245
def async_return(result):
6346
"""
@@ -97,7 +80,7 @@ def resolve_adapter(uri):
9780
if isinstance(uri, BaseAdapter):
9881
return uri
9982

100-
parsed = compat.urllib_parse.urlsplit(uri) # type: SplitResult
83+
parsed = urlsplit(uri) # type: SplitResult
10184

10285
if not parsed.scheme:
10386
raise with_context(
@@ -133,7 +116,6 @@ class AdapterMeta(ABCMeta):
133116
Automatically registers new adapter classes in ``adapter_registry``.
134117
"""
135118

136-
# noinspection PyShadowingBuiltins
137119
def __init__(cls, what, bases=None, dict=None):
138120
super(AdapterMeta, cls).__init__(what, bases, dict)
139121

@@ -154,8 +136,7 @@ def configure(cls, parsed):
154136
return cls(parsed)
155137

156138

157-
@add_metaclass(AdapterMeta)
158-
class BaseAdapter(object):
139+
class BaseAdapter(object, metaclass=AdapterMeta):
159140
"""
160141
Interface for IOTA API adapters.
161142
@@ -242,7 +223,7 @@ class HttpAdapter(BaseAdapter):
242223
:param AdapterSpec uri:
243224
URI or adapter instance.
244225
245-
If ``uri`` is a ``text_type``, it is parsed to extract ``scheme``,
226+
If ``uri`` is a ``str``, it is parsed to extract ``scheme``,
246227
``hostname`` and ``port``.
247228
248229
:param Optional[int] timeout:
@@ -284,8 +265,8 @@ def __init__(self, uri, timeout=None, authentication=None):
284265
self.timeout = timeout
285266
self.authentication = authentication
286267

287-
if isinstance(uri, text_type):
288-
uri = compat.urllib_parse.urlsplit(uri) # type: SplitResult
268+
if isinstance(uri, str):
269+
uri = urlsplit(uri) # type: SplitResult
289270

290271
if uri.scheme not in self.supported_protocols:
291272
raise with_context(
@@ -312,7 +293,6 @@ def __init__(self, uri, timeout=None, authentication=None):
312293
)
313294

314295
try:
315-
# noinspection PyStatementEffect
316296
uri.port
317297
except ValueError:
318298
raise with_context(
@@ -344,7 +324,7 @@ def get_uri(self):
344324
async def send_request(self, payload, **kwargs):
345325
# type: (dict, dict) -> dict
346326
kwargs.setdefault('headers', {})
347-
for key, value in iteritems(self.DEFAULT_HEADERS):
327+
for key, value in self.DEFAULT_HEADERS.items():
348328
kwargs['headers'].setdefault(key, value)
349329

350330
response = await self._send_http_request(
@@ -539,7 +519,6 @@ class MockAdapter(BaseAdapter):
539519
"""
540520
supported_protocols = ('mock',)
541521

542-
# noinspection PyUnusedLocal
543522
@classmethod
544523
def configure(cls, uri):
545524
return cls()

iota/adapter/wrappers.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
# coding=utf-8
2-
from __future__ import absolute_import, division, print_function, \
3-
unicode_literals
4-
51
from abc import ABCMeta, abstractmethod as abstract_method
62
from typing import Dict, Text
73

8-
from six import add_metaclass
9-
104
from iota.adapter import AdapterSpec, BaseAdapter, resolve_adapter
115

126
__all__ = [
137
'RoutingWrapper',
148
]
159

1610

17-
@add_metaclass(ABCMeta)
18-
class BaseWrapper(BaseAdapter):
11+
class BaseWrapper(BaseAdapter, metaclass=ABCMeta):
1912
"""
2013
Base functionality for "adapter wrappers", used to extend the
2114
functionality of IOTA adapters.

0 commit comments

Comments
 (0)