django/django

View on GitHub
django/utils/http.py

Summary

Maintainability
C
1 day
Test Coverage

File http.py has 298 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import base64
import re
import unicodedata
from binascii import Error as BinasciiError
from datetime import datetime, timezone
Severity: Minor
Found in django/utils/http.py - About 3 hrs to fix

    Function urlencode has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def urlencode(query, doseq=False):
        """
        A version of Python's urllib.parse.urlencode() function that can operate on
        MultiValueDict and non-string values.
        """
    Severity: Minor
    Found in django/utils/http.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 parse_header_parameters has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def parse_header_parameters(line):
        """
        Parse a Content-type like header.
        Return the main content-type and a dictionary of options.
        """
    Severity: Minor
    Found in django/utils/http.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 _url_has_allowed_host_and_scheme has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def _url_has_allowed_host_and_scheme(url, allowed_hosts, require_https=False):
        # Chrome considers any URL with more than two slashes to be absolute, but
        # urlparse is not so flexible. Treat any url with three slashes as unsafe.
        if url.startswith("///"):
            return False
    Severity: Minor
    Found in django/utils/http.py - About 55 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 parse_http_date has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def parse_http_date(date):
        """
        Parse a date format as specified by HTTP RFC 9110 Section 5.6.7.
    
        The three formats allowed by the RFC are accepted, even if only the first
    Severity: Minor
    Found in django/utils/http.py - About 55 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 content_disposition_header has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def content_disposition_header(as_attachment, filename):
        """
        Construct a Content-Disposition HTTP header value from the given filename
        as specified by RFC 6266.
        """
    Severity: Minor
    Found in django/utils/http.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 (not url_info.netloc or url_info.netloc in allowed_hosts) and (
    Severity: Major
    Found in django/utils/http.py - About 30 mins to fix

      Function _parseparam has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

      def _parseparam(s):
          while s[:1] == ";":
              s = s[1:]
              end = s.find(";")
              while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
      Severity: Minor
      Found in django/utils/http.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