knipknap/exscript

View on GitHub
Exscript/protocols/protocol.py

Summary

Maintainability
F
6 days
Test Coverage

File protocol.py has 1036 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#
# Copyright (C) 2010-2017 Samuel Abels
# The MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining
Severity: Major
Found in Exscript/protocols/protocol.py - About 2 days to fix

    Protocol has 60 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Protocol(object):
    
        """
        This is the base class for all protocols; it defines the common portions
        of the API.
    Severity: Major
    Found in Exscript/protocols/protocol.py - About 1 day to fix

      Function _app_authenticate has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

          def _app_authenticate(self,
                                account,
                                password,
                                flush=True,
                                bailout=False):
      Severity: Minor
      Found in Exscript/protocols/protocol.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 _open_posix_shell has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          def _open_posix_shell(self,
                                channel,
                                key_handlers,
                                handle_window_size):
              # We need to make sure to use an unbuffered stdin, else multi-byte
      Severity: Minor
      Found in Exscript/protocols/protocol.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 __init__ has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(self,
                       driver=None,
                       stdout=None,
                       stderr=None,
                       debug=0,
      Severity: Minor
      Found in Exscript/protocols/protocol.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 _open_windows_shell has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def _open_windows_shell(self, channel, key_handlers, handle_window_size):
              import threading
      
              def writeall(sock):
                  while True:
      Severity: Minor
      Found in Exscript/protocols/protocol.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 12 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self,
      Severity: Major
      Found in Exscript/protocols/protocol.py - About 1 hr to fix

        Function __init__ has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def __init__(self,
                         driver=None,
                         stdout=None,
                         stderr=None,
                         debug=0,
        Severity: Minor
        Found in Exscript/protocols/protocol.py - About 1 hr to fix

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

              def expect_prompt(self, consume=True):
                  """
                  Monitors the data received from the remote host and waits for a
                  prompt in the response. The prompt attempts to use
                  a sane default that works with many devices running Unix, IOS,
          Severity: Minor
          Found in Exscript/protocols/protocol.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

          Avoid deeply nested control flow statements.
          Open

                                      if not self.send_data is None:
                                          self.send_data.write(data)
                                      channel.send(data.encode(self.encoding))
          Severity: Major
          Found in Exscript/protocols/protocol.py - About 45 mins to fix

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

                def _get_account(self, account):
                    if isinstance(account, Context) or isinstance(account, _Context):
                        return account.context()
                    if account is None:
                        account = self.last_account
            Severity: Minor
            Found in Exscript/protocols/protocol.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 _call_key_handlers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def _call_key_handlers(self, key_handlers, data):
                    if key_handlers is not None:
                        for key, func in list(key_handlers.items()):
                            if data == key:
                                func(self)
            Severity: Minor
            Found in Exscript/protocols/protocol.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 set_driver has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def set_driver(self, driver=None):
                    """
                    Defines the driver that is used to recognize prompts and implement
                    behavior depending on the remote system.
                    The driver argument may be an instance of a protocols.drivers.Driver
            Severity: Minor
            Found in Exscript/protocols/protocol.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

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

                def set_username_prompt(self, regex=None):
                    """
                    Defines a pattern that is used to monitor the response of the
                    connected host for a username prompt.
            
            
            Severity: Major
            Found in Exscript/protocols/protocol.py and 4 other locations - About 1 hr to fix
            Exscript/protocols/protocol.py on lines 471..482
            Exscript/protocols/protocol.py on lines 496..510
            Exscript/protocols/protocol.py on lines 524..536
            Exscript/protocols/protocol.py on lines 550..562

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 41.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

                def set_password_prompt(self, regex=None):
                    """
                    Defines a pattern that is used to monitor the response of the
                    connected host for a password prompt.
            
            
            Severity: Major
            Found in Exscript/protocols/protocol.py and 4 other locations - About 1 hr to fix
            Exscript/protocols/protocol.py on lines 446..457
            Exscript/protocols/protocol.py on lines 496..510
            Exscript/protocols/protocol.py on lines 524..536
            Exscript/protocols/protocol.py on lines 550..562

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 41.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

                def set_login_error_prompt(self, error=None):
                    """
                    Defines a pattern that is used to monitor the response of the
                    connected host during the authentication procedure.
                    If the pattern matches an error is raised.
            Severity: Major
            Found in Exscript/protocols/protocol.py and 4 other locations - About 1 hr to fix
            Exscript/protocols/protocol.py on lines 446..457
            Exscript/protocols/protocol.py on lines 471..482
            Exscript/protocols/protocol.py on lines 496..510
            Exscript/protocols/protocol.py on lines 524..536

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 41.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

                def set_prompt(self, prompt=None):
                    """
                    Defines a pattern that is waited for when calling the expect_prompt()
                    method.
                    If the set_prompt() method is not called, or if it is called with the
            Severity: Major
            Found in Exscript/protocols/protocol.py and 4 other locations - About 1 hr to fix
            Exscript/protocols/protocol.py on lines 446..457
            Exscript/protocols/protocol.py on lines 471..482
            Exscript/protocols/protocol.py on lines 524..536
            Exscript/protocols/protocol.py on lines 550..562

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 41.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 5 locations. Consider refactoring.
            Open

                def set_error_prompt(self, error=None):
                    """
                    Defines a pattern that is used to monitor the response of the
                    connected host. If the pattern matches (any time the expect() or
                    expect_prompt() methods are used), an error is raised.
            Severity: Major
            Found in Exscript/protocols/protocol.py and 4 other locations - About 1 hr to fix
            Exscript/protocols/protocol.py on lines 446..457
            Exscript/protocols/protocol.py on lines 471..482
            Exscript/protocols/protocol.py on lines 496..510
            Exscript/protocols/protocol.py on lines 550..562

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 41.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                def waitfor(self, prompt):
                    """
                    Monitors the data received from the remote host and waits until
                    the response matches the given prompt.
                    Once a match has been found, the buffer containing incoming data
            Severity: Minor
            Found in Exscript/protocols/protocol.py and 1 other location - About 50 mins to fix
            Exscript/protocols/protocol.py on lines 1036..1061

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 36.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                def expect(self, prompt):
                    """
                    Like waitfor(), but also removes the matched string from the buffer
                    containing the incoming data. In other words, the following may not
                    alway complete::
            Severity: Minor
            Found in Exscript/protocols/protocol.py and 1 other location - About 50 mins to fix
            Exscript/protocols/protocol.py on lines 989..1030

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 36.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status