kennethreitz/requests

View on GitHub
src/requests/cookies.py

Summary

Maintainability
D
1 day
Test Coverage

File cookies.py has 439 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
requests.cookies
~~~~~~~~~~~~~~~~

Compatibility code to be able to use `http.cookiejar.CookieJar` with requests.
Severity: Minor
Found in src/requests/cookies.py - About 6 hrs to fix

    RequestsCookieJar has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
        """Compatibility class; is a http.cookiejar.CookieJar, but exposes a dict
        interface.
    
        This is the CookieJar we create by default for requests and sessions that
    Severity: Minor
    Found in src/requests/cookies.py - About 2 hrs to fix

      Function _find_no_duplicates has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def _find_no_duplicates(self, name, domain=None, path=None):
              """Both ``__get_item__`` and ``get`` call this function: it's never
              used elsewhere in Requests.
      
              :param name: a string containing name of cookie
      Severity: Minor
      Found in src/requests/cookies.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 _find has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def _find(self, name, domain=None, path=None):
              """Requests uses this method internally to get cookie values.
      
              If there are conflicting cookies, _find arbitrarily chooses one.
              See _find_no_duplicates if you want an exception thrown if there are
      Severity: Minor
      Found in src/requests/cookies.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

      Avoid deeply nested control flow statements.
      Open

                              if toReturn is not None:
                                  # if there are multiple cookies that meet passed in criteria
                                  raise CookieConflictError(
                                      f"There are multiple cookies with name, {name!r}"
                                  )
      Severity: Major
      Found in src/requests/cookies.py - About 45 mins to fix

        Function remove_cookie_by_name has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def remove_cookie_by_name(cookiejar, name, domain=None, path=None):
            """Unsets a cookie by name, by default over all domains and paths.
        
            Wraps CookieJar.clear(), is O(n).
            """
        Severity: Minor
        Found in src/requests/cookies.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 merge_cookies has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        def merge_cookies(cookiejar, cookies):
            """Add cookies to cookiejar and returns a merged CookieJar.
        
            :param cookiejar: CookieJar object to add the cookies to.
            :param cookies: Dictionary or CookieJar object to be added.
        Severity: Minor
        Found in src/requests/cookies.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 cookiejar_from_dict has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        def cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True):
            """Returns a CookieJar from a key/value dictionary.
        
            :param cookie_dict: Dict of key/values to insert into CookieJar.
            :param cookiejar: (optional) A cookiejar to add the cookies to.
        Severity: Minor
        Found in src/requests/cookies.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 get_dict has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_dict(self, domain=None, path=None):
                """Takes as an argument an optional domain and path and returns a plain
                old Python dict of name-value pairs of cookies that meet the
                requirements.
        
        
        Severity: Minor
        Found in src/requests/cookies.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