Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/zeroconf/_cache.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cython

from ._dns cimport (
DNSAddress,
DNSEntry,
Expand All @@ -10,6 +11,7 @@ from ._dns cimport (
)


cdef object _UNIQUE_RECORD_TYPES
cdef object _TYPE_PTR

cdef _remove_key(cython.dict cache, object key, DNSRecord record)
Expand Down
11 changes: 7 additions & 4 deletions src/zeroconf/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,17 @@ def async_get_unique(self, entry: _UniqueRecordsType) -> Optional[DNSRecord]:
return None
return store.get(entry)

def async_all_by_details(self, name: str, type_: int, class_: int) -> Iterator[DNSRecord]:
def async_all_by_details(self, name: _str, type_: int, class_: int) -> Iterator[DNSRecord]:
"""Gets all matching entries by details.

This function is not threadsafe and must be called from
the event loop.
"""
key = name.lower()
for entry in self.cache.get(key, []):
records = self.cache.get(key)
if records is None:
return
for entry in records:
if _dns_record_matches(entry, key, type_, class_):
yield entry

Expand All @@ -151,15 +154,15 @@ def async_entries_with_name(self, name: str) -> Dict[DNSRecord, DNSRecord]:
This function is not threadsafe and must be called from
the event loop.
"""
return self.cache.get(name.lower(), {})
return self.cache.get(name.lower()) or {}

def async_entries_with_server(self, name: str) -> Dict[DNSRecord, DNSRecord]:
"""Returns a dict of entries whose key matches the server.

This function is not threadsafe and must be called from
the event loop.
"""
return self.service_cache.get(name.lower(), {})
return self.service_cache.get(name.lower()) or {}

# The below functions are threadsafe and do not need to be run in the
# event loop, however they all make copies so they significantly
Expand Down