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


Python socket.getnameinfo方法代码示例

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


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

示例1: _getrealname

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def _getrealname(addr):
    """
    Return a 2-tuple of socket IP and port for IPv4 and a 4-tuple of
    socket IP, port, flowInfo, and scopeID for IPv6.  For IPv6, it
    returns the interface portion (the part after the %) as a part of
    the IPv6 address, which Python 3.7+ does not include.

    @param addr: A 2-tuple for IPv4 information or a 4-tuple for IPv6
        information.
    """
    if len(addr) == 4:
        # IPv6
        host = socket.getnameinfo(
            addr, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV)[0]
        return tuple([host] + list(addr[1:]))
    else:
        return addr[:2] 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:19,代码来源:tcp.py

示例2: _setRealAddress

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def _setRealAddress(self, address):
        """
        Set the resolved address of this L{_BaseBaseClient} and initiate the
        connection attempt.

        @param address: Depending on whether this is an IPv4 or IPv6 connection
            attempt, a 2-tuple of C{(host, port)} or a 4-tuple of C{(host,
            port, flow, scope)}.  At this point it is a fully resolved address,
            and the 'host' portion will always be an IP address, not a DNS
            name.
        """
        if len(address) == 4:
            # IPv6, make sure we have the scopeID associated
            hostname = socket.getnameinfo(
                address, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV)[0]
            self.realAddress = tuple([hostname] + list(address[1:]))
        else:
            self.realAddress = address
        self.doConnect() 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:21,代码来源:tcp.py

示例3: test_serverGetHostOnIPv6ScopeID

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def test_serverGetHostOnIPv6ScopeID(self):
        """
        When a connection is accepted over IPv6, the server
        L{ITransport.getHost} method returns an L{IPv6Address} giving the
        address on which the server accepted the connection, including the scope
        identifier.
        """
        interface = getLinkLocalIPv6Address()
        client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM)
        hostAddress = self._serverGetConnectionAddressTest(
            client, interface, 'getHost')

        peer = client.getpeername()
        hostname = socket.getnameinfo(peer, socket.NI_NUMERICHOST)[0]

        self.assertEqual(
            IPv6Address('TCP', hostname, *peer[1:]), hostAddress) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:19,代码来源:test_tcp.py

示例4: test_serverGetPeerOnIPv6

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def test_serverGetPeerOnIPv6(self):
        """
        When a connection is accepted over IPv6, the server
        L{ITransport.getPeer} method returns an L{IPv6Address} giving the
        address on the remote end of the connection.
        """
        interface = '::1'
        client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM)
        peerAddress = self._serverGetConnectionAddressTest(
            client, interface, 'getPeer')

        peer = client.getsockname()
        hostname = socket.getnameinfo(peer, socket.NI_NUMERICHOST)[0]

        self.assertEqual(
            IPv6Address('TCP', hostname, *peer[1:]), peerAddress) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:18,代码来源:test_tcp.py

示例5: test_serverGetPeerOnIPv6ScopeID

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def test_serverGetPeerOnIPv6ScopeID(self):
        """
        When a connection is accepted over IPv6, the server
        L{ITransport.getPeer} method returns an L{IPv6Address} giving the
        address on the remote end of the connection, including the scope
        identifier.
        """
        interface = getLinkLocalIPv6Address()
        client = createTestSocket(self, socket.AF_INET6, socket.SOCK_STREAM)
        peerAddress = self._serverGetConnectionAddressTest(
            client, interface, 'getPeer')

        peer = client.getsockname()
        hostname = socket.getnameinfo(peer, socket.NI_NUMERICHOST)[0]

        self.assertEqual(
            IPv6Address('TCP', hostname, *peer[1:]), peerAddress) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:19,代码来源:test_tcp.py

示例6: override_system_resolver

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def override_system_resolver(resolver=None):
    """Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    @param resolver: the resolver to use
    @type resolver: dns.resolver.Resolver object or None
    """
    if resolver is None:
        resolver = get_default_resolver()
    global _resolver
    _resolver = resolver
    socket.getaddrinfo = _getaddrinfo
    socket.getnameinfo = _getnameinfo
    socket.getfqdn = _getfqdn
    socket.gethostbyname = _gethostbyname
    socket.gethostbyname_ex = _gethostbyname_ex
    socket.gethostbyaddr = _gethostbyaddr 
开发者ID:elgatito,项目名称:script.elementum.burst,代码行数:26,代码来源:resolver.py

示例7: test_getnameinfo

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def test_getnameinfo(self):
        '''Tests _socket.getnameinfo()'''
        #sanity
        _socket.getnameinfo(("127.0.0.1", 80), 8)
        _socket.getnameinfo(("127.0.0.1", 80), 9)

        host, service = _socket.getnameinfo( ("127.0.0.1", 80), 8)
        self.assertEqual(service, '80')

        host, service = _socket.getnameinfo( ("127.0.0.1", 80), 0)
        self.assertEqual(service, "http")
        #IP gives a TypeError
        #self.assertRaises(SystemError, _socket.getnameinfo, ("127.0.0.1"), 8)
        #self.assertRaises(SystemError, _socket.getnameinfo, (321), 8)
        self.assertRaises(TypeError, _socket.getnameinfo, ("127.0.0.1"), '0')
        self.assertRaises(TypeError, _socket.getnameinfo, ("127.0.0.1", 80, 0, 0, 0), 8)
        self.assertRaises(_socket.gaierror, _socket.getnameinfo, ('no such host will ever exist', 80), 8) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:19,代码来源:test__socket.py

示例8: testBadParameters

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def testBadParameters(self):
        for address, flags in [
            ( (0,0),       0),
            ( (0,"http"),  0),
            ( "localhost", 0),
            ( 0,           0),
            ( ("",),       0),
        ]:
            try:
                socket.getnameinfo(address, flags)
            except TypeError:
                pass
            except Exception, x:
                self.fail("Bad getnameinfo parameters (%s, %s) raised wrong exception: %s" % (str(address), flags, str(x)))
            else:
                self.fail("Bad getnameinfo parameters (%s, %s) failed to raise exception" % (str(address), flags)) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:18,代码来源:test_socket.py

示例9: override_system_resolver

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def override_system_resolver(resolver=None):
    """Override the system resolver routines in the socket module with
    versions which use dnspython's resolver.

    This can be useful in testing situations where you want to control
    the resolution behavior of python code without having to change
    the system's resolver settings (e.g. /etc/resolv.conf).

    The resolver to use may be specified; if it's not, the default
    resolver will be used.

    @param resolver: the resolver to use
    @type resolver: thirdparty.dns.resolver.Resolver object or None
    """
    if resolver is None:
        resolver = get_default_resolver()
    global _resolver
    _resolver = resolver
    socket.getaddrinfo = _getaddrinfo
    socket.getnameinfo = _getnameinfo
    socket.getfqdn = _getfqdn
    socket.gethostbyname = _gethostbyname
    socket.gethostbyname_ex = _gethostbyname_ex
    socket.gethostbyaddr = _gethostbyaddr 
开发者ID:MrH0wl,项目名称:Cloudmare,代码行数:26,代码来源:resolver.py

示例10: testRefCountGetNameInfo

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def testRefCountGetNameInfo(self):
        # Testing reference count for getnameinfo
        try:
            # On some versions, this loses a reference
            orig = sys.getrefcount(__name__)
            socket.getnameinfo(__name__,0)
        except TypeError:
            self.assertEqual(sys.getrefcount(__name__), orig,
                             "socket.getnameinfo loses a reference") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_socket.py

示例11: testInterpreterCrash

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def testInterpreterCrash(self):
        # Making sure getnameinfo doesn't crash the interpreter
        try:
            # On some versions, this crashes the interpreter.
            socket.getnameinfo(('x', 0, 0, 0), 0)
        except socket.error:
            pass 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_socket.py

示例12: test_flowinfo

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def test_flowinfo(self):
        self.assertRaises(OverflowError, socket.getnameinfo,
                          ('::1',0, 0xffffffff), 0)
        s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
        try:
            self.assertRaises(OverflowError, s.bind, ('::1', 0, -10))
        finally:
            s.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_socket.py

示例13: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def __init__(self, host, port):
        host = socket.gethostbyname(host)
        host, port = socket.getnameinfo((host, port), socket.NI_NUMERICHOST)
        self.addr = (host, int(port))
        self._path = "%s:%s" % (host, port)
        self.socket = None
        self._create_socket() 
开发者ID:nfcpy,项目名称:nfcpy,代码行数:9,代码来源:udp.py

示例14: testRefCountGetNameInfo

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def testRefCountGetNameInfo(self):
        # Testing reference count for getnameinfo
        if hasattr(sys, "getrefcount"):
            try:
                # On some versions, this loses a reference
                orig = sys.getrefcount(__name__)
                socket.getnameinfo(__name__,0)
            except TypeError:
                self.assertEqual(sys.getrefcount(__name__), orig,
                                 "socket.getnameinfo loses a reference") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:12,代码来源:test_socket.py

示例15: getnameinfo

# 需要导入模块: import socket [as 别名]
# 或者: from socket import getnameinfo [as 别名]
def getnameinfo(self, sockaddr, flags=0):
        return self.run_in_executor(None, socket.getnameinfo, sockaddr, flags) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:base_events.py


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