当前位置: 首页>>代码示例>>Python>>正文


Python Zeroconf.get_service_info方法代码示例

本文整理汇总了Python中zeroconf.Zeroconf.get_service_info方法的典型用法代码示例。如果您正苦于以下问题:Python Zeroconf.get_service_info方法的具体用法?Python Zeroconf.get_service_info怎么用?Python Zeroconf.get_service_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zeroconf.Zeroconf的用法示例。


在下文中一共展示了Zeroconf.get_service_info方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
class ServiceDiscoveryClient:

    def __init__(self, service_timeout=None):
        self.zeroconf = Zeroconf()
        self.service_args = [SRV_TYPE, srv_fqname()]
        if service_timeout:
            self.service_args.append(service_timeout)

    @cached_property_with_ttl(ttl=1.0)
    def info(self):
        service_info = self.zeroconf.get_service_info(*self.service_args)
        if not service_info:
            raise ZeroconfServiceNotFound(
                "Pilotwire Controller Zeroconf service not found"
            )
        return service_info

    @property
    def address(self):
        # pylint: disable=no-member
        return socket.inet_ntoa(self.info.address)

    @property
    def port(self):
        # pylint: disable=no-member
        return str(self.info.port)
开发者ID:cailloumajor,项目名称:pilotwire-controller,代码行数:28,代码来源:zeroconf.py

示例2: ServiceListener

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
class ServiceListener(object):
    def __init__(self):
        # Is this necessary, when zeroconf is being passed into add_service?
        self.zconf = Zeroconf()
        self.services = []

    def remove_service(self, zeroconf, service_type, name):
        print "Not implemented."
        return True

    def add_service(self, zeroconf, service_type, name):
        this_service = {}
        this_service['name'] = name
        this_service['service_type'] = service_type
        this_service['address'] = ''
        this_service['server'] = ''
        info = self.zconf.get_service_info(service_type, name)
        if info:
            this_service['address'] = "%s:%d" % (socket.inet_ntoa(info.address), info.port)
            # Construct the link by finding service type in service_types object; or use http if not found in list.
            this_service['link'] = "%s%s" % (proto_dict.get(service_type, proto_dict['_http._tcp.local.']), this_service['address'])
            this_service['server'] = info.server
            # prop = info.getProperties()
            # if prop:
            #     print "  Properties are"
            #     for key, value in prop.items():
            #         print "    %s: %s" % (key, value)
        self.services.append(this_service)
开发者ID:ksdtech,项目名称:KSDNetworkLookup,代码行数:30,代码来源:ksdNetworkLookup.py

示例3: zeroconf_without_service_info

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
def zeroconf_without_service_info(mocker):
    from zeroconf import Zeroconf

    zeroconf_stub = mocker.stub(name='get_service_info')
    zeroconf_stub.return_value = None
    stub_object = Zeroconf()
    stub_object.get_service_info = zeroconf_stub
    return stub_object
开发者ID:strahlex,项目名称:pymachinetalk,代码行数:10,代码来源:test_dns_sd.py

示例4: zeroconf

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
def zeroconf(mocker):
    from zeroconf import Zeroconf

    service_info = ServiceInfoFactory().create()
    zeroconf_stub = mocker.stub(name='get_service_info')
    zeroconf_stub.return_value = service_info
    stub_object = Zeroconf()
    stub_object.get_service_info = zeroconf_stub
    return stub_object
开发者ID:strahlex,项目名称:pymachinetalk,代码行数:11,代码来源:test_dns_sd.py

示例5: serviceStatus

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
def serviceStatus():

    zeroconf = Zeroconf()

    info = zeroconf.get_service_info("_http._tcp.local.", "Takiyaki._http._tcp.local.")

    # If service registered #
    if info:
        return (socket.inet_ntoa(info.address), info.port)
    # No named service registered #
    else:
        print("Service doesn't exist")
    zeroconf.close()
开发者ID:merchat7,项目名称:LAN-Single-File-Distributor,代码行数:15,代码来源:trackerReg.py

示例6: test_bonjour

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
    def test_bonjour(self):
        'Test advertising via BonJour'
        from calibre.srv.bonjour import BonJour
        if ispy3:
            from zeroconf import Zeroconf
        else:
            from calibre.utils.Zeroconf import Zeroconf
        b = BonJour(wait_for_stop=False)
        with TestServer(lambda data:(data.path[0] + data.read()), plugins=(b,), shutdown_timeout=5) as server:
            self.assertTrue(b.started.wait(5), 'BonJour not started')
            self.ae(b.advertised_port, server.address[1])
            service = b.services[0]
            self.ae(service.type, '_calibre._tcp.local.')
            r = Zeroconf()
            info = r.get_service_info(service.type, service.name)
            self.assertIsNotNone(info)
            self.ae(info.text, b'\npath=/opds')

        self.assertTrue(b.stopped.wait(5), 'BonJour not stopped')
开发者ID:j-howell,项目名称:calibre,代码行数:21,代码来源:loop.py

示例7: on_service_state_change

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
def on_service_state_change(
    zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange,
) -> None:
    print("Service %s of type %s state changed: %s" % (name, service_type, state_change))

    if state_change is ServiceStateChange.Added:
        info = zeroconf.get_service_info(service_type, name)
        if info:
            print("  Address: %s:%d" % (socket.inet_ntoa(cast(bytes, info.address)), cast(int, info.port)))
            print("  Weight: %d, priority: %d" % (info.weight, info.priority))
            print("  Server: %s" % (info.server,))
            if info.properties:
                print("  Properties are:")
                for key, value in info.properties.items():
                    print("    %s: %s" % (key, value))
            else:
                print("  No properties")
        else:
            print("  No info")
        print('\n')
开发者ID:LRSEngineering,项目名称:python-zeroconf,代码行数:22,代码来源:browser.py

示例8: _fetch_fbx_mdns_info_via_mdns

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
 def _fetch_fbx_mdns_info_via_mdns(self):
     print('Querying mDNS about Freebox Server information...')
     info = {}
     try:
         r = Zeroconf()
         serv_info = r.get_service_info('_fbx-api._tcp.local.', 'Freebox Server._fbx-api._tcp.local.')
         info['api_domain'] = serv_info.properties[b'api_domain'].decode()
         info['https_available'] = True if serv_info.properties[b'https_available'] == b'1' else False
         info['https_port'] = int(serv_info.properties[b'https_port'])
         info['api_base_url'] = serv_info.properties[b'api_base_url'].decode()
         info['api_version'] = serv_info.properties[b'api_version'].decode()
         r.close()
     except Exception:
         print('Unable to retrieve configuration, assuming bridged mode')
         d = requests.get("http://mafreebox.freebox.fr/api_version")
         data = d.json()
         info['api_domain'] = data['api_domain']
         info['https_available'] = data['https_available']
         info['https_port'] = data['https_port']
         info['api_base_url'] = data['api_base_url']
         info['api_version'] = data['api_version']
     return info
开发者ID:skimpax,项目名称:fbxosctrl,代码行数:24,代码来源:fbxosctrl.py

示例9: len

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
#!/usr/bin/env python3

""" Example of resolving a service with a known name """

import logging
import sys

from zeroconf import Zeroconf

TYPE = '_test._tcp.local.'
NAME = 'My Service Name'

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    if len(sys.argv) > 1:
        assert sys.argv[1:] == ['--debug']
        logging.getLogger('zeroconf').setLevel(logging.DEBUG)

    zeroconf = Zeroconf()

    try:
        print(zeroconf.get_service_info(TYPE, NAME + '.' + TYPE))
    finally:
        zeroconf.close()
开发者ID:LRSEngineering,项目名称:python-zeroconf,代码行数:26,代码来源:resolver.py

示例10: test_integration_with_listener_class

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
    def test_integration_with_listener_class(self):

        service_added = Event()
        service_removed = Event()

        type_ = "_http._tcp.local."
        name = "xxxyyy"
        registration_name = "%s.%s" % (name, type_)

        class MyListener(object):
            def add_service(self, zeroconf, type, name):
                zeroconf.get_service_info(type, name)
                service_added.set()

            def remove_service(self, zeroconf, type, name):
                service_removed.set()

        zeroconf_browser = Zeroconf()
        zeroconf_browser.add_service_listener(type_, MyListener())

        properties = dict(
            prop_none=None,
            prop_string=b'a_prop',
            prop_float=1.0,
            prop_blank=b'a blanked string',
            prop_true=1,
            prop_false=0,
        )

        zeroconf_registrar = Zeroconf()
        desc = {'path': '/~paulsm/'}
        desc.update(properties)
        info = ServiceInfo(
            type_, registration_name,
            socket.inet_aton("10.0.1.2"), 80, 0, 0,
            desc, "ash-2.local.")
        zeroconf_registrar.register_service(info)

        try:
            service_added.wait(1)
            assert service_added.is_set()

            # short pause to allow multicast timers to expire
            time.sleep(2)

            # clear the answer cache to force query
            for record in zeroconf_browser.cache.entries():
                zeroconf_browser.cache.remove(record)

            # get service info without answer cache
            info = zeroconf_browser.get_service_info(type_, registration_name)

            assert info.properties[b'prop_none'] is False
            assert info.properties[b'prop_string'] == properties['prop_string']
            assert info.properties[b'prop_float'] is False
            assert info.properties[b'prop_blank'] == properties['prop_blank']
            assert info.properties[b'prop_true'] is True
            assert info.properties[b'prop_false'] is False

            zeroconf_registrar.unregister_service(info)
            service_removed.wait(1)
            assert service_removed.is_set()
        finally:
            zeroconf_registrar.close()
            zeroconf_browser.close()
开发者ID:dmrub,项目名称:python-zeroconf,代码行数:67,代码来源:test_zeroconf.py

示例11: test_integration_with_listener_class

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
    def test_integration_with_listener_class(self):

        service_added = Event()
        service_removed = Event()
        service_updated = Event()

        subtype_name = "My special Subtype"
        type_ = "_http._tcp.local."
        subtype = subtype_name + "._sub." + type_
        name = "xxxyyyæøå"
        registration_name = "%s.%s" % (name, subtype)

        class MyListener(r.ServiceListener):
            def add_service(self, zeroconf, type, name):
                zeroconf.get_service_info(type, name)
                service_added.set()

            def remove_service(self, zeroconf, type, name):
                service_removed.set()

        class MySubListener(r.ServiceListener):
            def add_service(self, zeroconf, type, name):
                pass

            def remove_service(self, zeroconf, type, name):
                pass

            def update_service(self, zeroconf, type, name):
                service_updated.set()

        listener = MyListener()
        zeroconf_browser = Zeroconf(interfaces=['127.0.0.1'])
        zeroconf_browser.add_service_listener(subtype, listener)

        properties = dict(
            prop_none=None,
            prop_string=b'a_prop',
            prop_float=1.0,
            prop_blank=b'a blanked string',
            prop_true=1,
            prop_false=0,
        )

        zeroconf_registrar = Zeroconf(interfaces=['127.0.0.1'])
        desc = {'path': '/~paulsm/'}  # type: r.ServicePropertiesType
        desc.update(properties)
        info_service = ServiceInfo(
            subtype, registration_name, socket.inet_aton("10.0.1.2"), 80, 0, 0, desc, "ash-2.local."
        )
        zeroconf_registrar.register_service(info_service)

        try:
            service_added.wait(1)
            assert service_added.is_set()

            # short pause to allow multicast timers to expire
            time.sleep(3)

            # clear the answer cache to force query
            for record in zeroconf_browser.cache.entries():
                zeroconf_browser.cache.remove(record)

            # get service info without answer cache
            info = zeroconf_browser.get_service_info(type_, registration_name)
            assert info is not None
            assert info.properties[b'prop_none'] is False
            assert info.properties[b'prop_string'] == properties['prop_string']
            assert info.properties[b'prop_float'] is False
            assert info.properties[b'prop_blank'] == properties['prop_blank']
            assert info.properties[b'prop_true'] is True
            assert info.properties[b'prop_false'] is False

            info = zeroconf_browser.get_service_info(subtype, registration_name)
            assert info is not None
            assert info.properties[b'prop_none'] is False

            # Begin material test addition
            sublistener = MySubListener()
            zeroconf_browser.add_service_listener(registration_name, sublistener)
            properties['prop_blank'] = b'an updated string'
            desc.update(properties)
            info_service = ServiceInfo(
                subtype, registration_name, socket.inet_aton("10.0.1.2"), 80, 0, 0, desc, "ash-2.local."
            )
            zeroconf_registrar.update_service(info_service)
            service_updated.wait(1)
            assert service_updated.is_set()

            info = zeroconf_browser.get_service_info(type_, registration_name)
            assert info is not None
            assert info.properties[b'prop_blank'] == properties['prop_blank']
            # End material test addition

            zeroconf_registrar.unregister_service(info_service)
            service_removed.wait(1)
            assert service_removed.is_set()

        finally:
            zeroconf_registrar.close()
            zeroconf_browser.remove_service_listener(listener)
#.........这里部分代码省略.........
开发者ID:jstasiak,项目名称:python-zeroconf,代码行数:103,代码来源:test_zeroconf.py

示例12: _fetch_fbx_mdns_info_via_mdns

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
 def _fetch_fbx_mdns_info_via_mdns(self):
     print('Querying mDNS about Freebox Server information...')
     r = Zeroconf()
     info = r.get_service_info('_fbx-api._tcp.local.', 'Freebox Server._fbx-api._tcp.local.')
     r.close()
     return info
开发者ID:bousqi,项目名称:fbxosctrl,代码行数:8,代码来源:fbxosctrl.py

示例13: len

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
    logging.basicConfig(level=logging.DEBUG)
    if len(sys.argv) > 1:
        assert sys.argv[1:] == ['--debug']
        logging.getLogger('zeroconf').setLevel(logging.DEBUG)

    # Test a few module features, including service registration, service
    # query (for Zoe), and service unregistration.
    print("Multicast DNS Service Discovery for Python, version %s" % (__version__,))
    r = Zeroconf()
    print("1. Testing registration of a service...")
    desc = {'version': '0.10', 'a': 'test value', 'b': 'another value'}
    info = ServiceInfo("_http._tcp.local.",
                       "My Service Name._http._tcp.local.",
                       socket.inet_aton("127.0.0.1"), 1234, 0, 0, desc)
    print("   Registering service...")
    r.register_service(info)
    print("   Registration done.")
    print("2. Testing query of service information...")
    print("   Getting ZOE service: %s" % (
        r.get_service_info("_http._tcp.local.", "ZOE._http._tcp.local.")))
    print("   Query done.")
    print("3. Testing query of own service...")
    queried_info = r.get_service_info("_http._tcp.local.", "My Service Name._http._tcp.local.")
    assert queried_info
    print("   Getting self: %s" % (queried_info,))
    print("   Query done.")
    print("4. Testing unregister of service information...")
    r.unregister_service(info)
    print("   Unregister done.")
    r.close()
开发者ID:LRSEngineering,项目名称:python-zeroconf,代码行数:32,代码来源:self_test.py

示例14: len

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
    if len(sys.argv) > 1:
        assert sys.argv[1:] == [u'--debug']
        logging.getLogger(u'zeroconf').setLevel(logging.DEBUG)

    # Test a few module features, including service registration, service
    # query (for Zoe), and service unregistration.
    print(u"Multicast DNS Service Discovery for Python, version %s" % (__version__,))


    r = Zeroconf()
    print(u"1. Testing registration of a service...")
    desc = {u'version': u'0.10', u'a': u'test value', u'b': u'another value'}
    info = ServiceInfo(u"_http._tcp.local.",
                       u"My Service Name._http._tcp.local.",
                       socket.inet_aton(u"127.0.0.1"), 1234, 0, 0, desc)
    print(u"   Registering service...")
    r.register_service(info)
    print(u"   Registration done.")
    print(u"2. Testing query of service information...")
    print(u"   Getting ZOE service: %s" % (
        r.get_service_info(u"_http._tcp.local.", u"ZOE._http._tcp.local.")))
    print(u"   Query done.")
    print(u"3. Testing query of own service...")
    info = r.get_service_info(u"_http._tcp.local.", u"My Service Name._http._tcp.local.")
    assert info
    print(u"   Getting self: %s" % (info,))
    print(u"   Query done.")
    print(u"4. Testing unregister of service information...")
    r.unregister_service(info)
    print(u"   Unregister done.")
    r.close()
开发者ID:Darth-Neo,项目名称:pyrpi,代码行数:33,代码来源:self_test.py

示例15: add_service

# 需要导入模块: from zeroconf import Zeroconf [as 别名]
# 或者: from zeroconf.Zeroconf import get_service_info [as 别名]
 def add_service(
     self, _zeroconf: zeroconf.Zeroconf, _type: str, name: str
 ) -> None:
     """Add service."""
     self.services[name] = _zeroconf.get_service_info(_type, name)
开发者ID:home-assistant,项目名称:home-assistant-cli,代码行数:7,代码来源:config.py


注:本文中的zeroconf.Zeroconf.get_service_info方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。