Skip to content

Commit 60ada21

Browse files
committed
Upgrade to Python 3.5+ only again as py-ipfs-http-client doesn't support 2.7 anymore
1 parent 3183161 commit 60ada21

25 files changed

+60
-173
lines changed

.travis.yml

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
sudo: false
21
language: python
32
matrix:
43
include:
54
- python: 3.6
65
env: TOXENV=lint
7-
- python: 2.7
8-
env: TOXENV=py27
9-
- python: 3.4
10-
env: TOXENV=py34
116
- python: 3.5
127
env: TOXENV=py35
138
- python: 3.6
149
env: TOXENV=py36
1510
- python: 3.7
1611
env: TOXENV=py37
17-
dist: xenial
12+
- python: 3.8
13+
env: TOXENV=py38
1814
- python: pypy3.5
1915
env: TOXENV=pypy3
20-
allow_failures:
21-
- python: 2.7
22-
env: TOXENV=py27
2316

2417
install:
2518
- pip install tox

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Steven Buss <[email protected]>
22
Fred Thomsen <[email protected]>
33
Jesse Weinstein <[email protected]>
4+
Alexander Schlarb <[email protected]>

LICENSE-MIT

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
The MIT License (MIT)
22

33
Copyright (c) 2014-2015 Steven Buss
4+
Copyright (c) 2019-2020 Alexander Schlarb
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal

multiaddr/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
from .multiaddr import Multiaddr # NOQA
32

43
__author__ = 'Steven Buss'

multiaddr/codecs/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- encoding: utf-8 -*-
2-
from __future__ import absolute_import
31
import importlib
42

53

multiaddr/codecs/_util.py

-8
This file was deleted.

multiaddr/codecs/domain.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
import idna
42

53
from . import LENGTH_PREFIXED_VAR_SIZE

multiaddr/codecs/fspath.py

+2-22
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
1-
from __future__ import absolute_import
21
import os
32

4-
import six
5-
63
from . import LENGTH_PREFIXED_VAR_SIZE
74

85

96
SIZE = LENGTH_PREFIXED_VAR_SIZE
107
IS_PATH = True
118

129

13-
if hasattr(os, "fsencode") and hasattr(os, "fsdecode"):
14-
fsencode = os.fsencode
15-
fsdecode = os.fsdecode
16-
else: # pragma: no cover (PY2)
17-
import sys
18-
19-
def fsencode(path):
20-
if not isinstance(path, six.binary_type):
21-
path = path.encode(sys.getfilesystemencoding())
22-
return path
23-
24-
def fsdecode(path):
25-
if not isinstance(path, six.text_type):
26-
path = path.decode(sys.getfilesystemencoding())
27-
return path
28-
29-
3010
def to_bytes(proto, string):
31-
return fsencode(string)
11+
return os.fsencode(string)
3212

3313

3414
def to_string(proto, buf):
35-
return fsdecode(buf)
15+
return os.fsdecode(buf)

multiaddr/codecs/ip4.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
from __future__ import absolute_import
2-
31
import netaddr
4-
import six
5-
6-
from ._util import packed_net_bytes_to_int
72

83

94
SIZE = 32
@@ -15,5 +10,4 @@ def to_bytes(proto, string):
1510

1611

1712
def to_string(proto, buf):
18-
ip_addr = netaddr.IPAddress(packed_net_bytes_to_int(buf), version=4)
19-
return six.text_type(ip_addr)
13+
return str(netaddr.IPAddress(int.from_bytes(buf, byteorder='big'), version=4))

multiaddr/codecs/ip6.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
from __future__ import absolute_import
2-
31
import netaddr
4-
import six
5-
6-
from ._util import packed_net_bytes_to_int
72

83

94
SIZE = 128
@@ -15,5 +10,4 @@ def to_bytes(proto, string):
1510

1611

1712
def to_string(proto, buf):
18-
ip_addr = netaddr.IPAddress(packed_net_bytes_to_int(buf), version=6)
19-
return six.text_type(ip_addr)
13+
return str(netaddr.IPAddress(int.from_bytes(buf, byteorder='big'), version=6))

multiaddr/codecs/onion.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
from __future__ import absolute_import
21
import base64
32
import struct
43

5-
import six
6-
74

85
SIZE = 96
96
IS_PATH = False
@@ -20,13 +17,13 @@ def to_bytes(proto, string):
2017
try:
2118
onion_host_bytes = base64.b32decode(addr[0].upper())
2219
except Exception as exc:
23-
six.raise_from(ValueError("Cannot decode {0!r} as base32: {1}".format(addr[0], exc)), exc)
20+
raise ValueError("Cannot decode {0!r} as base32: {1}".format(addr[0], exc)) from exc
2421

2522
# onion port number
2623
try:
2724
port = int(addr[1], 10)
2825
except ValueError as exc:
29-
six.raise_from(ValueError("Port number is not a base 10 integer"), exc)
26+
raise ValueError("Port number is not a base 10 integer") from exc
3027
if port not in range(1, 65536):
3128
raise ValueError("Port number is not in range(1, 65536)")
3229

@@ -36,5 +33,5 @@ def to_bytes(proto, string):
3633
def to_string(proto, buf):
3734
addr_bytes, port_bytes = (buf[:-2], buf[-2:])
3835
addr = base64.b32encode(addr_bytes).decode('ascii').lower()
39-
port = six.text_type(struct.unpack('>H', port_bytes)[0])
40-
return u':'.join([addr, port])
36+
port = str(struct.unpack('>H', port_bytes)[0])
37+
return ':'.join([addr, port])

multiaddr/codecs/onion3.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
from __future__ import absolute_import
21
import base64
32
import struct
43

5-
import six
6-
74

85
SIZE = 296
96
IS_PATH = False
@@ -20,13 +17,13 @@ def to_bytes(proto, string):
2017
try:
2118
onion3_host_bytes = base64.b32decode(addr[0].upper())
2219
except Exception as exc:
23-
six.raise_from(ValueError("Cannot decode {0!r} as base32: {1}".format(addr[0], exc)), exc)
20+
raise ValueError("Cannot decode {0!r} as base32: {1}".format(addr[0], exc)) from exc
2421

2522
# onion3 port number
2623
try:
2724
port = int(addr[1], 10)
2825
except ValueError as exc:
29-
six.raise_from(ValueError("Port number is not a base 10 integer"), exc)
26+
raise ValueError("Port number is not a base 10 integer") from exc
3027
if port not in range(1, 65536):
3128
raise ValueError("Port number is not in range(1, 65536)")
3229

@@ -36,5 +33,5 @@ def to_bytes(proto, string):
3633
def to_string(proto, buf):
3734
addr_bytes, port_bytes = (buf[:-2], buf[-2:])
3835
addr = base64.b32encode(addr_bytes).decode('ascii').lower()
39-
port = six.text_type(struct.unpack('>H', port_bytes)[0])
40-
return u':'.join([addr, port])
36+
port = str(struct.unpack('>H', port_bytes)[0])
37+
return ':'.join([addr, port])

multiaddr/codecs/p2p.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from __future__ import absolute_import
2-
31
import base58
4-
import six
52

63
from . import LENGTH_PREFIXED_VAR_SIZE
74

@@ -11,9 +8,6 @@
118

129

1310
def to_bytes(proto, string):
14-
# the address is a base58-encoded string
15-
if six.PY2 and isinstance(string, unicode): # pragma: no cover (PY2) # noqa: F821
16-
string = string.encode("ascii")
1711
mm = base58.b58decode(string)
1812
if len(mm) < 5:
1913
raise ValueError("P2P MultiHash too short: len() < 5")

multiaddr/codecs/uint16be.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from __future__ import absolute_import
21
import struct
32

4-
import six
5-
63

74
SIZE = 16
85
IS_PATH = False
@@ -12,12 +9,12 @@ def to_bytes(proto, string):
129
try:
1310
return struct.pack('>H', int(string, 10))
1411
except ValueError as exc:
15-
six.raise_from(ValueError("Not a base 10 integer"), exc)
12+
raise ValueError("Not a base 10 integer") from exc
1613
except struct.error as exc:
17-
six.raise_from(ValueError("Integer not in range(65536)"), exc)
14+
raise ValueError("Integer not in range(65536)") from exc
1815

1916

2017
def to_string(proto, buf):
2118
if len(buf) != 2:
2219
raise ValueError("Invalid integer length (must be 2 bytes / 16 bits)")
23-
return six.text_type(struct.unpack('>H', buf)[0])
20+
return str(struct.unpack('>H', buf)[0])

multiaddr/exceptions.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, proto, string):
1515
self.proto = proto
1616
self.string = string
1717

18-
super(ProtocolLookupError, self).__init__(
18+
super().__init__(
1919
"MultiAddr {0!r} does not contain protocol {1}".format(string, proto)
2020
)
2121

@@ -40,7 +40,7 @@ def __init__(self, message, string, protocol=None, original=None):
4040
else:
4141
message = "Invalid MultiAddr {0!r}: {1}".format(string, message)
4242

43-
super(StringParseError, self).__init__(message)
43+
super().__init__(message)
4444

4545

4646
class BinaryParseError(ParseError):
@@ -56,7 +56,7 @@ def __init__(self, message, binary, protocol, original=None):
5656

5757
message = "Invalid binary MultiAddr protocol {0}: {1}".format(protocol, message)
5858

59-
super(BinaryParseError, self).__init__(message)
59+
super().__init__(message)
6060

6161

6262
class ProtocolManagerError(Error):
@@ -71,7 +71,7 @@ def __init__(self, proto, kind="name"):
7171
self.proto = proto
7272
self.kind = kind
7373

74-
super(ProtocolExistsError, self).__init__(
74+
super().__init__(
7575
"Protocol with {0} {1!r} already exists".format(kind, getattr(proto, kind))
7676
)
7777

@@ -84,6 +84,6 @@ def __init__(self, value, kind="name"):
8484
self.value = value
8585
self.kind = kind
8686

87-
super(ProtocolNotFoundError, self).__init__(
87+
super().__init__(
8888
"No protocol with {0} {1!r} found".format(kind, value)
8989
)

multiaddr/multiaddr.py

+7-32
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
# -*- coding: utf-8 -*-
2-
try:
3-
import collections.abc
4-
except ImportError: # pragma: no cover (PY2)
5-
import collections
6-
collections.abc = collections
7-
8-
import six
1+
import collections.abc
2+
93
import varint
104

115
from . import exceptions, protocols
@@ -59,15 +53,12 @@ def __iter__(self):
5953
# If we have an address, return it
6054
yield proto, codec.to_string(proto, part)
6155
except Exception as exc:
62-
six.raise_from(
63-
exceptions.BinaryParseError(
56+
raise exceptions.BinaryParseError(
6457
str(exc),
6558
self._mapping.to_bytes(),
6659
proto.name,
6760
exc,
68-
),
69-
exc,
70-
)
61+
) from exc
7162
else:
7263
# We were given something like '/utp', which doesn't have
7364
# an address, so return None
@@ -116,15 +107,9 @@ def __init__(self, addr):
116107
addr : A string-encoded or a byte-encoded Multiaddr
117108
118109
"""
119-
# On Python 2 text string will often be binary anyways so detect the
120-
# obvious case of a “binary-encoded” multiaddr starting with a slash
121-
# and decode it into text
122-
if six.PY2 and isinstance(addr, str) and addr.startswith("/"): # pragma: no cover (PY2)
123-
addr = addr.decode("utf-8")
124-
125-
if isinstance(addr, six.text_type):
110+
if isinstance(addr, str):
126111
self._bytes = string_to_bytes(addr)
127-
elif isinstance(addr, six.binary_type):
112+
elif isinstance(addr, bytes):
128113
self._bytes = addr
129114
elif isinstance(addr, Multiaddr):
130115
self._bytes = addr.to_bytes()
@@ -155,17 +140,7 @@ def __iter__(self):
155140
return iter(MultiAddrKeys(self))
156141

157142
def __len__(self):
158-
return sum((1 for _ in bytes_iter(self.to_bytes())))
159-
160-
# On Python 2 __str__ needs to return binary text, so expose the original
161-
# function as __unicode__ and transparently encode its returned text based
162-
# on the current locale
163-
if six.PY2: # pragma: no cover (PY2)
164-
__unicode__ = __str__
165-
166-
def __str__(self):
167-
import locale
168-
return self.__unicode__().encode(locale.getpreferredencoding())
143+
return sum(1 for _ in bytes_iter(self.to_bytes()))
169144

170145
def __repr__(self):
171146
return "<Multiaddr %s>" % str(self)

0 commit comments

Comments
 (0)