diff --git a/scapy/contrib/isotp/isotp_soft_socket.py b/scapy/contrib/isotp/isotp_soft_socket.py index 52100b008d9..7febde3b696 100644 --- a/scapy/contrib/isotp/isotp_soft_socket.py +++ b/scapy/contrib/isotp/isotp_soft_socket.py @@ -38,6 +38,7 @@ Callable, TYPE_CHECKING, ) + if TYPE_CHECKING: from scapy.contrib.cansocket import CANSocket @@ -223,6 +224,8 @@ class TimeoutScheduler: # use heapq functions on _handles! _handles = [] # type: List[TimeoutScheduler.Handle] + logger = logging.getLogger("scapy.contrib.automotive.timeout_scheduler") + @classmethod def schedule(cls, timeout, callback): # type: (float, Callable[[], None]) -> TimeoutScheduler.Handle @@ -311,13 +314,13 @@ def _wait(cls, handle): # Wait until the next timeout, # or until event.set() gets called in another thread. if to_wait > 0: - log_isotp.debug("TimeoutScheduler Thread going to sleep @ %f " + - "for %fs", now, to_wait) + cls.logger.debug("Thread going to sleep @ %f " + + "for %fs", now, to_wait) interrupted = cls._event.wait(to_wait) new = cls._time() - log_isotp.debug("TimeoutScheduler Thread awake @ %f, slept for" + - " %f, interrupted=%d", new, new - now, - interrupted) + cls.logger.debug("Thread awake @ %f, slept for" + + " %f, interrupted=%d", new, new - now, + interrupted) # Clear the event so that we can wait on it again, # Must be done before doing the callbacks to avoid losing a set(). @@ -330,7 +333,7 @@ def _task(cls): start when the first timeout is added and stop when the last timeout is removed or executed.""" - log_isotp.debug("TimeoutScheduler Thread spawning @ %f", cls._time()) + cls.logger.debug("Thread spawning @ %f", cls._time()) time_empty = None @@ -352,7 +355,7 @@ def _task(cls): finally: # Worst case scenario: if this thread dies, the next scheduled # timeout will start a new one - log_isotp.debug("TimeoutScheduler Thread died @ %f", cls._time()) + cls.logger.debug("Thread died @ %f", cls._time()) cls._thread = None @classmethod diff --git a/scapy/packet.py b/scapy/packet.py index e5e06571d1c..33e624862bb 100644 --- a/scapy/packet.py +++ b/scapy/packet.py @@ -21,6 +21,8 @@ import types import warnings +from typing_extensions import Self + from scapy.fields import ( AnyField, BitField, @@ -61,9 +63,8 @@ TypeVar, Union, Sequence, - cast, + cast ) -from scapy.compat import Self try: import pyx