File serializer.py
has 1503 lines of code (exceeds 250 allowed). Consider refactoring. Open
"""
Response serializers for the different AWS service protocols.
The module contains classes that take a service's response dict, and
given an operation model, serialize the HTTP response according to the
Function _serialize_event_stream
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def _serialize_event_stream(
self,
response: dict,
operation_model: OperationModel,
mime_type: str,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
ResponseSerializer
has 21 functions (exceeds 20 allowed). Consider refactoring. Open
class ResponseSerializer(abc.ABC):
"""
The response serializer is responsible for the serialization of a service implementation's result to an actual
HTTP response (which will be sent to the calling client).
It is the base class of all serializers and therefore contains the basic logic which is used among all of them.
Function _serialize_type_structure
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def _serialize_type_structure(
self, body: dict, value: dict, shape: StructureShape, key: Optional[str], mime_type: str
):
if value is None:
return
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function aws_response_serializer
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def aws_response_serializer(
service_name: str, operation: str, protocol: Optional[ProtocolName] = None
):
"""
A decorator for an HTTP route that can serialize return values or exceptions into AWS responses.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _serialize_error
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def _serialize_error(
self,
error: ServiceException,
response: Response,
shape: StructureShape,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _serialize_payload
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def _serialize_payload(
self,
parameters: dict,
response: Response,
shape: Optional[Shape],
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _add_additional_error_tags
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def _add_additional_error_tags(
self, parameters: dict, node: ETree, shape: StructureShape, mime_type: str
):
if shape:
params = {}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _process_header_members
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def _process_header_members(self, parameters: dict, response: Response, shape: Shape):
shape_members = shape.members if isinstance(shape, StructureShape) else []
for name in shape_members:
member_shape = shape_members[name]
location = member_shape.serialization.get("location")
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _serialize_type_structure
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def _serialize_type_structure(
self, xmlnode: ETree.Element, params: dict, shape: StructureShape, name: str, mime_type
) -> None:
structure_node = ETree.SubElement(xmlnode, name)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _serialize_response
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_response(
Function _serialize_payload
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_payload(
Function _serialize_response
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_response(
Function _serialize_response
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_response(
Function _serialize_response
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_response(
Function _serialize_response
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_response(
Function _serialize_error
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_error(
Function _serialize_error
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_error(
Function _serialize_error
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_error(
Function _serialize_error
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_error(
Function _encode_event_payload
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def _encode_event_payload(
self,
event_type: str,
content: Union[str, bytes] = "",
error_code: Optional[str] = None,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _serialize_error
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_error(
Function _serialize_error
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_error(
Function _serialize_type_structure
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_type_structure(
Function _serialize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize(
Function _serialize_type_blob
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_type_blob(
Function _serialize_body_params
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_body_params(
Function _serialize_type_map
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_type_map(
Function _serialize_type_list
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_type_list(
Function _serialize_body_params
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_body_params(
Function _serialize_type_structure
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_type_structure(
Function _serialize_type_blob
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_type_blob(
Function _serialize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize(self, body: dict, value: Any, shape, key: Optional[str], mime_type: str):
Function _serialize_type_list
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_type_list(
Function _serialize_body_params
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_body_params(
Function _serialize_type_map
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_type_map(
Function _serialize_body_params
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_body_params(
Function _default_serialize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _default_serialize(self, xmlnode: ETree.Element, params: str, _, name: str, __) -> None:
Function _serialize_type_timestamp
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_type_timestamp(
Function _default_serialize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _default_serialize(self, body: dict, value: Any, _, key: str, __):
Function _default_serialize
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _default_serialize(self, xmlnode: ETree.Element, params: str, _, name: str, __) -> None:
Function _serialize_type_timestamp
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def _serialize_type_timestamp(
Function _partition_members
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _partition_members(self, parameters: dict, shape: Optional[Shape]) -> Tuple[dict, dict]:
"""Separates the top-level keys in the given parameters dict into header- and payload-located params."""
if not isinstance(shape, StructureShape):
# If the shape isn't a structure, we default to the whole response being parsed in the body.
# Non-payload members are only loaded in the top-level hierarchy and those are always structures.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _serialize_header_value
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _serialize_header_value(self, shape: Shape, value: Any):
"""Serializes a value for the location trait "header"."""
if shape.type_name == "timestamp":
datetime_obj = parse_to_aware_datetime(value)
timestamp_format = shape.serialization.get(
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return value
Function _add_error_tags
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _add_error_tags(
self, error: ServiceException, error_tag: ETree.Element, mime_type: str
) -> None:
"""The SQS API stubs is now generated from JSON specs, and some fields have been modified"""
code_tag = ETree.SubElement(error_tag, "Code")
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _serialize_type_map
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _serialize_type_map(
self, xmlnode: ETree.Element, params: dict, shape: MapShape, name: str, mime_type: str
) -> None:
"""
Given the ``name`` of MyMap, an input of {"key1": "val1", "key2": "val2"}, and the ``flattened: False``
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _serialize_type_list
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _serialize_type_list(
self, xmlnode: ETree.Element, params: list, shape: ListShape, name: str, mime_type: str
) -> None:
if params is None:
# Don't serialize any param whose value is None.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"