annotate Lib/test/test_socket.py @ 21283:d4907cdcc299 legacy-trunk

Use an immutable tuple for __slots instead of a mutable list Bump version number
author Andrew M. Kuchling <amk@amk.ca>
date Fri, 07 Dec 2001 14:22:13 +0000
parents 5e735f197ca6
children 9b2d1f8f4be3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
1 # Not tested:
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
2 # socket.fromfd()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
3 # sktobj.getsockopt()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
4 # sktobj.recvfrom()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
5 # sktobj.sendto()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
6 # sktobj.setblocking()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
7 # sktobj.setsockopt()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
8 # sktobj.shutdown()
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
9
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
10
15966
e59b835ad89a a bold attempt to fix things broken by MAL's verify patch: import
Fredrik Lundh <fredrik@pythonware.com>
parents: 15957
diff changeset
11 from test_support import verbose, TestFailed
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
12 import socket
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
13 import os
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
14 import time
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
15
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
16 def missing_ok(str):
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
17 try:
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
18 getattr(socket, str)
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
19 except AttributeError:
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
20 pass
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
21
6368
94e0b31fdf5f Fixed test for socket.error to work when it's a class exception.
Guido van Rossum <guido@python.org>
parents: 5716
diff changeset
22 try: raise socket.error
94e0b31fdf5f Fixed test for socket.error to work when it's a class exception.
Guido van Rossum <guido@python.org>
parents: 5716
diff changeset
23 except socket.error: print "socket.error"
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
24
5457
53440097111f Print less in test_socket.
Guido van Rossum <guido@python.org>
parents: 5060
diff changeset
25 socket.AF_INET
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
26
5457
53440097111f Print less in test_socket.
Guido van Rossum <guido@python.org>
parents: 5060
diff changeset
27 socket.SOCK_STREAM
53440097111f Print less in test_socket.
Guido van Rossum <guido@python.org>
parents: 5060
diff changeset
28 socket.SOCK_DGRAM
53440097111f Print less in test_socket.
Guido van Rossum <guido@python.org>
parents: 5060
diff changeset
29 socket.SOCK_RAW
53440097111f Print less in test_socket.
Guido van Rossum <guido@python.org>
parents: 5060
diff changeset
30 socket.SOCK_RDM
53440097111f Print less in test_socket.
Guido van Rossum <guido@python.org>
parents: 5060
diff changeset
31 socket.SOCK_SEQPACKET
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
32
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
33 for optional in ("AF_UNIX",
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
34
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
35 "SO_DEBUG", "SO_ACCEPTCONN", "SO_REUSEADDR", "SO_KEEPALIVE",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
36 "SO_DONTROUTE", "SO_BROADCAST", "SO_USELOOPBACK", "SO_LINGER",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
37 "SO_OOBINLINE", "SO_REUSEPORT", "SO_SNDBUF", "SO_RCVBUF",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
38 "SO_SNDLOWAT", "SO_RCVLOWAT", "SO_SNDTIMEO", "SO_RCVTIMEO",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
39 "SO_ERROR", "SO_TYPE", "SOMAXCONN",
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
40
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
41 "MSG_OOB", "MSG_PEEK", "MSG_DONTROUTE", "MSG_EOR",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
42 "MSG_TRUNC", "MSG_CTRUNC", "MSG_WAITALL", "MSG_BTAG",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
43 "MSG_ETAG",
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
44
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
45 "SOL_SOCKET",
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
46
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
47 "IPPROTO_IP", "IPPROTO_ICMP", "IPPROTO_IGMP",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
48 "IPPROTO_GGP", "IPPROTO_TCP", "IPPROTO_EGP",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
49 "IPPROTO_PUP", "IPPROTO_UDP", "IPPROTO_IDP",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
50 "IPPROTO_HELLO", "IPPROTO_ND", "IPPROTO_TP",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
51 "IPPROTO_XTP", "IPPROTO_EON", "IPPROTO_BIP",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
52 "IPPROTO_RAW", "IPPROTO_MAX",
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
53
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
54 "IPPORT_RESERVED", "IPPORT_USERRESERVED",
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
55
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
56 "INADDR_ANY", "INADDR_BROADCAST", "INADDR_LOOPBACK",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
57 "INADDR_UNSPEC_GROUP", "INADDR_ALLHOSTS_GROUP",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
58 "INADDR_MAX_LOCAL_GROUP", "INADDR_NONE",
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
59
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
60 "IP_OPTIONS", "IP_HDRINCL", "IP_TOS", "IP_TTL",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
61 "IP_RECVOPTS", "IP_RECVRETOPTS", "IP_RECVDSTADDR",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
62 "IP_RETOPTS", "IP_MULTICAST_IF", "IP_MULTICAST_TTL",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
63 "IP_MULTICAST_LOOP", "IP_ADD_MEMBERSHIP",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
64 "IP_DROP_MEMBERSHIP",
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
65 ):
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
66 missing_ok(optional)
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
67
5716
ce64a8139216 socket_type --> SocketType
Fred Drake <fdrake@acm.org>
parents: 5573
diff changeset
68 socktype = socket.SocketType
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
69 hostname = socket.gethostname()
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
70 ip = socket.gethostbyname(hostname)
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
71 hname, aliases, ipaddrs = socket.gethostbyaddr(ip)
4940
5eed51750284 Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents: 4914
diff changeset
72 all_host_names = [hname] + aliases
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
73
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
74 if verbose:
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
75 print hostname
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
76 print ip
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
77 print hname, aliases, ipaddrs
4940
5eed51750284 Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents: 4914
diff changeset
78 print all_host_names
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
79
4940
5eed51750284 Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents: 4914
diff changeset
80 for name in all_host_names:
16519
631d4c8db784 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 15966
diff changeset
81 if name.find('.'):
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
82 break
4940
5eed51750284 Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents: 4914
diff changeset
83 else:
5eed51750284 Rewrite the `hostname mismatch' test as per GvR suggestion.
Barry Warsaw <barry@python.org>
parents: 4914
diff changeset
84 print 'FQDN not found'
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
85
17208
c8817a9bbbdd Make socket.getservbyname test optional on socket module having that
Barry Warsaw <barry@python.org>
parents: 16519
diff changeset
86 if hasattr(socket, 'getservbyname'):
c8817a9bbbdd Make socket.getservbyname test optional on socket module having that
Barry Warsaw <barry@python.org>
parents: 16519
diff changeset
87 print socket.getservbyname('telnet', 'tcp')
c8817a9bbbdd Make socket.getservbyname test optional on socket module having that
Barry Warsaw <barry@python.org>
parents: 16519
diff changeset
88 try:
c8817a9bbbdd Make socket.getservbyname test optional on socket module having that
Barry Warsaw <barry@python.org>
parents: 16519
diff changeset
89 socket.getservbyname('telnet', 'udp')
c8817a9bbbdd Make socket.getservbyname test optional on socket module having that
Barry Warsaw <barry@python.org>
parents: 16519
diff changeset
90 except socket.error:
c8817a9bbbdd Make socket.getservbyname test optional on socket module having that
Barry Warsaw <barry@python.org>
parents: 16519
diff changeset
91 pass
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
92
20853
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
93 try:
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
94 # On some versions, this loses a reference
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
95 import sys
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
96 orig = sys.getrefcount(__name__)
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
97 socket.getnameinfo(__name__,0)
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
98 except SystemError:
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
99 if sys.getrefcount(__name__) <> orig:
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
100 raise TestFailed,"socket.getnameinfo loses a reference"
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
101
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
102 try:
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
103 # On some versions, this crashes the interpreter.
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
104 socket.getnameinfo(('x', 0, 0, 0), 0)
20941
5e735f197ca6 getnameinfo() appears to raise socket.error instead of
Barry Warsaw <barry@python.org>
parents: 20853
diff changeset
105 except socket.error:
20853
77bb2ae067c2 Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents: 20733
diff changeset
106 pass
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
107
5520
31d66194a77c Suppress fork part of socket test when we can't fork.
Guido van Rossum <guido@python.org>
parents: 5457
diff changeset
108 canfork = hasattr(os, 'fork')
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
109 try:
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
110 PORT = 50007
5520
31d66194a77c Suppress fork part of socket test when we can't fork.
Guido van Rossum <guido@python.org>
parents: 5457
diff changeset
111 if not canfork or os.fork():
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
112 # parent is server
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
113 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
13137
72e3cdb32a6c Skip Montanaro: modify test_socket.py to listen/connect using loopback addr
Guido van Rossum <guido@python.org>
parents: 12049
diff changeset
114 s.bind(("127.0.0.1", PORT))
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
115 s.listen(1)
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
116 if verbose:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
117 print 'parent accepting'
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
118 if canfork:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
119 conn, addr = s.accept()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
120 if verbose:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
121 print 'connected by', addr
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
122 # couple of interesting tests while we've got a live socket
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
123 f = conn.fileno()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
124 if verbose:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
125 print 'fileno:', f
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
126 p = conn.getpeername()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
127 if verbose:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
128 print 'peer:', p
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
129 n = conn.getsockname()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
130 if verbose:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
131 print 'sockname:', n
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
132 f = conn.makefile()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
133 if verbose:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
134 print 'file obj:', f
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
135 while 1:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
136 data = conn.recv(1024)
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
137 if not data:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
138 break
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
139 if verbose:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
140 print 'received:', data
20733
635fa14eda50 Test sendall().
Guido van Rossum <guido@python.org>
parents: 17208
diff changeset
141 conn.sendall(data)
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
142 conn.close()
4880
9a7e9f10aed6 Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff changeset
143 else:
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
144 try:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
145 # child is client
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
146 time.sleep(5)
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
147 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
148 if verbose:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
149 print 'child connecting'
13137
72e3cdb32a6c Skip Montanaro: modify test_socket.py to listen/connect using loopback addr
Guido van Rossum <guido@python.org>
parents: 12049
diff changeset
150 s.connect(("127.0.0.1", PORT))
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
151 msg = 'socket test'
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
152 s.send(msg)
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
153 data = s.recv(1024)
15540
9d43129c8c55 Update the code to better reflect recommended style:
Fred Drake <fdrake@acm.org>
parents: 13137
diff changeset
154 if msg != data:
7747
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
155 print 'parent/client mismatch'
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
156 s.close()
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
157 finally:
aedd2d0dcb31 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6368
diff changeset
158 os._exit(1)
5520
31d66194a77c Suppress fork part of socket test when we can't fork.
Guido van Rossum <guido@python.org>
parents: 5457
diff changeset
159 except socket.error, msg:
31d66194a77c Suppress fork part of socket test when we can't fork.
Guido van Rossum <guido@python.org>
parents: 5457
diff changeset
160 raise TestFailed, msg