當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。