|
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 | + |
9 | 3 | import varint
|
10 | 4 |
|
11 | 5 | from . import exceptions, protocols
|
@@ -59,15 +53,12 @@ def __iter__(self):
|
59 | 53 | # If we have an address, return it
|
60 | 54 | yield proto, codec.to_string(proto, part)
|
61 | 55 | except Exception as exc:
|
62 |
| - six.raise_from( |
63 |
| - exceptions.BinaryParseError( |
| 56 | + raise exceptions.BinaryParseError( |
64 | 57 | str(exc),
|
65 | 58 | self._mapping.to_bytes(),
|
66 | 59 | proto.name,
|
67 | 60 | exc,
|
68 |
| - ), |
69 |
| - exc, |
70 |
| - ) |
| 61 | + ) from exc |
71 | 62 | else:
|
72 | 63 | # We were given something like '/utp', which doesn't have
|
73 | 64 | # an address, so return None
|
@@ -116,15 +107,9 @@ def __init__(self, addr):
|
116 | 107 | addr : A string-encoded or a byte-encoded Multiaddr
|
117 | 108 |
|
118 | 109 | """
|
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): |
126 | 111 | self._bytes = string_to_bytes(addr)
|
127 |
| - elif isinstance(addr, six.binary_type): |
| 112 | + elif isinstance(addr, bytes): |
128 | 113 | self._bytes = addr
|
129 | 114 | elif isinstance(addr, Multiaddr):
|
130 | 115 | self._bytes = addr.to_bytes()
|
@@ -155,17 +140,7 @@ def __iter__(self):
|
155 | 140 | return iter(MultiAddrKeys(self))
|
156 | 141 |
|
157 | 142 | 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())) |
169 | 144 |
|
170 | 145 | def __repr__(self):
|
171 | 146 | return "<Multiaddr %s>" % str(self)
|
|
0 commit comments