Skip to content

Commit 8ae8ba1

Browse files
authored
feat: cython3 support (#1190)
1 parent 32756ff commit 8ae8ba1

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/zeroconf/_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def async_all_by_details(self, name: _str, type_: int, class_: int) -> Iterable[
144144
"""
145145
return self._async_all_by_details(name, type_, class_)
146146

147-
def _async_all_by_details(self, name: _str, type_: int, class_: int) -> List[DNSRecord]:
147+
def _async_all_by_details(self, name: _str, type_: _int, class_: _int) -> List[DNSRecord]:
148148
"""Gets all matching entries by details.
149149
150150
This function is not thread-safe and must be called from
@@ -258,5 +258,5 @@ def _async_mark_unique_records_older_than_1s_to_expire(
258258
record.set_created_ttl(now, 1)
259259

260260

261-
def _dns_record_matches(record: _DNSRecord, key: _str, type_: int, class_: int) -> bool:
261+
def _dns_record_matches(record: _DNSRecord, key: _str, type_: _int, class_: _int) -> bool:
262262
return key == record.key and type_ == record.type and class_ == record.class_

src/zeroconf/_protocol/incoming.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868
_seen_logs: Dict[str, Union[int, tuple]] = {}
6969
_str = str
70+
_int = int
7071

7172

7273
class DNSIncoming:
@@ -231,7 +232,7 @@ def _read_character_string(self) -> bytes:
231232
self.offset += 1
232233
return self._read_string(length)
233234

234-
def _read_string(self, length: int) -> bytes:
235+
def _read_string(self, length: _int) -> bytes:
235236
"""Reads a string of a given length from the packet"""
236237
info = self.data[self.offset : self.offset + length]
237238
self.offset += length
@@ -267,7 +268,7 @@ def _read_others(self) -> None:
267268
self._answers.append(rec)
268269

269270
def _read_record(
270-
self, domain: _str, type_: int, class_: int, ttl: int, length: int
271+
self, domain: _str, type_: _int, class_: _int, ttl: _int, length: _int
271272
) -> Optional[DNSRecord]:
272273
"""Read known records types and skip unknown ones."""
273274
if type_ == _TYPE_A:
@@ -324,7 +325,7 @@ def _read_record(
324325
self.offset += length
325326
return None
326327

327-
def _read_bitmap(self, end: int) -> List[int]:
328+
def _read_bitmap(self, end: _int) -> List[int]:
328329
"""Reads an NSEC bitmap from the packet."""
329330
rdtypes = []
330331
while self.offset < end:
@@ -355,7 +356,7 @@ def _read_name(self) -> str:
355356
)
356357
return name
357358

358-
def _decode_labels_at_offset(self, off: int, labels: List[str], seen_pointers: Set[int]) -> int:
359+
def _decode_labels_at_offset(self, off: _int, labels: List[str], seen_pointers: Set[int]) -> int:
359360
# This is a tight loop that is called frequently, small optimizations can make a difference.
360361
while off < self._data_len:
361362
length = self.data[off]

src/zeroconf/_protocol/outgoing.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
str_ = str
4444
float_ = float
45+
int_ = int
4546
DNSQuestion_ = DNSQuestion
4647
DNSRecord_ = DNSRecord
4748

@@ -197,20 +198,20 @@ def add_question_or_all_cache(
197198
for cached_entry in cached_entries:
198199
self.add_answer_at_time(cached_entry, now)
199200

200-
def _write_byte(self, value: int) -> None:
201+
def _write_byte(self, value: int_) -> None:
201202
"""Writes a single byte to the packet"""
202203
self.data.append(value.to_bytes(1, 'big'))
203204
self.size += 1
204205

205-
def _insert_short_at_start(self, value: int) -> None:
206+
def _insert_short_at_start(self, value: int_) -> None:
206207
"""Inserts an unsigned short at the start of the packet"""
207208
self.data.insert(0, value.to_bytes(2, 'big'))
208209

209-
def _replace_short(self, index: int, value: int) -> None:
210+
def _replace_short(self, index: int_, value: int_) -> None:
210211
"""Replaces an unsigned short in a certain position in the packet"""
211212
self.data[index] = value.to_bytes(2, 'big')
212213

213-
def write_short(self, value: int) -> None:
214+
def write_short(self, value: int_) -> None:
214215
"""Writes an unsigned short to the packet"""
215216
self.data.append(value.to_bytes(2, 'big'))
216217
self.size += 2
@@ -321,7 +322,7 @@ def _write_record(self, record: DNSRecord_, now: float_) -> bool:
321322
self._replace_short(index, length)
322323
return self._check_data_limit_or_rollback(start_data_length, start_size)
323324

324-
def _check_data_limit_or_rollback(self, start_data_length: int, start_size: int) -> bool:
325+
def _check_data_limit_or_rollback(self, start_data_length: int_, start_size: int_) -> bool:
325326
"""Check data limit, if we go over, then rollback and return False."""
326327
len_limit = _MAX_MSG_ABSOLUTE if self.allow_long else _MAX_MSG_TYPICAL
327328
self.allow_long = False
@@ -338,23 +339,23 @@ def _check_data_limit_or_rollback(self, start_data_length: int, start_size: int)
338339
del self.names[name]
339340
return False
340341

341-
def _write_questions_from_offset(self, questions_offset: int) -> int:
342+
def _write_questions_from_offset(self, questions_offset: int_) -> int:
342343
questions_written = 0
343344
for question in self.questions[questions_offset:]:
344345
if not self._write_question(question):
345346
break
346347
questions_written += 1
347348
return questions_written
348349

349-
def _write_answers_from_offset(self, answer_offset: int) -> int:
350+
def _write_answers_from_offset(self, answer_offset: int_) -> int:
350351
answers_written = 0
351352
for answer, time_ in self.answers[answer_offset:]:
352353
if not self._write_record(answer, time_):
353354
break
354355
answers_written += 1
355356
return answers_written
356357

357-
def _write_records_from_offset(self, records: Sequence[DNSRecord], offset: int) -> int:
358+
def _write_records_from_offset(self, records: Sequence[DNSRecord], offset: int_) -> int:
358359
records_written = 0
359360
for record in records[offset:]:
360361
if not self._write_record(record, 0):
@@ -363,7 +364,7 @@ def _write_records_from_offset(self, records: Sequence[DNSRecord], offset: int)
363364
return records_written
364365

365366
def _has_more_to_add(
366-
self, questions_offset: int, answer_offset: int, authority_offset: int, additional_offset: int
367+
self, questions_offset: int_, answer_offset: int_, authority_offset: int_, additional_offset: int_
367368
) -> bool:
368369
"""Check if all questions, answers, authority, and additionals have been written to the packet."""
369370
return (

0 commit comments

Comments
 (0)