diff --git a/build_ext.py b/build_ext.py index 1b27457da..8e4e7b99f 100644 --- a/build_ext.py +++ b/build_ext.py @@ -31,6 +31,7 @@ def build(setup_kwargs: Any) -> None: "src/zeroconf/_protocol/outgoing.py", "src/zeroconf/_handlers/record_manager.py", "src/zeroconf/_services/registry.py", + "src/zeroconf/_utils/time.py", ], compiler_directives={"language_level": "3"}, # Python 3 ), diff --git a/src/zeroconf/_listener.pxd b/src/zeroconf/_listener.pxd index 0f32a44a7..87ed8b5f2 100644 --- a/src/zeroconf/_listener.pxd +++ b/src/zeroconf/_listener.pxd @@ -1,13 +1,13 @@ import cython +from ._protocol.incoming cimport DNSIncoming +from ._utils.time cimport current_time_millis, millis_to_seconds + -cdef object millis_to_seconds cdef object log cdef object logging_DEBUG -from ._protocol.incoming cimport DNSIncoming - cdef class AsyncListener: diff --git a/src/zeroconf/_utils/time.pxd b/src/zeroconf/_utils/time.pxd new file mode 100644 index 000000000..367f39b66 --- /dev/null +++ b/src/zeroconf/_utils/time.pxd @@ -0,0 +1,4 @@ + +cpdef current_time_millis() + +cpdef millis_to_seconds(object millis) diff --git a/src/zeroconf/_utils/time.py b/src/zeroconf/_utils/time.py index 59362c557..c6811585c 100644 --- a/src/zeroconf/_utils/time.py +++ b/src/zeroconf/_utils/time.py @@ -23,6 +23,8 @@ import time +_float = float + def current_time_millis() -> float: """Current time in milliseconds. @@ -33,6 +35,6 @@ def current_time_millis() -> float: return time.monotonic() * 1000 -def millis_to_seconds(millis: float) -> float: +def millis_to_seconds(millis: _float) -> float: """Convert milliseconds to seconds.""" return millis / 1000.0