Back to index

python3.2  3.2.2
Public Member Functions
test.test_socket.GeneralModuleTests Class Reference

Begin Tests. More...

List of all members.

Public Member Functions

def test_repr
def test_weakref
def testSocketError
def testSendtoErrors
def testCrucialConstants
def testHostnameRes
def testRefCountGetNameInfo
def testInterpreterCrash
def testNtoH
def testNtoHErrors
def testGetServBy
def testDefaultTimeout
def testIPv4_inet_aton_fourbytes
def testIPv4toString
def testIPv6toString
def testStringToIPv4
def testStringToIPv6
def testSockName
def testGetSockOpt
def testSetSockOpt
def testSendAfterClose
def testNewAttributes
def test_getsockaddrarg
def test_sock_ioctl
def testGetaddrinfo
def test_getnameinfo
def test_idna
def check_sendall_interrupted
def test_sendall_interrupted
def test_sendall_interrupted_with_timeout
def test_dealloc_warn
def test_name_closed_socketio
def testListenBacklog0

Detailed Description

Begin Tests.

Definition at line 263 of file test_socket.py.


Member Function Documentation

Definition at line 719 of file test_socket.py.

00719 
00720     def check_sendall_interrupted(self, with_timeout):
00721         # socketpair() is not stricly required, but it makes things easier.
00722         if not hasattr(signal, 'alarm') or not hasattr(socket, 'socketpair'):
00723             self.skipTest("signal.alarm and socket.socketpair required for this test")
00724         # Our signal handlers clobber the C errno by calling a math function
00725         # with an invalid domain value.
00726         def ok_handler(*args):
00727             self.assertRaises(ValueError, math.acosh, 0)
00728         def raising_handler(*args):
00729             self.assertRaises(ValueError, math.acosh, 0)
00730             1 // 0
00731         c, s = socket.socketpair()
00732         old_alarm = signal.signal(signal.SIGALRM, raising_handler)
00733         try:
00734             if with_timeout:
00735                 # Just above the one second minimum for signal.alarm
00736                 c.settimeout(1.5)
00737             with self.assertRaises(ZeroDivisionError):
00738                 signal.alarm(1)
00739                 c.sendall(b"x" * (1024**2))
00740             if with_timeout:
00741                 signal.signal(signal.SIGALRM, ok_handler)
00742                 signal.alarm(1)
00743                 self.assertRaises(socket.timeout, c.sendall, b"x" * (1024**2))
00744         finally:
00745             signal.signal(signal.SIGALRM, old_alarm)
00746             c.close()
00747             s.close()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 754 of file test_socket.py.

00754 
00755     def test_dealloc_warn(self):
00756         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00757         r = repr(sock)
00758         with self.assertWarns(ResourceWarning) as cm:
00759             sock = None
00760             support.gc_collect()
00761         self.assertIn(r, str(cm.warning.args[0]))
00762         # An open socket file object gets dereferenced after the socket
00763         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00764         f = sock.makefile('rb')
00765         r = repr(sock)
00766         sock = None
00767         support.gc_collect()
00768         with self.assertWarns(ResourceWarning):
00769             f = None
00770             support.gc_collect()

Here is the call graph for this function:

Definition at line 703 of file test_socket.py.

00703 
00704     def test_getnameinfo(self):
00705         # only IP addresses are allowed
00706         self.assertRaises(socket.error, socket.getnameinfo, ('mail.python.org',0), 0)

Here is the call graph for this function:

Definition at line 616 of file test_socket.py.

00616 
00617     def test_getsockaddrarg(self):
00618         host = '0.0.0.0'
00619         port = support.find_unused_port()
00620         big_port = port + 65536
00621         neg_port = port - 65536
00622         sock = socket.socket()
00623         try:
00624             self.assertRaises(OverflowError, sock.bind, (host, big_port))
00625             self.assertRaises(OverflowError, sock.bind, (host, neg_port))
00626             sock.bind((host, port))
00627         finally:
00628             sock.close()

Here is the call graph for this function:

Definition at line 709 of file test_socket.py.

00709 
00710     def test_idna(self):
00711         support.requires('network')
00712         # these should all be successful
00713         socket.gethostbyname('испытание.python.org')
00714         socket.gethostbyname_ex('испытание.python.org')
00715         socket.getaddrinfo('испытание.python.org',0,socket.AF_UNSPEC,socket.SOCK_STREAM)
00716         # this may not work if the forward lookup choses the IPv6 address, as that doesn't
00717         # have a reverse entry yet
00718         # socket.gethostbyaddr('испытание.python.org')

Definition at line 771 of file test_socket.py.

00771 
00772     def test_name_closed_socketio(self):
00773         with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
00774             fp = sock.makefile("rb")
00775             fp.close()
00776             self.assertEqual(repr(fp), "<_io.BufferedReader name=-1>")

Here is the call graph for this function:

Definition at line 265 of file test_socket.py.

00265 
00266     def test_repr(self):
00267         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00268         self.addCleanup(s.close)
00269         self.assertTrue(repr(s).startswith("<socket.socket object"))

Here is the call graph for this function:

Definition at line 748 of file test_socket.py.

00748 
00749     def test_sendall_interrupted(self):
00750         self.check_sendall_interrupted(False)

Here is the call graph for this function:

Definition at line 751 of file test_socket.py.

Here is the call graph for this function:

Definition at line 630 of file test_socket.py.

00630 
00631     def test_sock_ioctl(self):
00632         self.assertTrue(hasattr(socket.socket, 'ioctl'))
00633         self.assertTrue(hasattr(socket, 'SIO_RCVALL'))
00634         self.assertTrue(hasattr(socket, 'RCVALL_ON'))
00635         self.assertTrue(hasattr(socket, 'RCVALL_OFF'))
00636         self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS'))
00637         s = socket.socket()
00638         self.addCleanup(s.close)
00639         self.assertRaises(ValueError, s.ioctl, -1, None)
00640         s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100))

Here is the call graph for this function:

Definition at line 270 of file test_socket.py.

00270 
00271     def test_weakref(self):
00272         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00273         p = proxy(s)
00274         self.assertEqual(p.fileno(), s.fileno())
00275         s.close()
00276         s = None
00277         try:
00278             p.fileno()
00279         except ReferenceError:
00280             pass
00281         else:
00282             self.fail('Socket proxy still exists')

Here is the call graph for this function:

Definition at line 342 of file test_socket.py.

00342 
00343     def testCrucialConstants(self):
00344         # Testing for mission critical constants
00345         socket.AF_INET
00346         socket.SOCK_STREAM
00347         socket.SOCK_DGRAM
00348         socket.SOCK_RAW
00349         socket.SOCK_RDM
00350         socket.SOCK_SEQPACKET
00351         socket.SOL_SOCKET
00352         socket.SO_REUSEADDR

Definition at line 460 of file test_socket.py.

00460 
00461     def testDefaultTimeout(self):
00462         # Testing default timeout
00463         # The default timeout should initially be None
00464         self.assertEqual(socket.getdefaulttimeout(), None)
00465         s = socket.socket()
00466         self.assertEqual(s.gettimeout(), None)
00467         s.close()
00468 
00469         # Set the default timeout to 10, and see if it propagates
00470         socket.setdefaulttimeout(10)
00471         self.assertEqual(socket.getdefaulttimeout(), 10)
00472         s = socket.socket()
00473         self.assertEqual(s.gettimeout(), 10)
00474         s.close()
00475 
00476         # Reset the default timeout to None, and see if it propagates
00477         socket.setdefaulttimeout(None)
00478         self.assertEqual(socket.getdefaulttimeout(), None)
00479         s = socket.socket()
00480         self.assertEqual(s.gettimeout(), None)
00481         s.close()
00482 
00483         # Check that setting it to an invalid value raises ValueError
00484         self.assertRaises(ValueError, socket.setdefaulttimeout, -1)
00485 
00486         # Check that setting it to an invalid type raises TypeError
00487         self.assertRaises(TypeError, socket.setdefaulttimeout, "spam")

Here is the call graph for this function:

Definition at line 641 of file test_socket.py.

00641 
00642     def testGetaddrinfo(self):
00643         try:
00644             socket.getaddrinfo('localhost', 80)
00645         except socket.gaierror as err:
00646             if err.errno == socket.EAI_SERVICE:
00647                 # see http://bugs.python.org/issue1282647
00648                 self.skipTest("buggy libc version")
00649             raise
00650         # len of every sequence is supposed to be == 5
00651         for info in socket.getaddrinfo(HOST, None):
00652             self.assertEqual(len(info), 5)
00653         # host can be a domain name, a string representation of an
00654         # IPv4/v6 address or None
00655         socket.getaddrinfo('localhost', 80)
00656         socket.getaddrinfo('127.0.0.1', 80)
00657         socket.getaddrinfo(None, 80)
00658         if SUPPORTS_IPV6:
00659             socket.getaddrinfo('::1', 80)
00660         # port can be a string service name such as "http", a numeric
00661         # port number or None
00662         socket.getaddrinfo(HOST, "http")
00663         socket.getaddrinfo(HOST, 80)
00664         socket.getaddrinfo(HOST, None)
00665         # test family and socktype filters
00666         infos = socket.getaddrinfo(HOST, None, socket.AF_INET)
00667         for family, _, _, _, _ in infos:
00668             self.assertEqual(family, socket.AF_INET)
00669         infos = socket.getaddrinfo(HOST, None, 0, socket.SOCK_STREAM)
00670         for _, socktype, _, _, _ in infos:
00671             self.assertEqual(socktype, socket.SOCK_STREAM)
00672         # test proto and flags arguments
00673         socket.getaddrinfo(HOST, None, 0, 0, socket.SOL_TCP)
00674         socket.getaddrinfo(HOST, None, 0, 0, 0, socket.AI_PASSIVE)
00675         # a server willing to support both IPv4 and IPv6 will
00676         # usually do this
00677         socket.getaddrinfo(None, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0,
00678                            socket.AI_PASSIVE)
00679         # test keyword arguments
00680         a = socket.getaddrinfo(HOST, None)
00681         b = socket.getaddrinfo(host=HOST, port=None)
00682         self.assertEqual(a, b)
00683         a = socket.getaddrinfo(HOST, None, socket.AF_INET)
00684         b = socket.getaddrinfo(HOST, None, family=socket.AF_INET)
00685         self.assertEqual(a, b)
00686         a = socket.getaddrinfo(HOST, None, 0, socket.SOCK_STREAM)
00687         b = socket.getaddrinfo(HOST, None, type=socket.SOCK_STREAM)
00688         self.assertEqual(a, b)
00689         a = socket.getaddrinfo(HOST, None, 0, 0, socket.SOL_TCP)
00690         b = socket.getaddrinfo(HOST, None, proto=socket.SOL_TCP)
00691         self.assertEqual(a, b)
00692         a = socket.getaddrinfo(HOST, None, 0, 0, 0, socket.AI_PASSIVE)
00693         b = socket.getaddrinfo(HOST, None, flags=socket.AI_PASSIVE)
00694         self.assertEqual(a, b)
00695         a = socket.getaddrinfo(None, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0,
00696                                socket.AI_PASSIVE)
00697         b = socket.getaddrinfo(host=None, port=0, family=socket.AF_UNSPEC,
00698                                type=socket.SOCK_STREAM, proto=0,
00699                                flags=socket.AI_PASSIVE)
00700         self.assertEqual(a, b)
00701         # Issue #6697.
00702         self.assertRaises(UnicodeEncodeError, socket.getaddrinfo, 'localhost', '\uD800')

Here is the call graph for this function:

Definition at line 419 of file test_socket.py.

00419 
00420     def testGetServBy(self):
00421         eq = self.assertEqual
00422         # Find one service that exists, then check all the related interfaces.
00423         # I've ordered this by protocols that have both a tcp and udp
00424         # protocol, at least for modern Linuxes.
00425         if (sys.platform.startswith('linux') or
00426             sys.platform.startswith('freebsd') or
00427             sys.platform.startswith('netbsd') or
00428             sys.platform == 'darwin'):
00429             # avoid the 'echo' service on this platform, as there is an
00430             # assumption breaking non-standard port/protocol entry
00431             services = ('daytime', 'qotd', 'domain')
00432         else:
00433             services = ('echo', 'daytime', 'domain')
00434         for service in services:
00435             try:
00436                 port = socket.getservbyname(service, 'tcp')
00437                 break
00438             except socket.error:
00439                 pass
00440         else:
00441             raise socket.error
00442         # Try same call with optional protocol omitted
00443         port2 = socket.getservbyname(service)
00444         eq(port, port2)
00445         # Try udp, but don't barf it it doesn't exist
00446         try:
00447             udpport = socket.getservbyname(service, 'udp')
00448         except socket.error:
00449             udpport = None
00450         else:
00451             eq(udpport, port)
00452         # Now make sure the lookup by port returns the same service name
00453         eq(socket.getservbyport(port2), service)
00454         eq(socket.getservbyport(port, 'tcp'), service)
00455         if udpport is not None:
00456             eq(socket.getservbyport(udpport, 'udp'), service)
00457         # Make sure getservbyport does not accept out of range ports.
00458         self.assertRaises(OverflowError, socket.getservbyport, -1)
00459         self.assertRaises(OverflowError, socket.getservbyport, 65536)

Here is the call graph for this function:

Definition at line 585 of file test_socket.py.

00585 
00586     def testGetSockOpt(self):
00587         # Testing getsockopt()
00588         # We know a socket should start without reuse==0
00589         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00590         self.addCleanup(sock.close)
00591         reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
00592         self.assertFalse(reuse != 0, "initial mode is reuse")

Here is the call graph for this function:

Definition at line 353 of file test_socket.py.

00353 
00354     def testHostnameRes(self):
00355         # Testing hostname resolution mechanisms
00356         hostname = socket.gethostname()
00357         try:
00358             ip = socket.gethostbyname(hostname)
00359         except socket.error:
00360             # Probably name lookup wasn't set up right; skip this test
00361             return
00362         self.assertTrue(ip.find('.') >= 0, "Error resolving host to ip.")
00363         try:
00364             hname, aliases, ipaddrs = socket.gethostbyaddr(ip)
00365         except socket.error:
00366             # Probably a similar problem as above; skip this test
00367             return
00368         all_host_names = [hostname, hname] + aliases
00369         fqhn = socket.getfqdn(ip)
00370         if not fqhn in all_host_names:
00371             self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names)))

Here is the call graph for this function:

Definition at line 383 of file test_socket.py.

00383 
00384     def testInterpreterCrash(self):
00385         # Making sure getnameinfo doesn't crash the interpreter
00386         try:
00387             # On some versions, this crashes the interpreter.
00388             socket.getnameinfo(('x', 0, 0, 0), 0)
00389         except socket.error:
00390             pass

Definition at line 488 of file test_socket.py.

00488 
00489     def testIPv4_inet_aton_fourbytes(self):
00490         if not hasattr(socket, 'inet_aton'):
00491             return  # No inet_aton, nothing to check
00492         # Test that issue1008086 and issue767150 are fixed.
00493         # It must return 4 bytes.
00494         self.assertEqual(b'\x00'*4, socket.inet_aton('0.0.0.0'))
00495         self.assertEqual(b'\xff'*4, socket.inet_aton('255.255.255.255'))

Here is the call graph for this function:

Definition at line 496 of file test_socket.py.

00496 
00497     def testIPv4toString(self):
00498         if not hasattr(socket, 'inet_pton'):
00499             return # No inet_pton() on this platform
00500         from socket import inet_aton as f, inet_pton, AF_INET
00501         g = lambda a: inet_pton(AF_INET, a)
00502 
00503         self.assertEqual(b'\x00\x00\x00\x00', f('0.0.0.0'))
00504         self.assertEqual(b'\xff\x00\xff\x00', f('255.0.255.0'))
00505         self.assertEqual(b'\xaa\xaa\xaa\xaa', f('170.170.170.170'))
00506         self.assertEqual(b'\x01\x02\x03\x04', f('1.2.3.4'))
00507         self.assertEqual(b'\xff\xff\xff\xff', f('255.255.255.255'))
00508 
00509         self.assertEqual(b'\x00\x00\x00\x00', g('0.0.0.0'))
00510         self.assertEqual(b'\xff\x00\xff\x00', g('255.0.255.0'))
00511         self.assertEqual(b'\xaa\xaa\xaa\xaa', g('170.170.170.170'))
00512         self.assertEqual(b'\xff\xff\xff\xff', g('255.255.255.255'))

Here is the call graph for this function:

Definition at line 513 of file test_socket.py.

00513 
00514     def testIPv6toString(self):
00515         if not hasattr(socket, 'inet_pton'):
00516             return # No inet_pton() on this platform
00517         try:
00518             from socket import inet_pton, AF_INET6, has_ipv6
00519             if not has_ipv6:
00520                 return
00521         except ImportError:
00522             return
00523         f = lambda a: inet_pton(AF_INET6, a)
00524 
00525         self.assertEqual(b'\x00' * 16, f('::'))
00526         self.assertEqual(b'\x00' * 16, f('0::0'))
00527         self.assertEqual(b'\x00\x01' + b'\x00' * 14, f('1::'))
00528         self.assertEqual(
00529             b'\x45\xef\x76\xcb\x00\x1a\x56\xef\xaf\xeb\x0b\xac\x19\x24\xae\xae',
00530             f('45ef:76cb:1a:56ef:afeb:bac:1924:aeae')
00531         )

Here is the call graph for this function:

Definition at line 777 of file test_socket.py.

00777 
00778     def testListenBacklog0(self):
00779         srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00780         srv.bind((HOST, 0))
00781         # backlog = 0
00782         srv.listen(0)
00783         srv.close()
00784 
00785 
@unittest.skipUnless(thread, 'Threading required for this test.')

Definition at line 608 of file test_socket.py.

00608 
00609     def testNewAttributes(self):
00610         # testing .family, .type and .protocol
00611         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00612         self.assertEqual(sock.family, socket.AF_INET)
00613         self.assertEqual(sock.type, socket.SOCK_STREAM)
00614         self.assertEqual(sock.proto, 0)
00615         sock.close()

Here is the call graph for this function:

Definition at line 391 of file test_socket.py.

00391 
00392     def testNtoH(self):
00393         # This just checks that htons etc. are their own inverse,
00394         # when looking at the lower 16 or 32 bits.
00395         sizes = {socket.htonl: 32, socket.ntohl: 32,
00396                  socket.htons: 16, socket.ntohs: 16}
00397         for func, size in sizes.items():
00398             mask = (1<<size) - 1
00399             for i in (0, 1, 0xffff, ~0xffff, 2, 0x01234567, 0x76543210):
00400                 self.assertEqual(i & mask, func(func(i&mask)) & mask)
00401 
00402             swapped = func(mask)
00403             self.assertEqual(swapped & mask, mask)
00404             self.assertRaises(OverflowError, func, 1<<34)

Here is the call graph for this function:

Definition at line 405 of file test_socket.py.

00405 
00406     def testNtoHErrors(self):
00407         good_values = [ 1, 2, 3, 1, 2, 3 ]
00408         bad_values = [ -1, -2, -3, -1, -2, -3 ]
00409         for k in good_values:
00410             socket.ntohl(k)
00411             socket.ntohs(k)
00412             socket.htonl(k)
00413             socket.htons(k)
00414         for k in bad_values:
00415             self.assertRaises(OverflowError, socket.ntohl, k)
00416             self.assertRaises(OverflowError, socket.ntohs, k)
00417             self.assertRaises(OverflowError, socket.htonl, k)
00418             self.assertRaises(OverflowError, socket.htons, k)

Here is the call graph for this function:

Definition at line 372 of file test_socket.py.

00372 
00373     def testRefCountGetNameInfo(self):
00374         # Testing reference count for getnameinfo
00375         if hasattr(sys, "getrefcount"):
00376             try:
00377                 # On some versions, this loses a reference
00378                 orig = sys.getrefcount(__name__)
00379                 socket.getnameinfo(__name__,0)
00380             except TypeError:
00381                 if sys.getrefcount(__name__) != orig:
00382                     self.fail("socket.getnameinfo loses a reference")

Here is the call graph for this function:

Definition at line 601 of file test_socket.py.

00601 
00602     def testSendAfterClose(self):
00603         # testing send() after close() with timeout
00604         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00605         sock.settimeout(1)
00606         sock.close()
00607         self.assertRaises(socket.error, sock.send, b"spam")

Here is the call graph for this function:

Definition at line 298 of file test_socket.py.

00298 
00299     def testSendtoErrors(self):
00300         # Testing that sendto doens't masks failures. See #10169.
00301         s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
00302         self.addCleanup(s.close)
00303         s.bind(('', 0))
00304         sockname = s.getsockname()
00305         # 2 args
00306         with self.assertRaises(TypeError) as cm:
00307             s.sendto('\u2620', sockname)
00308         self.assertEqual(str(cm.exception),
00309                          "'str' does not support the buffer interface")
00310         with self.assertRaises(TypeError) as cm:
00311             s.sendto(5j, sockname)
00312         self.assertEqual(str(cm.exception),
00313                          "'complex' does not support the buffer interface")
00314         with self.assertRaises(TypeError) as cm:
00315             s.sendto(b'foo', None)
00316         self.assertIn('not NoneType',str(cm.exception))
00317         # 3 args
00318         with self.assertRaises(TypeError) as cm:
00319             s.sendto('\u2620', 0, sockname)
00320         self.assertEqual(str(cm.exception),
00321                          "'str' does not support the buffer interface")
00322         with self.assertRaises(TypeError) as cm:
00323             s.sendto(5j, 0, sockname)
00324         self.assertEqual(str(cm.exception),
00325                          "'complex' does not support the buffer interface")
00326         with self.assertRaises(TypeError) as cm:
00327             s.sendto(b'foo', 0, None)
00328         self.assertIn('not NoneType', str(cm.exception))
00329         with self.assertRaises(TypeError) as cm:
00330             s.sendto(b'foo', 'bar', sockname)
00331         self.assertIn('an integer is required', str(cm.exception))
00332         with self.assertRaises(TypeError) as cm:
00333             s.sendto(b'foo', None, None)
00334         self.assertIn('an integer is required', str(cm.exception))
00335         # wrong number of args
00336         with self.assertRaises(TypeError) as cm:
00337             s.sendto(b'foo')
00338         self.assertIn('(1 given)', str(cm.exception))
00339         with self.assertRaises(TypeError) as cm:
00340             s.sendto(b'foo', 0, sockname, 4)
00341         self.assertIn('(4 given)', str(cm.exception))

Here is the call graph for this function:

Definition at line 593 of file test_socket.py.

00593 
00594     def testSetSockOpt(self):
00595         # Testing setsockopt()
00596         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00597         self.addCleanup(sock.close)
00598         sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
00599         reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR)
00600         self.assertFalse(reuse == 0, "failed to set reuse mode")

Here is the call graph for this function:

Definition at line 283 of file test_socket.py.

00283 
00284     def testSocketError(self):
00285         # Testing socket module exceptions
00286         def raise_error(*args, **kwargs):
00287             raise socket.error
00288         def raise_herror(*args, **kwargs):
00289             raise socket.herror
00290         def raise_gaierror(*args, **kwargs):
00291             raise socket.gaierror
00292         self.assertRaises(socket.error, raise_error,
00293                               "Error raising socket exception.")
00294         self.assertRaises(socket.error, raise_herror,
00295                               "Error raising socket exception.")
00296         self.assertRaises(socket.error, raise_gaierror,
00297                               "Error raising socket exception.")

Here is the call graph for this function:

Definition at line 567 of file test_socket.py.

00567 
00568     def testSockName(self):
00569         # Testing getsockname()
00570         port = support.find_unused_port()
00571         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00572         self.addCleanup(sock.close)
00573         sock.bind(("0.0.0.0", port))
00574         name = sock.getsockname()
00575         # XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate
00576         # it reasonable to get the host's addr in addition to 0.0.0.0.
00577         # At least for eCos.  This is required for the S/390 to pass.
00578         try:
00579             my_ip_addr = socket.gethostbyname(socket.gethostname())
00580         except socket.error:
00581             # Probably name lookup wasn't set up right; skip this test
00582             return
00583         self.assertIn(name[0], ("0.0.0.0", my_ip_addr), '%s invalid' % name[0])
00584         self.assertEqual(name[1], port)

Here is the call graph for this function:

Definition at line 532 of file test_socket.py.

00532 
00533     def testStringToIPv4(self):
00534         if not hasattr(socket, 'inet_ntop'):
00535             return # No inet_ntop() on this platform
00536         from socket import inet_ntoa as f, inet_ntop, AF_INET
00537         g = lambda a: inet_ntop(AF_INET, a)
00538 
00539         self.assertEqual('1.0.1.0', f(b'\x01\x00\x01\x00'))
00540         self.assertEqual('170.85.170.85', f(b'\xaa\x55\xaa\x55'))
00541         self.assertEqual('255.255.255.255', f(b'\xff\xff\xff\xff'))
00542         self.assertEqual('1.2.3.4', f(b'\x01\x02\x03\x04'))
00543 
00544         self.assertEqual('1.0.1.0', g(b'\x01\x00\x01\x00'))
00545         self.assertEqual('170.85.170.85', g(b'\xaa\x55\xaa\x55'))
00546         self.assertEqual('255.255.255.255', g(b'\xff\xff\xff\xff'))

Here is the call graph for this function:

Definition at line 547 of file test_socket.py.

00547 
00548     def testStringToIPv6(self):
00549         if not hasattr(socket, 'inet_ntop'):
00550             return # No inet_ntop() on this platform
00551         try:
00552             from socket import inet_ntop, AF_INET6, has_ipv6
00553             if not has_ipv6:
00554                 return
00555         except ImportError:
00556             return
00557         f = lambda a: inet_ntop(AF_INET6, a)
00558 
00559         self.assertEqual('::', f(b'\x00' * 16))
00560         self.assertEqual('::1', f(b'\x00' * 15 + b'\x01'))
00561         self.assertEqual(
00562             'aef:b01:506:1001:ffff:9997:55:170',
00563             f(b'\x0a\xef\x0b\x01\x05\x06\x10\x01\xff\xff\x99\x97\x00\x55\x01\x70')
00564         )

Here is the call graph for this function:


The documentation for this class was generated from the following file: