8000 remove deprecated HttpRequest type alias (#9757) · localstack/localstack@3021997 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3021997

Browse files
authored
remove deprecated HttpRequest type alias (#9757)
1 parent 2f05d65 commit 3021997

File tree

8 files changed

+93
-106
lines changed

8 files changed

+93
-106
lines changed

localstack-core/localstack/aws/api/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from .core import (
22
CommonServiceException,
3-
HttpRequest,
4-
HttpResponse,
53
RequestContext,
64
ServiceException,
75
ServiceRequest,
@@ -16,6 +14,4 @@
1614
"ServiceRequest",
1715
"ServiceResponse",
1816
"handler",
19-
"HttpRequest",
20-
"HttpResponse",
2117
]

localstack-core/localstack/aws/api/core.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
from localstack.http import Request, Response
99
from localstack.utils.strings import long_uid
1010

11-
# FIXME: deprecated, use localstack.http.Request and localstack.http.Response instead
12-
HttpRequest = Request
13-
HttpResponse = Response
14-
1511

1612
class ServiceRequest(TypedDict):
1713
pass

localstack-core/localstack/aws/protocol/parser.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@
8585
)
8686
from werkzeug.exceptions import BadRequest, NotFound
8787

88-
from localstack.aws.api import HttpRequest
8988
from localstack.aws.protocol.op_router import RestServiceOperationRouter
9089
from localstack.config import LEGACY_V2_S3_PROVIDER
90+
from localstack.http import Request
9191

9292

9393
def _text_content(func):
@@ -104,7 +104,7 @@ def _text_content(func):
104104

105105
def _get_text_content(
106106
self,
107-
request: HttpRequest,
107+
request: Request,
108108
shape: Shape,
109109
node_or_string: Union[ETree.Element, str],
110110
uri_params: Mapping[str, Any] = None,
@@ -202,7 +202,7 @@ def __init__(self, service: ServiceModel) -> None:
202202
self.service = service
203203

204204
@_handle_exceptions
205-
def parse(self, request: HttpRequest) -> Tuple[OperationModel, Any]:
205+
def parse(self, request: Request) -> Tuple[OperationModel, Any]:
206206
"""
207207
Determines which operation the request was aiming for and parses the incoming request such that the resulting
208208
dictionary can be used to invoke the service's function implementation.
@@ -215,12 +215,12 @@ def parse(self, request: HttpRequest) -> Tuple[OperationModel, Any]:
215215
raise NotImplementedError
216216

217217
def _parse_shape(
218-
self, request: HttpRequest, shape: Shape, node: Any, uri_params: Mapping[str, Any] = None
218+
self, request: Request, shape: Shape, node: Any, uri_params: Mapping[str, Any] = None
219219
) -> Any:
220220
"""
221221
Main parsing method which dynamically calls the parsing function for the specific shape.
222222
223-
:param request: the complete HttpRequest
223+
:param request: the complete Request
224224
:param shape: of the node
225225
:param node: the single part of the HTTP request to parse
226226
:param uri_params: the extracted URI path params
@@ -273,7 +273,7 @@ def _parse_shape(
273273

274274
def _parse_list(
275275
self,
276-
request: HttpRequest,
276+
request: Request,
277277
shape: ListShape,
278278
node: list,
279279
uri_params: Mapping[str, Any] = None,
@@ -362,7 +362,7 @@ class QueryRequestParser(RequestParser):
362362
"""
363363

364364
@_handle_exceptions
365-
def parse(self, request: HttpRequest) -> Tuple[OperationModel, Any]:
365+
def parse(self, request: Request) -> Tuple[OperationModel, Any]:
366366
instance = request.values
367367
if "Action" not in instance:
368368
raise ProtocolParserError(
@@ -387,7 +387,7 @@ def parse(self, request: HttpRequest) -> Tuple[OperationModel, Any]:
387387

388388
def _process_member(
389389
self,
390-
request: HttpRequest,
390+
request: Request,
391391
member_name: str,
392392
member_shape: Shape,
393393
node: dict,
@@ -409,7 +409,7 @@ def _process_member(
409409

410410
def _parse_structure(
411411
self,
412-
request: HttpRequest,
412+
request: Request,
413413
shape: StructureShape,
414414
node: dict,
415415
uri_params: Mapping[str, Any] = None,
@@ -431,7 +431,7 @@ def _parse_structure(
431431
return result if len(result) > 0 else None
432432

433433
def _parse_map(
434-
self, request: HttpRequest, shape: MapShape, node: dict, uri_params: Mapping[str, Any]
434+
self, request: Request, shape: MapShape, node: dict, uri_params: Mapping[str, Any]
435435
) -> dict:
436436
"""
437437
This is what the node looks like for a flattened map::
@@ -479,7 +4 EF5E 79,7 @@ def _parse_map(
479479

480480
def _parse_list(
481481
self,
482-
request: HttpRequest,
482+
request: Request,
483483
shape: ListShape,
484484
node: dict,
485485
uri_params: Mapping[str, Any] = None,
@@ -554,7 +554,7 @@ def __init__(self, service: ServiceModel) -> None:
554554
self._operation_router = RestServiceOperationRouter(service)
555555

556556
@_handle_exceptions
557-
def parse(self, request: HttpRequest) -> Tuple[OperationModel, Any]:
557+
def parse(self, request: Request) -> Tuple[OperationModel, Any]:
558558
try:
559559
operation, uri_params = self._operation_router.match(request)
560560
except NotFound as e:
@@ -571,7 +571,7 @@ def parse(self, request: HttpRequest) -> Tuple[OperationModel, Any]:
571571

572572
def _parse_payload(
573573
self,
574-
request: HttpRequest,
574+
request: Request,
575575
shape: Shape,
576576
member_shapes: Dict[str, Shape],
577577
uri_params: Mapping[str, Any],
@@ -622,7 +622,7 @@ def _parse_payload(
622622
final_parsed.update(non_payload_parsed)
623623
final_parsed.update(payload_parsed)
624624

625-
def _initial_body_parse(self, request: HttpRequest) -> Any:
625+
def _initial_body_parse(self, request: Request) -> Any:
626626
"""
627627
This method executes the initial parsing of the body (XML, JSON, or CBOR).
628628
The parsed body will afterwards still be walked through and the nodes will be converted to the appropriate
@@ -633,13 +633,13 @@ def _initial_body_parse(self, request: HttpRequest) -> Any:
633633
"""
634634
raise NotImplementedError("_initial_body_parse")
635635

636-
def _create_event_stream(self, request: HttpRequest, shape: Shape) -> Any:
636+
def _create_event_stream(self, request: Request, shape: Shape) -> Any:
637637
# TODO handle event streams
638638
raise NotImplementedError("_create_event_stream")
639639

640-
def create_input_stream(self, request: HttpRequest) -> IO[bytes]:
640+
def create_input_stream(self, request: Request) -> IO[bytes]:
641641
"""
642-
Returns an IO object that makes the payload of the HttpRequest available for streaming.
642+
Returns an IO object that makes the payload of the Request available for streaming.
643643
644644
:param request: the http request
645645
:return: the input stream that allows services to consume the request payload
@@ -661,15 +661,15 @@ def __init__(self, service_model: ServiceModel):
661661
self.ignore_get_body_errors = True
662662
self._namespace_re = re.compile("{.*}")
663663

664-
def _initial_body_parse(self, request: HttpRequest) -> ETree.Element:
664+
def _initial_body_parse(self, request: Request) -> ETree.Element:
665665
body = request.data
666666
if not body:
667667
return ETree.Element("")
668668
return self._parse_xml_string_to_dom(body)
669669

670670
def _parse_structure(
671671
self,
672-
request: HttpRequest,
672+
request: Request,
673673
shape: StructureShape,
674674
node: ETree.Element,
675675
uri_params: Mapping[str, Any] = None,
@@ -704,7 +704,7 @@ def _parse_structure(
704704

705705
def _parse_map(
706706
self,
707-
request: HttpRequest,
707+
request: Request,
708708
shape: MapShape,
709709
node: dict,
710710
uri_params: Mapping[str, Any] = None,
@@ -732,7 +732,7 @@ def _parse_map(
732732

733733
def _parse_list(
734734
self,
735-
request: HttpRequest,
735+
request: Request,
736736
shape: ListShape,
737737
node: dict,
738738
uri_params: Mapping[str, Any] = None,
@@ -799,7 +799,7 @@ def _build_name_to_xml_node(self, parent_node: Union[list, ETree.Element]) -> di
799799
xml_dict[key] = item
800800
return xml_dict
801801

802-
def _create_event_stream(self, request: HttpRequest, shape: Shape) -> Any:
802+
def _create_event_stream(self, request: Request, shape: Shape) -> Any:
803803
# TODO handle event streams
804804
raise NotImplementedError("_create_event_stream")
805805

@@ -814,7 +814,7 @@ class BaseJSONRequestParser(RequestParser, ABC):
814814

815815
def _parse_structure(
816816
self,
817-
request: HttpRequest,
817+
request: Request,
818818
shape: StructureShape,
819819
value: Optional[dict],
820820
uri_params: Mapping[str, Any] = None,
@@ -839,7 +839,7 @@ def _parse_structure(
839839

840840
def _parse_map(
841841
self,
842-
request: HttpRequest,
842+
request: Request,
843843
shape: MapShape,
844844
value: Optional[dict],
845845
uri_params: Mapping[str, Any] = None,
@@ -855,7 +855,7 @@ def _parse_map(
855855
parsed[actual_key] = actual_value
856856
return parsed
857857

858-
def _parse_body_as_json(self, request: HttpRequest) -> dict:
858+
def _parse_body_as_json(self, request: Request) -> dict:
859859
body_contents = request.data
860860
if not body_contents:
861861
return {}
@@ -871,12 +871,12 @@ def _parse_body_as_json(self, request: HttpRequest) -> dict:
871871
raise ProtocolParserError("HTTP body could not be parsed as JSON.") from e
872872

873873
def _parse_boolean(
874-
self, request: HttpRequest, shape: Shape, node: bool, uri_params: Mapping[str, Any] = None
874+
self, request: Request, shape: Shape, node: bool, uri_params: Mapping[str, Any] = None
875875
) -> bool:
876876
return super()._noop_parser(request, shape, node, uri_params)
877877

878878
def _parse_blob(
879-
self, request: HttpRequest, shape: Shape, node: bool, uri_params: Mapping[str, Any] = None
879+
self, request: Request, shape: Shape, node: bool, uri_params: Mapping[str, Any] = None
880880
) -> bytes:
881881
if isinstance(node, bytes) and request.mimetype.startswith("application/x-amz-cbor"):
882882
# CBOR does not base64 encode binary data
@@ -894,7 +894,7 @@ class JSONRequestParser(BaseJSONRequestParser):
894894
"""
895895

896896
@_handle_exceptions
897-
def parse(self, request: HttpRequest) -> Tuple[OperationModel, Any]:
897+
def parse(self, request: Request) -> Tuple[OperationModel, Any]:
898898
target = request.headers["X-Amz-Target"]
899899
# assuming that the last part of the target string (e.g., "x.y.z.MyAction") contains the operation name
900900
operation_name = target.rpartition(".")[2]
@@ -906,7 +906,7 @@ def parse(self, request: HttpRequest) -> Tuple[OperationModel, Any]:
906906
return operation, final_parsed
907907

908908
def _do_parse(
909-
self, request: HttpRequest, shape: Shape, uri_params: Mapping[str, Any] = None
909+
self, request: Request, shape: Shape, uri_params: Mapping[str, Any] = None
910910
) -> dict:
911911
parsed = {}
912912
if shape is not None:
@@ -917,12 +917,12 @@ def _do_parse(
917917
parsed = self._handle_json_body(request, shape, uri_params)
918918
return parsed
919919

920-
def _handle_event_stream(self, request: HttpRequest, shape: Shape, event_name: str):
920+
def _handle_event_stream(self, request: Request, shape: Shape, event_name: str):
921921
# TODO handle event streams
922922
raise NotImplementedError
923923

924924
def _handle_json_body(
925-
self, request: HttpRequest, shape: Shape, uri_params: Mapping[str, Any] = None
925+
self, request: Request, shape: Shape, uri_params: Mapping[str, Any] = None
926926
) -> Any:
927927
# The json.loads() gives us the primitive JSON types, but we need to traverse the parsed JSON data to convert
928928
# to richer types (blobs, timestamps, etc.)
@@ -938,10 +938,10 @@ class RestJSONRequestParser(BaseRestRequestParser, BaseJSONRequestParser):
938938
The operation is defined by the HTTP method and the path suffix.
939939
"""
940940

941-
def _initial_body_parse(self, request: HttpRequest) -> dict:
941+
def _initial_body_parse(self, request: Request) -> dict:
942942
retur 10000 n self._parse_body_as_json(request)
943943

944-
def _create_event_stream(self, request: HttpRequest, shape: Shape) -> Any:
944+
def _create_event_stream(self, request: Request, shape: Shape) -> Any:
945945
raise NotImplementedError
946946

947947

@@ -977,7 +977,7 @@ class VirtualHostRewriter:
977977
a request instead of EnvironBuilder, we should copy it before parsing (except the stream).
978978
"""
979979

980-
def __init__(self, request: HttpRequest):
980+
def __init__(self, request: Request):
981981
self.request = request
982982
self.old_host = None
983983
self.old_path = None
@@ -1017,7 +1017,7 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
10171017

10181018
@staticmethod
10191019
def _set_request_props(
1020-
request: HttpRequest, path: str, host: str, raw_uri: Optional[str] = None
1020+
request: Request, path: str, host: str, raw_uri: Optional[str] = None
10211021
):
10221022
"""Sets the HTTP request's path and host and clears the cache in the request object."""
10231023
request.path = path
@@ -1044,13 +1044,13 @@ def _set_request_props(
10441044
pass
10451045

10461046
@staticmethod
1047-
def _is_vhost_address_get_bucket(request: HttpRequest) -> str | None:
1047+
def _is_vhost_address_get_bucket(request: Request) -> str | None:
10481048
from localstack.services.s3.utils import uses_host_addressing
10491049

10501050
return uses_host_addressing(request.headers)
10511051

10521052
@_handle_exceptions
1053-
def parse(self, request: HttpRequest) -> Tuple[OperationModel, Any]:
1053+
def parse(self, request: Request) -> Tuple[OperationModel, Any]:
10541054
if not LEGACY_V2_S3_PROVIDER:
10551055
"""Handle virtual-host-addressing for S3."""
10561056
with self.VirtualHostRewriter(request):
@@ -1059,7 +1059,7 @@ def parse(self, request: HttpRequest) -> Tuple[OperationModel, Any]:
10591059
return super().parse(request)
10601060

10611061
def _parse_shape(
1062-
self, request: HttpRequest, shape: Shape, node: Any, uri_params: Mapping[str, Any] = None
1062+
self, request: Request, shape: Shape, node: Any, uri_params: Mapping[str, Any] = None
10631063
) -> Any:
10641064
"""
10651065
Special handling of parsing the shape for s3 object-names (=key):

0 commit comments

Comments
 (0)
0