2
2
import json
3
3
from dataclasses import dataclass , field
4
4
from enum import Enum
5
- from typing import Callable , Type , Union , get_origin , ForwardRef
5
+ from typing_extensions import Type , get_origin
6
+ from typing import Callable , Union , ForwardRef
6
7
from typing import TypeVar , Optional , Dict , List , Any
7
8
from urllib .parse import urljoin , quote_plus
8
9
@@ -91,7 +92,7 @@ def qsvalue(arg):
91
92
return quote_plus (str (arg ))
92
93
93
94
94
- def append_querystring (url : str , args : dict [str , Any ]):
95
+ def append_querystring (url : str , args : Dict [str , Any ]):
95
96
if args :
96
97
for key in args :
97
98
val = args [key ]
@@ -113,13 +114,13 @@ def has_request_body(method: str):
113
114
@dataclass
114
115
class SendContext :
115
116
session : Optional [requests .Session ] = None
116
- headers : dict [str , str ] = field (default_factory = dict )
117
+ headers : Dict [str , str ] = field (default_factory = dict )
117
118
method : str = None
118
119
url : Optional [str ] = None
119
120
request : Optional [Union [IReturn , IReturnVoid , List [IReturn ], List [IReturnVoid ]]] = None
120
121
body : Optional [Any ] = None
121
122
body_string : Optional [str ] = None
122
- args : Optional [dict [str , str ]] = None
123
+ args : Optional [Dict [str , str ]] = None
123
124
response_as : type = None
124
125
request_filter : Callable [[Any ], None ] = None
125
126
response_filter : Callable [[Response ], None ] = None
@@ -270,29 +271,29 @@ def to_absolute_url(self, path_or_url: str):
270
271
return path_or_url
271
272
return urljoin (self .base_url , path_or_url )
272
273
273
- def get_url (self , path : str , response_as : Type , args : dict [str , Any ] = None ):
274
+ def get_url (self , path : str , response_as : Type , args : Dict [str , Any ] = None ):
274
275
return self .send_url (path , "GET" , response_as , None , args )
275
276
276
- def delete_url (self , path : str , response_as : Type , args : dict [str , Any ] = None ):
277
+ def delete_url (self , path : str , response_as : Type , args : Dict [str , Any ] = None ):
277
278
return self .send_url (path , "DELETE" , response_as , None , args )
278
279
279
- def options_url (self , path : str , response_as : Type , args : dict [str , Any ] = None ):
280
+ def options_url (self , path : str , response_as : Type , args : Dict [str , Any ] = None ):
280
281
return self .send_url (path , "OPTIONS" , response_as , None , args )
281
282
282
- def head_url (self , path : str , response_as : Type , args : dict [str , Any ] = None ):
283
+ def head_url (self , path : str , response_as : Type , args : Dict [str , Any ] = None ):
283
284
return self .send_url (path , "HEAD" , response_as , None , args )
284
285
285
- def post_url (self , path : str , body : Any = None , response_as : Type = None , args : dict [str , Any ] = None ):
286
+ def post_url (self , path : str , body : Any = None , response_as : Type = None , args : Dict [str , Any ] = None ):
286
287
return self .send_url (path , "POST" , response_as , body , args )
287
288
288
- def put_url (self , path : str , body : Any = None , response_as : Type = None , args : dict [str , Any ] = None ):
289
+ def put_url (self , path : str , body : Any = None , response_as : Type = None , args : Dict [str , Any ] = None ):
289
290
return self .send_url (path , "PUT" , response_as , body , args )
290
291
291
- def patch_url (self , path : str , body : Any = None , response_as : Type = None , args : dict [str , Any ] = None ):
292
+ def patch_url (self , path : str , body : Any = None , response_as : Type = None , args : Dict [str , Any ] = None ):
292
293
return self .send_url (path , "PATCH" , response_as , body , args )
293
294
294
295
def send_url (self , path : str , method : str = None , response_as : Type = None , body : Any = None ,
295
- args : dict [str , Any ] = None ):
296
+ args : Dict [str , Any ] = None ):
296
297
297
298
if body and not response_as :
298
299
response_as = _resolve_response_type (body )
@@ -359,7 +360,7 @@ def send_all(self, request_dtos: List[IReturn[T]]):
359
360
body = None ,
360
361
body_string = None ,
361
362
args = None ,
362
- response_as = list .__class_getitem__ (item_response_as )))
363
+ response_as = list .__class_getitem__ (item_response_as ))) # requires 3.9
363
364
364
365
def send_all_oneway (self , request_dtos : list ):
365
366
request , item_response_as = self .assert_valid_batch_request (request_dtos )
@@ -374,7 +375,7 @@ def send_all_oneway(self, request_dtos: list):
374
375
body = None ,
375
376
body_string = None ,
376
377
args = None ,
377
- response_as = list .__class_getitem__ (item_response_as )))
378
+ response_as = list .__class_getitem__ (item_response_as ))) # requires 3.9
378
379
379
380
def _resend_request (self , info : SendContext ):
380
381
0 commit comments