ettoreleandrotognoli/python-ami

View on GitHub

Showing 10 of 14 total issues

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

class AMIClient(object):
    asterisk_start_regex = re.compile(r'^Asterisk *Call *Manager/(?P<version>([0-9]+\.)*[0-9]+)', re.IGNORECASE)
    asterisk_line_regex = re.compile(b'\r\n', re.IGNORECASE | re.MULTILINE)
    asterisk_pack_regex = re.compile(b'\r\n\r\n', re.IGNORECASE | re.MULTILINE)

Severity: Minor
Found in asterisk/ami/client.py - About 2 hrs to fix

    File client.py has 274 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import re
    import socket
    import threading
    from functools import partial
    
    
    Severity: Minor
    Found in asterisk/ami/client.py - About 2 hrs to fix

      Function read has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def read(response):
              lines = response.splitlines()
              (key, value) = map(lambda s: s.strip(), lines[0].split(':', 1))
              if not key.lower() == 'response':
                  raise Exception()
      Severity: Minor
      Found in asterisk/ami/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 _next_pack has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def _next_pack(self):
              data = b''
              while not self.finished.is_set():
                  recv = self._socket.recv(self._buffer_size)
                  if recv == b'':
      Severity: Minor
      Found in asterisk/ami/client.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 __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, address='127.0.0.1', port=5038,
      Severity: Major
      Found in asterisk/ami/client.py - About 50 mins to fix

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

            def check_white_list(self, event_name):
                if self.white_list is None:
                    return True
                for rule in self.white_list:
                    if isinstance(rule, basestring) and event_name == rule:
        Severity: Minor
        Found in asterisk/ami/event.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 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, on_event=None, white_list=None, black_list=[], **kwargs):
                self.white_list = [white_list] if isinstance(white_list, (basestring, PatternType)) else white_list
                self.black_list = [black_list] if isinstance(black_list, (basestring, PatternType)) else black_list
                for k in list(kwargs.keys()):
                    if k.startswith('on_'):
        Severity: Minor
        Found in asterisk/ami/event.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 read has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def read(event):
                lines = event.splitlines()
                (key, value) = lines[0].split(': ', 1)
                if not key.lower() == 'event':
                    raise Exception()
        Severity: Minor
        Found in asterisk/ami/event.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 check_attribute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def check_attribute(self, rules, value):
                if isinstance(rules, (PatternType, basestring)):
                    rules = [rules]
                for rule in rules:
                    if isinstance(rule, basestring) and rule == value:
        Severity: Minor
        Found in asterisk/ami/event.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

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

            def _login_wrapper(self, *args, **kwargs):
                callback = kwargs.pop('callback', None) or (lambda *a, **k: None)
        
                def on_login(response, *a, **k):
                    if not response.is_error():
        Severity: Minor
        Found in asterisk/ami/client.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

        Severity
        Category
        Status
        Source
        Language