File net.py
has 405 lines of code (exceeds 250 allowed). Consider refactoring. Open
import logging
import random
import re
import socket
import threading
Function is_port_open
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
def is_port_open(
port_or_url: Union[int, str],
http_path: str = None,
expect_success: bool = True,
protocols: Optional[Union[str, List[str]]] = None,
- Read upRead up
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_free_tcp_port_range
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def get_free_tcp_port_range(num_ports: int, max_attempts: int = 50) -> "PortRange":
"""
Attempts to get a contiguous range of free ports from the dynamic port range. For instance,
``get_free_tcp_port_range(4)`` may return the following result: ``PortRange(44000:44004)``.
- Read upRead up
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 reserve_port
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def reserve_port(self, port: Optional[IntOrPort] = None, duration: Optional[int] = None) -> int:
"""
Reserves the given port (if it is still free). If the given port is None, it reserves a free port from the
configured port range for external services. If a port is given, it has to be within the configured
range of external services (i.e., in the range [self.start, self.end)).
- Read upRead up
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 wait_for_port_status
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def wait_for_port_status(
Function send_dns_query
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def send_dns_query(
Avoid deeply nested control flow statements. Open
if not quiet:
LOG.warning(
"Error connecting to TCP port %s:%s (result=%s)", host, port, result
)
return False
Function wait_for_port_closed
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def wait_for_port_closed(
Function wait_for_port_open
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def wait_for_port_open(
Function is_port_open
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def is_port_open(
Function get_free_tcp_port
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def get_free_tcp_port(blocklist: List[int] = None) -> int:
"""
Tries to bind a socket to port 0 and returns the port that was assigned by the system. If the port is
in the given ``blocklist``, or the port is marked as reserved in ``dynamic_port_range``, the procedure
is repeated for up to 50 times.
- Read upRead up
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 False