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: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author='Paul Scott-Murphy, William McBrine, Jakub Stasiak',
url='https://github.com/jstasiak/python-zeroconf',
package_data={"zeroconf": ["py.typed"]},
packages=["zeroconf", "zeroconf.services", "zeroconf._utils"],
packages=["zeroconf", "zeroconf._services", "zeroconf._utils"],
platforms=['unix', 'linux', 'osx'],
license='LGPL',
zip_safe=False,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from zeroconf import Zeroconf
from zeroconf.const import _LISTENER_TIME
from zeroconf._exceptions import BadTypeInNameException, NonUniqueNameException, ServiceNameAlreadyRegistered
from zeroconf.services import ServiceInfo, ServiceListener
from zeroconf._services import ServiceInfo, ServiceListener
from zeroconf._utils.time import current_time_millis


Expand Down
6 changes: 3 additions & 3 deletions tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-


""" Unit tests for zeroconf.services. """
""" Unit tests for zeroconf._services. """

import logging
import socket
Expand All @@ -16,9 +16,9 @@

import zeroconf as r
from zeroconf import const
import zeroconf.services as s
import zeroconf._services as s
from zeroconf import Zeroconf
from zeroconf.services import (
from zeroconf._services import (
ServiceBrowser,
ServiceInfo,
ServiceStateChange,
Expand Down
6 changes: 3 additions & 3 deletions zeroconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
NonUniqueNameException,
ServiceNameAlreadyRegistered,
)
from .services import ( # noqa # import needed for backwards compat
from ._services import ( # noqa # import needed for backwards compat
instance_name_from_service_info,
Signal,
SignalRegistrationInterface,
Expand All @@ -56,8 +56,8 @@
ServiceListener,
ServiceStateChange,
)
from .services.registry import ServiceRegistry # noqa # import needed for backwards compat
from .services.types import ZeroconfServiceTypes # noqa # import needed for backwards compat
from ._services.registry import ServiceRegistry # noqa # import needed for backwards compat
from ._services.types import ZeroconfServiceTypes # noqa # import needed for backwards compat
from ._utils.name import service_type_name # noqa # import needed for backwards compat
from ._utils.net import ( # noqa # import needed for backwards compat
add_multicast_member,
Expand Down
16 changes: 8 additions & 8 deletions zeroconf/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
from ._exceptions import NonUniqueNameException
from ._handlers import QueryHandler, RecordManager
from ._logger import QuietLogger, log
from ._services import (
RecordUpdateListener,
ServiceBrowser,
ServiceInfo,
ServiceListener,
instance_name_from_service_info,
)
from ._services.registry import ServiceRegistry
from ._utils.name import service_type_name
from ._utils.net import (
IPVersion,
Expand All @@ -59,14 +67,6 @@
_TYPE_PTR,
_UNREGISTER_TIME,
)
from .services import (
RecordUpdateListener,
ServiceBrowser,
ServiceInfo,
ServiceListener,
instance_name_from_service_info,
)
from .services.registry import ServiceRegistry


class NotifyListener:
Expand Down
6 changes: 2 additions & 4 deletions zeroconf/_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

from ._dns import DNSAddress, DNSIncoming, DNSOutgoing, DNSPointer, DNSQuestion, DNSRecord
from ._logger import log
from ._services import RecordUpdateListener
from ._services.registry import ServiceRegistry
from ._utils.time import current_time_millis
from .const import (
_CLASS_IN,
Expand All @@ -38,10 +40,6 @@
_TYPE_SRV,
_TYPE_TXT,
)
from .services import (
RecordUpdateListener,
)
from .services.registry import ServiceRegistry


if TYPE_CHECKING:
Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions zeroconf/services/registry.py → zeroconf/_services/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


from .._exceptions import ServiceNameAlreadyRegistered
from ..services import ServiceInfo
from .._services import ServiceInfo


class ServiceRegistry:
Expand All @@ -40,7 +40,7 @@ def __init__(
self,
) -> None:
"""Create the ServiceRegistry class."""
self.services = {} # type: Dict[str, ServiceInfo]
self._services = {} # type: Dict[str, ServiceInfo]
self.types = {} # type: Dict[str, List]
self.servers = {} # type: Dict[str, List]
self._lock = threading.Lock() # add and remove services thread safe
Expand All @@ -66,11 +66,11 @@ def update(self, info: ServiceInfo) -> None:

def get_service_infos(self) -> List[ServiceInfo]:
"""Return all ServiceInfo."""
return list(self.services.values())
return list(self._services.values())

def get_info_name(self, name: str) -> Optional[ServiceInfo]:
"""Return all ServiceInfo for the name."""
return self.services.get(name)
return self._services.get(name)

def get_types(self) -> List[str]:
"""Return all types."""
Expand All @@ -89,7 +89,7 @@ def _get_by_index(self, attr: str, key: str) -> List[ServiceInfo]:
service_infos = []

for name in getattr(self, attr).get(key, [])[:]:
info = self.services.get(name)
info = self._services.get(name)
# Since we do not get under a lock since it would be
# a performance issue, its possible
# the service can be unregistered during the get
Expand All @@ -102,17 +102,17 @@ def _get_by_index(self, attr: str, key: str) -> List[ServiceInfo]:
def _add(self, info: ServiceInfo) -> None:
"""Add a new service under the lock."""
lower_name = info.name.lower()
if lower_name in self.services:
if lower_name in self._services:
raise ServiceNameAlreadyRegistered

self.services[lower_name] = info
self._services[lower_name] = info
self.types.setdefault(info.type, []).append(lower_name)
self.servers.setdefault(info.server, []).append(lower_name)

def _remove(self, info: ServiceInfo) -> None:
"""Remove a service under the lock."""
lower_name = info.name.lower()
old_service_info = self.services[lower_name]
old_service_info = self._services[lower_name]
self.types[old_service_info.type].remove(lower_name)
self.servers[old_service_info.server].remove(lower_name)
del self.services[lower_name]
del self._services[lower_name]
2 changes: 1 addition & 1 deletion zeroconf/services/types.py → zeroconf/_services/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
from typing import Optional, Set, Tuple, Union

from .._core import Zeroconf
from .._services import ServiceBrowser, ServiceListener
from .._utils.net import IPVersion, InterfaceChoice, InterfacesType
from ..const import _SERVICE_TYPE_ENUMERATION_NAME
from ..services import ServiceBrowser, ServiceListener


class ZeroconfServiceTypes(ServiceListener):
Expand Down
2 changes: 1 addition & 1 deletion zeroconf/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
from ._core import NotifyListener, Zeroconf
from ._dns import DNSOutgoing
from ._exceptions import NonUniqueNameException
from ._services import ServiceInfo, _ServiceBrowserBase, instance_name_from_service_info
from ._utils.aio import wait_condition_or_timeout
from ._utils.net import IPVersion, InterfaceChoice, InterfacesType
from ._utils.time import current_time_millis, millis_to_seconds
from .const import _BROWSER_TIME, _CHECK_TIME, _LISTENER_TIME, _MDNS_PORT, _REGISTER_TIME, _UNREGISTER_TIME
from .services import ServiceInfo, _ServiceBrowserBase, instance_name_from_service_info


def _get_best_available_queue() -> queue.Queue:
Expand Down