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

Commit 0e609ad

Browse files
committed
PR review changes
1 parent 9c95b9c commit 0e609ad

Some content is hidden

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

46 files changed

+259
-284
lines changed

examples/send_transfer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Tag,
1313
TryteString,
1414
)
15-
from address_generator import get_seed, output_seed
15+
from .address_generator import get_seed, output_seed
1616

1717

1818
def main(address, depth, message, tag, uri, value):

iota/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
from typing import Dict
12

23
# Define a few magic constants.
3-
from typing import Dict, Text
4-
54
DEFAULT_PORT: int = 14265
65
"""
76
Default port to use when configuring an adapter, if the port is not
@@ -16,7 +15,7 @@
1615
In that way, it's kind of like toxic waste in a superhero story.
1716
"""
1817

19-
STANDARD_UNITS: Dict[Text, int] = {
18+
STANDARD_UNITS: Dict[str, int] = {
2019
# Valid IOTA unit suffixes. Example value '-273.15 Ki'
2120
'i': 1,
2221
'Ki': 1000,

iota/adapter/__init__.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from inspect import isabstract as is_abstract
77
from logging import DEBUG, Logger
88
from socket import getdefaulttimeout as get_default_timeout
9-
from typing import Container, Dict, List, Optional, Text, Tuple, Union, Any
10-
from httpx import AsyncClient, Response, codes, auth
9+
from typing import Container, List, Optional, Tuple, Union, Any, Dict
10+
from httpx import AsyncClient, Response, codes, BasicAuth
1111
import asyncio
1212

1313
from iota.exceptions import with_context
@@ -32,7 +32,7 @@
3232
"""
3333

3434
# Custom types for type hints and docstrings.
35-
AdapterSpec = Union[Text, 'BaseAdapter']
35+
AdapterSpec = Union[str, 'BaseAdapter']
3636
"""
3737
Placeholder that means “URI or adapter instance”.
3838
@@ -69,7 +69,7 @@ class InvalidUri(ValueError):
6969
pass
7070

7171

72-
adapter_registry: Dict[Text, 'AdapterMeta'] = {}
72+
adapter_registry: Dict[str, 'AdapterMeta'] = {}
7373
"""
7474
Keeps track of available adapters and their supported protocols.
7575
"""
@@ -127,7 +127,7 @@ def __init__(cls, what, bases=None, dict=None) -> None:
127127
# adapters.
128128
adapter_registry.setdefault(protocol, cls)
129129

130-
def configure(cls, parsed: Union[Text, SplitResult]) -> 'HttpAdapter':
130+
def configure(cls, parsed: Union[str, SplitResult]) -> 'HttpAdapter':
131131
"""
132132
Creates a new instance using the specified URI.
133133
@@ -144,7 +144,7 @@ class BaseAdapter(object, metaclass=AdapterMeta):
144144
Adapters make it easy to customize the way an API instance
145145
communicates with a node.
146146
"""
147-
supported_protocols: Tuple[Text] = ()
147+
supported_protocols: Tuple[str] = ()
148148
"""
149149
Protocols that ``resolve_adapter`` can use to identify this adapter
150150
type.
@@ -157,7 +157,7 @@ def __init__(self) -> None:
157157
self.local_pow: bool = False
158158

159159
@abstract_method
160-
def get_uri(self) -> Text:
160+
def get_uri(self) -> str:
161161
"""
162162
Returns the URI that this adapter will use.
163163
"""
@@ -166,7 +166,7 @@ def get_uri(self) -> Text:
166166
)
167167

168168
@abstract_method
169-
def send_request(self, payload: Dict, **kwargs: Any) -> Dict:
169+
def send_request(self, payload: dict, **kwargs: Any) -> dict:
170170
"""
171171
Sends an API request to the node.
172172
@@ -199,7 +199,7 @@ def set_logger(self, logger: Logger) -> 'BaseAdapter':
199199
def _log(
200200
self,
201201
level: int,
202-
message: Text,
202+
message: str,
203203
context: Optional[dict] = None
204204
) -> None:
205205
"""
@@ -231,7 +231,7 @@ class HttpAdapter(BaseAdapter):
231231
:param Optional[int] timeout:
232232
Connection timeout in seconds.
233233
234-
:param Optional[Tuple(Text,Text)] authentication:
234+
:param Optional[Tuple(str,str)] authentication:
235235
Credetentials for basic authentication with the node.
236236
237237
:return:
@@ -261,9 +261,9 @@ class HttpAdapter(BaseAdapter):
261261

262262
def __init__(
263263
self,
264-
uri: Union[Text, SplitResult],
264+
uri: Union[str, SplitResult],
265265
timeout: Optional[int] = None,
266-
authentication: Optional[Tuple[Text, Text]] = None
266+
authentication: Optional[Tuple[str, str]] = None
267267
) -> None:
268268
super(HttpAdapter, self).__init__()
269269

@@ -316,16 +316,16 @@ def __init__(
316316
self.uri = uri
317317

318318
@property
319-
def node_url(self) -> Text:
319+
def node_url(self) -> str:
320320
"""
321321
Returns the node URL.
322322
"""
323323
return self.uri.geturl()
324324

325-
def get_uri(self) -> Text:
325+
def get_uri(self) -> str:
326326
return self.uri.geturl()
327327

328-
async def send_request(self, payload: Dict, **kwargs: Any) -> Dict:
328+
async def send_request(self, payload: dict, **kwargs: Any) -> dict:
329329
kwargs.setdefault('headers', {})
330330
for key, value in self.DEFAULT_HEADERS.items():
331331
kwargs['headers'].setdefault(key, value)
@@ -343,9 +343,9 @@ async def send_request(self, payload: Dict, **kwargs: Any) -> Dict:
343343

344344
async def _send_http_request(
345345
self,
346-
url: Text,
347-
payload: Optional[Text],
348-
method: Text = 'post',
346+
url: str,
347+
payload: Optional[str],
348+
method: str = 'post',
349349
**kwargs: Any
350350
) -> Response:
351351
"""
@@ -360,7 +360,7 @@ async def _send_http_request(
360360
)
361361

362362
if self.authentication:
363-
kwargs.setdefault('auth', auth.BasicAuth(*self.authentication))
363+
kwargs.setdefault('auth', BasicAuth(*self.authentication))
364364

365365
self._log(
366366
level=DEBUG,
@@ -405,9 +405,9 @@ async def _send_http_request(
405405
def _interpret_response(
406406
self,
407407
response: Response,
408-
payload: Dict,
408+
payload: dict,
409409
expected_status: Container[int]
410-
) -> Dict:
410+
) -> dict:
411411
"""
412412
Interprets the HTTP response from the node.
413413
@@ -437,7 +437,7 @@ def _interpret_response(
437437
)
438438

439439
try:
440-
decoded: Dict = json.loads(raw_content)
440+
decoded: dict = json.loads(raw_content)
441441
# :bc: py2k doesn't have JSONDecodeError
442442
except ValueError:
443443
raise with_context(
@@ -538,13 +538,13 @@ def configure(cls, uri):
538538
def __init__(self) -> None:
539539
super(MockAdapter, self).__init__()
540540

541-
self.responses: Dict[Text, deque] = {}
541+
self.responses: Dict[str, deque] = {}
542542
self.requests: List[dict] = []
543543

544-
def get_uri(self) -> Text:
544+
def get_uri(self) -> str:
545545
return 'mock://'
546546

547-
def seed_response(self, command: Text, response: Dict) -> 'MockAdapter':
547+
def seed_response(self, command: str, response: dict) -> 'MockAdapter':
548548
"""
549549
Sets the response that the adapter will return for the specified
550550
command.
@@ -558,7 +558,7 @@ def seed_response(self, command: Text, response: Dict) -> 'MockAdapter':
558558
have a seeded response for a particular command, it will raise a
559559
``BadApiResponse`` exception (simulates a 404 response).
560560
561-
:param Text command:
561+
:param str command:
562562
The name of the command. Note that this is the camelCase version
563563
of the command name (e.g., ``getNodeInfo``, not ``get_node_info``).
564564
@@ -584,7 +584,7 @@ def seed_response(self, command: Text, response: Dict) -> 'MockAdapter':
584584
self.responses[command].append(response)
585585
return self
586586

587-
async def send_request(self, payload: Dict, **kwargs: Any) -> Dict:
587+
async def send_request(self, payload: Dict, **kwargs: Any) -> dict:
588588
"""
589589
Mimic asynchronous behavior of `HttpAdapter.send_request`.
590590
"""

iota/adapter/wrappers.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import ABCMeta, abstractmethod as abstract_method
2-
from typing import Dict, Text
2+
from typing import Dict, Any
33

44
from iota.adapter import AdapterSpec, BaseAdapter, resolve_adapter
55

@@ -22,11 +22,11 @@ def __init__(self, adapter: AdapterSpec) -> None:
2222

2323
self.adapter: BaseAdapter = adapter
2424

25-
def get_uri(self) -> Text:
25+
def get_uri(self) -> str:
2626
return self.adapter.get_uri()
2727

2828
@abstract_method
29-
def send_request(self, payload: Dict, **kwargs: Any) -> Dict:
29+
def send_request(self, payload: dict, **kwargs: Any) -> dict:
3030
raise NotImplementedError(
3131
'Not implemented in {cls}.'.format(cls=type(self).__name__),
3232
)
@@ -94,13 +94,13 @@ def __init__(self, default_adapter: AdapterSpec) -> None:
9494
# when resolving URIs.
9595
self.adapter_aliases: Dict[AdapterSpec, BaseAdapter] = {}
9696

97-
self.routes: Dict[Text, BaseAdapter] = {}
97+
self.routes: Dict[str, BaseAdapter] = {}
9898

99-
def add_route(self, command: Text, adapter: AdapterSpec) -> 'RoutingWrapper':
99+
def add_route(self, command: str, adapter: AdapterSpec) -> 'RoutingWrapper':
100100
"""
101101
Adds a route to the wrapper.
102102
103-
:param Text command:
103+
:param str command:
104104
The name of the command. Note that this is the camelCase version of
105105
the command name (e.g., ``attachToTangle``, not ``attach_to_tangle``).
106106
@@ -125,13 +125,13 @@ def add_route(self, command: Text, adapter: AdapterSpec) -> 'RoutingWrapper':
125125

126126
return self
127127

128-
def get_adapter(self, command: Text) -> BaseAdapter:
128+
def get_adapter(self, command: str) -> BaseAdapter:
129129
"""
130130
Return the adapter for the specified command.
131131
"""
132132
return self.routes.get(command, self.adapter)
133133

134-
async def send_request(self, payload: Dict, **kwargs: Any) -> Dict:
134+
async def send_request(self, payload: dict, **kwargs: Any) -> dict:
135135
command = payload.get('command')
136136

137137
return await self.get_adapter(command).send_request(payload, **kwargs)

0 commit comments

Comments
 (0)