def test_good_instance_names(self): assert r.service_type_name('.._x._tcp.local.') == '_x._tcp.local.' assert r.service_type_name( 'x.sub._http._tcp.local.') == '_http._tcp.local.' assert (r.service_type_name( '6d86f882b90facee9170ad3439d72a4d6ee9f511._zget._http._tcp.local.') == '_http._tcp.local.')
def test_good_instance_names(self): good_names_to_try = ( ".._x._tcp.local.", "x.sub._http._tcp.local.", "6d86f882b90facee9170ad3439d72a4d6ee9f511._zget._http._tcp.local.", ) for name in good_names_to_try: r.service_type_name(name)
def test_good_instance_names(self): good_names_to_try = ( '.._x._tcp.local.', 'x.sub._http._tcp.local.', '6d86f882b90facee9170ad3439d72a4d6ee9f511._zget._http._tcp.local.', ) for name in good_names_to_try: r.service_type_name(name)
def test_good_service_names(self): good_names_to_try = ( "_x._tcp.local.", "_x._udp.local.", "_12345-67890-abc._udp.local.", "x._sub._http._tcp.local.", "a" * 63 + "._sub._http._tcp.local.", "a" * 61 + u"â._sub._http._tcp.local.", ) for name in good_names_to_try: r.service_type_name(name)
def test_good_service_names(self): good_names_to_try = ( '_x._tcp.local.', '_x._udp.local.', '_12345-67890-abc._udp.local.', 'x._sub._http._tcp.local.', 'a' * 63 + '._sub._http._tcp.local.', 'a' * 61 + u'â._sub._http._tcp.local.', ) for name in good_names_to_try: r.service_type_name(name)
def test_good_service_names(self): good_names_to_try = ( ('_x._tcp.local.', '_x._tcp.local.'), ('_x._udp.local.', '_x._udp.local.'), ('_12345-67890-abc._udp.local.', '_12345-67890-abc._udp.local.'), ('x._sub._http._tcp.local.', '_http._tcp.local.'), ('a' * 63 + '._sub._http._tcp.local.', '_http._tcp.local.'), ('a' * 61 + u'â._sub._http._tcp.local.', '_http._tcp.local.'), ) for name, result in good_names_to_try: assert r.service_type_name(name) == result assert r.service_type_name('_one_two._tcp.local.', strict=False) == '_one_two._tcp.local.'
def advertise_proxy(self, service_type, ip, port): friendly_name = "proxy-mesh on " + socket.gethostname() name = friendly_name + "._apt_proxy._tcp.local." print "zeroconf service type name " + zeroconf.service_type_name(name) desc = {} self.our_ip = socket.inet_aton(ip) info = zeroconf.ServiceInfo(service_type, name, self.our_ip, port, 0, 0, desc, friendly_name + ".local.") self.zc.register_service(info) self.info_entries.append(info)
def check_service(self, info, allow_name_change): service_name = service_type_name(info.name) if not info.type.endswith(service_name): raise BadTypeInNameException instance_name = info.name[: -len(service_name) - 1] next_instance_number = 2 # check for a name conflict while info.name.lower() in self.services: if not allow_name_change: raise NonUniqueNameException # change the name and look for a conflict info.name = "%s-%s.%s" % (instance_name, next_instance_number, info.type) next_instance_number += 1 service_type_name(info.name)
def add_service(self, zc, type_, name): try: assert zeroconf.service_type_name(name) assert str(name) except (AssertionError, UnicodeError, zeroconf.BadTypeInNameException): return if name not in self._found_types: self._found_types.append(name) zeroconf.ServiceBrowser(self._zc, name, self) if type_ in self._found_types: s = zc.get_service_info(type_, name) if s: self._found_services.append(s)
def test_good_instance_names_without_protocol(self): good_names_to_try = ( "Rachio-C73233.local.", 'YeelightColorBulb-3AFD.local.', 'YeelightTunableBulb-7220.local.', "AlexanderHomeAssistant 74651D.local.", 'iSmartGate-152.local.', 'MyQ-FGA.local.', 'lutron-02c4392a.local.', 'WICED-hap-3E2734.local.', 'MyHost.local.', 'MyHost.sub.local.', ) for name in good_names_to_try: assert r.service_type_name(name, strict=False) == 'local.' for name in good_names_to_try: # Raises without strict=False self.assertRaises(r.BadTypeInNameException, r.service_type_name, name)
def __init__(self, zc, type_, handlers=None, listener=None): assert handlers or listener, "You need to specify at least one handler" if not type_.endswith(service_type_name(type_)): raise BadTypeInNameException self.zc = zc self.type = type_