django/django

View on GitHub
django/http/response.py

Summary

Maintainability
D
2 days
Test Coverage

File response.py has 413 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import datetime
import json
import mimetypes
import os
import re
Severity: Minor
Found in django/http/response.py - About 5 hrs to fix

    HttpResponseBase has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class HttpResponseBase:
        """
        An HTTP response base class with dictionary-accessed headers.
    
        This class doesn't handle content. It should not be used directly.
    Severity: Minor
    Found in django/http/response.py - About 3 hrs to fix

      Function set_cookie has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def set_cookie(self, key, value='', max_age=None, expires=None, path='/',
                         domain=None, secure=False, httponly=False, samesite=None):
              """
              Set a cookie.
      
      
      Severity: Minor
      Found in django/http/response.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 set_headers has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def set_headers(self, filelike):
              """
              Set some common response headers (Content-Length, Content-Type, and
              Content-Disposition) based on the `filelike` response content.
              """
      Severity: Minor
      Found in django/http/response.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 _convert_to_charset has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def _convert_to_charset(self, value, charset, mime_encode=False):
              """
              Convert headers key/value to ascii/latin-1 native strings.
      
              `charset` must be 'ascii' or 'latin-1'. If `mime_encode` is True and
      Severity: Minor
      Found in django/http/response.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 set_cookie has 9 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def set_cookie(self, key, value='', max_age=None, expires=None, path='/',
      Severity: Major
      Found in django/http/response.py - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

                if ((isinstance(value, bytes) and (b'\n' in value or b'\r' in value)) or
                        isinstance(value, str) and ('\n' in value or '\r' in value)):
                    raise BadHeaderError("Header values can't contain newlines (got %r)" % value)
                try:
        Severity: Major
        Found in django/http/response.py - About 40 mins to fix

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

              def __init__(self, data, encoder=DjangoJSONEncoder, safe=True,
          Severity: Minor
          Found in django/http/response.py - About 35 mins to fix

            Function content has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def content(self, value):
                    # Consume iterators upon assignment to allow repeated iteration.
                    if hasattr(value, '__iter__') and not isinstance(value, (bytes, str)):
                        content = b''.join(self.make_bytes(chunk) for chunk in value)
                        if hasattr(value, 'close'):
            Severity: Minor
            Found in django/http/response.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 __init__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def __init__(self, content_type=None, status=None, reason=None, charset=None):
                    # _headers is a mapping of the lowercase name to the original case of
                    # the header (required for working with legacy systems) and the header
                    # value. Both the name of the header and its value are ASCII strings.
                    self._headers = {}
            Severity: Minor
            Found in django/http/response.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