django/django

View on GitHub
django/utils/http.py

Summary

Maintainability
D
1 day
Test Coverage

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

import base64
import calendar
import datetime
import re
import unicodedata
Severity: Minor
Found in django/utils/http.py - About 5 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 limited_parse_qsl has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def limited_parse_qsl(qs, keep_blank_values=False, encoding='utf-8',
                          errors='replace', fields_limit=None):
        """
        Return a list of key/value tuples parsed from query string.
    
    
    Severity: Minor
    Found in django/utils/http.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 _urlsplit has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def _urlsplit(url, scheme='', allow_fragments=True):
        """Parse a URL into 5 components:
        <scheme>://<netloc>/<path>?<query>#<fragment>
        Return a 5-tuple: (scheme, netloc, path, query, fragment).
        Note that we don't break the components up in smaller bits
    Severity: Minor
    Found in django/utils/http.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 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 RFC7231 section 7.1.1.1.
    
        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 _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 limited_parse_qsl has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def limited_parse_qsl(qs, keep_blank_values=False, encoding='utf-8',
    Severity: Minor
    Found in django/utils/http.py - About 35 mins to fix

      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

        There are no issues that match your filters.

        Category
        Status