8000 feat: add more cython typing to DNSRecord · python-zeroconf/python-zeroconf@2c6ae75 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c6ae75

Browse files
committed
feat: add more cython typing to DNSRecord
1 parent e0f8a0e commit 2c6ae75

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/zeroconf/_dns.pxd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ cdef class DNSRecord(DNSEntry):
4646

4747
cpdef set_created_ttl(self, cython.float created, cython.float ttl)
4848

49+
cpdef get_remaining_ttl(self, cython.float current_time)
50+
51+
cpdef is_expired(self, cython.float current_time)
52+
53+
cpdef is_stale(self, cython.float current_time)
54+
55+
cpdef is_recent(self, cython.float current_time)
56+
4957
cdef class DNSAddress(DNSRecord):
5058

5159
cdef public cython.int _hash

src/zeroconf/_dns.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,19 @@ def get_expiration_time(self, percent: int_) -> float:
192192
return self.created + (percent * self.ttl * 10)
193193

194194
# TODO: Switch to just int here
195-
def get_remaining_ttl(self, now: float) -> int_or_float_:
195+
def get_remaining_ttl(self, now: float_) -> int_or_float_:
196196
"""Returns the remaining TTL in seconds."""
197197
return max(0, millis_to_seconds((self.created + (_EXPIRE_FULL_TIME_MS * self.ttl)) - now))
198198

199-
def is_expired(self, now: float) -> bool:
199+
def is_expired(self, now: float_) -> bool:
200200
"""Returns true if this record has expired."""
201201
return self.creat 8765 ed + (_EXPIRE_FULL_TIME_MS * self.ttl) <= now
202202

203-
def is_stale(self, now: float) -> bool:
203+
def is_stale(self, now: float_) -> bool:
204204
"""Returns true if this record is at least half way expired."""
205205
return self.created + (_EXPIRE_STALE_TIME_MS * self.ttl) <= now
206206

207-
def is_recent(self, now: float) -> bool:
207+
def is_recent(self, now: float_) -> bool:
208208
"""Returns true if the record more than one quarter of its TTL remaining."""
209209
return self.created + (_RECENT_TIME_MS * self.ttl) > now
210210

0 commit comments

Comments
 (0)
0