kennethreitz/requests

View on GitHub
src/requests/utils.py

Summary

Maintainability
F
4 days
Test Coverage

File utils.py has 776 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
requests.utils
~~~~~~~~~~~~~~

This module provides utility functions that are used within Requests
Severity: Major
Found in src/requests/utils.py - About 1 day to fix

    Function should_bypass_proxies has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    def should_bypass_proxies(url, no_proxy):
        """
        Returns whether we should bypass proxies or not.
    
        :rtype: bool
    Severity: Minor
    Found in src/requests/utils.py - About 4 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 super_len has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def super_len(o):
        total_length = None
        current_position = 0
    
        if isinstance(o, str):
    Severity: Minor
    Found in src/requests/utils.py - About 3 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 proxy_bypass_registry has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def proxy_bypass_registry(host):
            try:
                import winreg
            except ImportError:
                return False
    Severity: Minor
    Found in src/requests/utils.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 get_netrc_auth has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_netrc_auth(url, raise_errors=False):
        """Returns the Requests tuple auth for a given url from netrc."""
    
        netrc_file = os.environ.get("NETRC")
        if netrc_file is not None:
    Severity: Minor
    Found in src/requests/utils.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 guess_json_utf has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def guess_json_utf(data):
        """
        :rtype: str
        """
        # JSON always starts with two ASCII characters, so detection is as
    Severity: Minor
    Found in src/requests/utils.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 unquote_unreserved has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def unquote_unreserved(uri):
        """Un-escape any percent-escape sequences in a URI that are unreserved
        characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
    
        :rtype: str
    Severity: Minor
    Found in src/requests/utils.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 is_valid_cidr has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def is_valid_cidr(string_network):
        """
        Very simple check of the cidr format in no_proxy variable.
    
        :rtype: bool
    Severity: Minor
    Found in src/requests/utils.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_header_links has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def parse_header_links(value):
        """Return a list of parsed link headers proxies.
    
        i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"
    
    
    Severity: Minor
    Found in src/requests/utils.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

    Avoid deeply nested control flow statements.
    Open

                        if address_in_network(parsed.hostname, proxy_ip):
                            return True
                    elif parsed.hostname == proxy_ip:
    Severity: Major
    Found in src/requests/utils.py - About 45 mins to fix

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

      def extract_zipped_paths(path):
          """Replace nonexistent paths that look like they refer to a member of a zip
          archive with the location of an extracted copy of the target, or else
          just return the provided path unchanged.
          """
      Severity: Minor
      Found in src/requests/utils.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 "utf-32-be"
      Severity: Major
      Found in src/requests/utils.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            return None
        Severity: Major
        Found in src/requests/utils.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return True
          Severity: Major
          Found in src/requests/utils.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return False
            Severity: Major
            Found in src/requests/utils.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return "utf-16-be"
              Severity: Major
              Found in src/requests/utils.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return "utf-16-le"
                Severity: Major
                Found in src/requests/utils.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return True
                  Severity: Major
                  Found in src/requests/utils.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return "utf-32-le"
                    Severity: Major
                    Found in src/requests/utils.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return True
                      Severity: Major
                      Found in src/requests/utils.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return False
                        Severity: Major
                        Found in src/requests/utils.py - About 30 mins to fix

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

                          def _parse_content_type_header(header):
                              """Returns content type and parameters from given header
                          
                              :param header: string
                              :return: tuple containing content type and dictionary of
                          Severity: Minor
                          Found in src/requests/utils.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