Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_socket.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 9b2d1f8f4be3 |
| children | 169e01ec3596 c2733e8f6612 |
| 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 | 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 |
|
21315
9b2d1f8f4be3
Refcounting isn't available in Jython. Putting the jython test around it.
Finn Bock <bckfnn@worldonline.dk>
parents:
20941
diff
changeset
|
93 import sys |
|
9b2d1f8f4be3
Refcounting isn't available in Jython. Putting the jython test around it.
Finn Bock <bckfnn@worldonline.dk>
parents:
20941
diff
changeset
|
94 if not sys.platform.startswith('java'): |
|
9b2d1f8f4be3
Refcounting isn't available in Jython. Putting the jython test around it.
Finn Bock <bckfnn@worldonline.dk>
parents:
20941
diff
changeset
|
95 try: |
|
9b2d1f8f4be3
Refcounting isn't available in Jython. Putting the jython test around it.
Finn Bock <bckfnn@worldonline.dk>
parents:
20941
diff
changeset
|
96 # On some versions, this loses a reference |
|
9b2d1f8f4be3
Refcounting isn't available in Jython. Putting the jython test around it.
Finn Bock <bckfnn@worldonline.dk>
parents:
20941
diff
changeset
|
97 orig = sys.getrefcount(__name__) |
|
9b2d1f8f4be3
Refcounting isn't available in Jython. Putting the jython test around it.
Finn Bock <bckfnn@worldonline.dk>
parents:
20941
diff
changeset
|
98 socket.getnameinfo(__name__,0) |
|
9b2d1f8f4be3
Refcounting isn't available in Jython. Putting the jython test around it.
Finn Bock <bckfnn@worldonline.dk>
parents:
20941
diff
changeset
|
99 except SystemError: |
|
9b2d1f8f4be3
Refcounting isn't available in Jython. Putting the jython test around it.
Finn Bock <bckfnn@worldonline.dk>
parents:
20941
diff
changeset
|
100 if sys.getrefcount(__name__) <> orig: |
|
9b2d1f8f4be3
Refcounting isn't available in Jython. Putting the jython test around it.
Finn Bock <bckfnn@worldonline.dk>
parents:
20941
diff
changeset
|
101 raise TestFailed,"socket.getnameinfo loses a reference" |
|
20853
77bb2ae067c2
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents:
20733
diff
changeset
|
102 |
|
77bb2ae067c2
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents:
20733
diff
changeset
|
103 try: |
|
77bb2ae067c2
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents:
20733
diff
changeset
|
104 # 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
|
105 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
|
106 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
|
107 pass |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
108 |
|
5520
31d66194a77c
Suppress fork part of socket test when we can't fork.
Guido van Rossum <guido@python.org>
parents:
5457
diff
changeset
|
109 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
|
110 try: |
|
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
111 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
|
112 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
|
113 # parent is server |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
114 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
|
115 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
|
116 s.listen(1) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
117 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
118 print 'parent accepting' |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
119 if canfork: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
120 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
|
121 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
122 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
|
123 # 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
|
124 f = conn.fileno() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
125 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
126 print 'fileno:', f |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
127 p = conn.getpeername() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
128 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
129 print 'peer:', p |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
130 n = conn.getsockname() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
131 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
132 print 'sockname:', n |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
133 f = conn.makefile() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
134 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
135 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
|
136 while 1: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
137 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
|
138 if not data: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
139 break |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
140 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
141 print 'received:', data |
| 20733 | 142 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
|
143 conn.close() |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
144 else: |
|
7747
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
145 try: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
146 # child is client |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
147 time.sleep(5) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
148 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
|
149 if verbose: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
150 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
|
151 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
|
152 msg = 'socket test' |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
153 s.send(msg) |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
154 data = s.recv(1024) |
|
15540
9d43129c8c55
Update the code to better reflect recommended style:
Fred Drake <fdrake@acm.org>
parents:
13137
diff
changeset
|
155 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
|
156 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
|
157 s.close() |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
158 finally: |
|
aedd2d0dcb31
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6368
diff
changeset
|
159 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
|
160 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
|
161 raise TestFailed, msg |
