1
- # coding=utf-8
2
- from __future__ import absolute_import , division , print_function , \
3
- unicode_literals
4
1
5
2
import json
6
3
from abc import ABCMeta , abstractmethod as abstract_method
11
8
from typing import Container , Dict , List , Optional , Text , Tuple , Union
12
9
from httpx import AsyncClient , Response , codes , auth
13
10
import asyncio
14
- from six import PY2 , binary_type , iteritems , moves as compat , text_type , \
15
- add_metaclass
16
11
17
12
from iota .exceptions import with_context
18
13
from iota .json import JsonEncoder
28
23
'resolve_adapter' ,
29
24
]
30
25
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__ )
38
26
39
27
API_VERSION = '1'
40
28
"""
52
40
"""
53
41
54
42
# 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
61
44
62
45
def async_return (result ):
63
46
"""
@@ -97,7 +80,7 @@ def resolve_adapter(uri):
97
80
if isinstance (uri , BaseAdapter ):
98
81
return uri
99
82
100
- parsed = compat . urllib_parse . urlsplit (uri ) # type: SplitResult
83
+ parsed = urlsplit (uri ) # type: SplitResult
101
84
102
85
if not parsed .scheme :
103
86
raise with_context (
@@ -133,7 +116,6 @@ class AdapterMeta(ABCMeta):
133
116
Automatically registers new adapter classes in ``adapter_registry``.
134
117
"""
135
118
136
- # noinspection PyShadowingBuiltins
137
119
def __init__ (cls , what , bases = None , dict = None ):
138
120
super (AdapterMeta , cls ).__init__ (what , bases , dict )
139
121
@@ -154,8 +136,7 @@ def configure(cls, parsed):
154
136
return cls (parsed )
155
137
156
138
157
- @add_metaclass (AdapterMeta )
158
- class BaseAdapter (object ):
139
+ class BaseAdapter (object , metaclass = AdapterMeta ):
159
140
"""
160
141
Interface for IOTA API adapters.
161
142
@@ -242,7 +223,7 @@ class HttpAdapter(BaseAdapter):
242
223
:param AdapterSpec uri:
243
224
URI or adapter instance.
244
225
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``,
246
227
``hostname`` and ``port``.
247
228
248
229
:param Optional[int] timeout:
@@ -284,8 +265,8 @@ def __init__(self, uri, timeout=None, authentication=None):
284
265
self .timeout = timeout
285
266
self .authentication = authentication
286
267
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
289
270
290
271
if uri .scheme not in self .supported_protocols :
291
272
raise with_context (
@@ -312,7 +293,6 @@ def __init__(self, uri, timeout=None, authentication=None):
312
293
)
313
294
314
295
try :
315
- # noinspection PyStatementEffect
316
296
uri .port
317
297
except ValueError :
318
298
raise with_context (
@@ -344,7 +324,7 @@ def get_uri(self):
344
324
async def send_request (self , payload , ** kwargs ):
345
325
# type: (dict, dict) -> dict
346
326
kwargs .setdefault ('headers' , {})
347
- for key , value in iteritems ( self .DEFAULT_HEADERS ):
327
+ for key , value in self .DEFAULT_HEADERS . items ( ):
348
328
kwargs ['headers' ].setdefault (key , value )
349
329
350
330
response = await self ._send_http_request (
@@ -539,7 +519,6 @@ class MockAdapter(BaseAdapter):
539
519
"""
540
520
supported_protocols = ('mock' ,)
541
521
542
- # noinspection PyUnusedLocal
543
522
@classmethod
544
523
def configure (cls , uri ):
545
524
return cls ()
0 commit comments