localstack/localstack

View on GitHub
localstack/aws/protocol/serializer.py

Summary

Maintainability
F
1 wk
Test Coverage

File serializer.py has 1505 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
Severity: Major
Found in localstack/aws/protocol/serializer.py - About 4 days to fix

    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,
    Severity: Minor
    Found in localstack/aws/protocol/serializer.py - About 2 hrs to fix

    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.
    Severity: Minor
    Found in localstack/aws/protocol/serializer.py - About 2 hrs to fix

      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
      Severity: Minor
      Found in localstack/aws/protocol/serializer.py - About 2 hrs to fix

      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.
      Severity: Minor
      Found in localstack/aws/protocol/serializer.py - About 1 hr to fix

      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: HttpResponse,
              shape: StructureShape,
      Severity: Minor
      Found in localstack/aws/protocol/serializer.py - About 1 hr to fix

      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: HttpResponse,
              shape: Optional[Shape],
      Severity: Minor
      Found in localstack/aws/protocol/serializer.py - About 1 hr to fix

      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: HttpResponse, 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")
      Severity: Minor
      Found in localstack/aws/protocol/serializer.py - About 1 hr to fix

      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 = {}
      Severity: Minor
      Found in localstack/aws/protocol/serializer.py - About 1 hr to fix

      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)
      
      
      Severity: Minor
      Found in localstack/aws/protocol/serializer.py - About 1 hr to fix

      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(
      Severity: Major
      Found in localstack/aws/protocol/serializer.py - About 50 mins to fix

        Function _serialize_response has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def _serialize_response(
        Severity: Major
        Found in localstack/aws/protocol/serializer.py - About 50 mins to fix

          Function _serialize_response has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def _serialize_response(
          Severity: Major
          Found in localstack/aws/protocol/serializer.py - About 50 mins to fix

            Function _serialize_response has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                def _serialize_response(
            Severity: Major
            Found in localstack/aws/protocol/serializer.py - About 50 mins to fix

              Function _serialize_payload has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def _serialize_payload(
              Severity: Major
              Found in localstack/aws/protocol/serializer.py - About 50 mins to fix

                Function _serialize_response has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def _serialize_response(
                Severity: Major
                Found in localstack/aws/protocol/serializer.py - About 50 mins to fix

                  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,
                  Severity: Minor
                  Found in localstack/aws/protocol/serializer.py - About 45 mins to fix

                  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(
                  Severity: Minor
                  Found in localstack/aws/protocol/serializer.py - About 45 mins to fix

                    Function _serialize_error has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def _serialize_error(
                    Severity: Minor
                    Found in localstack/aws/protocol/serializer.py - About 45 mins to fix

                      Function _serialize_error has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          def _serialize_error(
                      Severity: Minor
                      Found in localstack/aws/protocol/serializer.py - About 45 mins to fix

                        Function _serialize_error has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            def _serialize_error(
                        Severity: Minor
                        Found in localstack/aws/protocol/serializer.py - About 45 mins to fix

                          Function _serialize_error has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              def _serialize_error(
                          Severity: Minor
                          Found in localstack/aws/protocol/serializer.py - About 45 mins to fix

                            Function _serialize_error has 6 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                def _serialize_error(
                            Severity: Minor
                            Found in localstack/aws/protocol/serializer.py - About 45 mins to fix

                              Function _serialize_body_params has 5 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                  def _serialize_body_params(
                              Severity: Minor
                              Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                Function _serialize_type_blob has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                    def _serialize_type_blob(
                                Severity: Minor
                                Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                  Function _serialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                      def _serialize(
                                  Severity: Minor
                                  Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                    Function _default_serialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                    Open

                                        def _default_serialize(self, body: dict, value: Any, _, key: str, __):
                                    Severity: Minor
                                    Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                      Function _serialize_type_timestamp has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                      Open

                                          def _serialize_type_timestamp(
                                      Severity: Minor
                                      Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                        Function _serialize_body_params has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                        Open

                                            def _serialize_body_params(
                                        Severity: Minor
                                        Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                          Function _serialize_type_list has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                          Open

                                              def _serialize_type_list(
                                          Severity: Minor
                                          Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                            Function _serialize_type_map has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                            Open

                                                def _serialize_type_map(
                                            Severity: Minor
                                            Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                              Function _serialize_body_params has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                              Open

                                                  def _serialize_body_params(
                                              Severity: Minor
                                              Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                Function _serialize_type_map has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                Open

                                                    def _serialize_type_map(
                                                Severity: Minor
                                                Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                  Function _default_serialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                  Open

                                                      def _default_serialize(self, xmlnode: ETree.Element, params: str, _, name: str, __) -> None:
                                                  Severity: Minor
                                                  Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                    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):
                                                    Severity: Minor
                                                    Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                      Function _serialize_body_params has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                      Open

                                                          def _serialize_body_params(
                                                      Severity: Minor
                                                      Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                        Function _serialize_type_list has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                        Open

                                                            def _serialize_type_list(
                                                        Severity: Minor
                                                        Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                          Function _serialize_type_structure has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                          Open

                                                              def _serialize_type_structure(
                                                          Severity: Minor
                                                          Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                            Function _serialize_type_blob has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                            Open

                                                                def _serialize_type_blob(
                                                            Severity: Minor
                                                            Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                              Function _serialize_type_timestamp has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                              Open

                                                                  def _serialize_type_timestamp(
                                                              Severity: Minor
                                                              Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                                Function _serialize_type_structure has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                Open

                                                                    def _serialize_type_structure(
                                                                Severity: Minor
                                                                Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                                  Function _default_serialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                                                  Open

                                                                      def _default_serialize(self, xmlnode: ETree.Element, params: str, _, name: str, __) -> None:
                                                                  Severity: Minor
                                                                  Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                                    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(
                                                                    Severity: Minor
                                                                    Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                                    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 _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.
                                                                    Severity: Minor
                                                                    Found in localstack/aws/protocol/serializer.py - About 35 mins to fix

                                                                    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
                                                                    Severity: Major
                                                                    Found in localstack/aws/protocol/serializer.py - About 30 mins to fix

                                                                      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.
                                                                      Severity: Minor
                                                                      Found in localstack/aws/protocol/serializer.py - About 25 mins to fix

                                                                      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``
                                                                      Severity: Minor
                                                                      Found in localstack/aws/protocol/serializer.py - About 25 mins to fix

                                                                      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_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")
                                                                      Severity: Minor
                                                                      Found in localstack/aws/protocol/serializer.py - About 25 mins to fix

                                                                      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

                                                                      There are no issues that match your filters.

                                                                      Category
                                                                      Status