66from inspect import isabstract as is_abstract
77from logging import DEBUG , Logger
88from 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
1111import asyncio
1212
1313from iota .exceptions import with_context
3232"""
3333
3434# Custom types for type hints and docstrings.
35- AdapterSpec = Union [Text , 'BaseAdapter' ]
35+ AdapterSpec = Union [str , 'BaseAdapter' ]
3636"""
3737Placeholder 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"""
7474Keeps 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 """
0 commit comments