Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_socket.py @ 86127:a3d09c19bb93
merge with 3.3
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sun, 06 Oct 2013 19:24:00 +0200 |
| parents | 540a9c69c2ea |
| children | 09105051b9f4 |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
58415
diff
changeset
|
1 #!/usr/bin/env python3 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
2 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3 import unittest |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46899
diff
changeset
|
4 from test import support |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
5 |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
6 import errno |
|
58146
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
7 import io |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
8 import socket |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
9 import select |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
10 import tempfile |
|
81587
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
11 import _testcapi |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
12 import time |
|
46161
848160d10780
Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44782
diff
changeset
|
13 import traceback |
|
46899
bd2c95c165ea
Rename Queue module to queue.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46370
diff
changeset
|
14 import queue |
|
25152
0c9dfd5a06d4
Skip UDP testing for MacPython (for now), it hangs. This may be due to
Jack Jansen <jack.jansen@cwi.nl>
parents:
24772
diff
changeset
|
15 import sys |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
16 import os |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
17 import array |
|
65604
8d7f18332db7
Fix SOCK_CLOEXEC and SOCK_NONBLOCK tests on recent glibcs with old Linux kernels.
Antoine Pitrou <solipsis@pitrou.net>
parents:
65416
diff
changeset
|
18 import platform |
|
64536
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
19 import contextlib |
|
32160
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
20 from weakref import proxy |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
21 import signal |
|
64961
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
22 import math |
|
68774
5e13e5e6df30
Issue #11127: Raise a TypeError when trying to pickle a socket object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68258
diff
changeset
|
23 import pickle |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
24 import struct |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
25 try: |
|
76150
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
26 import multiprocessing |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
27 except ImportError: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
28 multiprocessing = False |
|
85619
b7f6f6f59e91
Issue #18904: test_socket: add inheritance tests using fcntl and FD_CLOEXEC
Victor Stinner <victor.stinner@gmail.com>
parents:
85481
diff
changeset
|
29 try: |
|
b7f6f6f59e91
Issue #18904: test_socket: add inheritance tests using fcntl and FD_CLOEXEC
Victor Stinner <victor.stinner@gmail.com>
parents:
85481
diff
changeset
|
30 import fcntl |
|
b7f6f6f59e91
Issue #18904: test_socket: add inheritance tests using fcntl and FD_CLOEXEC
Victor Stinner <victor.stinner@gmail.com>
parents:
85481
diff
changeset
|
31 except ImportError: |
|
b7f6f6f59e91
Issue #18904: test_socket: add inheritance tests using fcntl and FD_CLOEXEC
Victor Stinner <victor.stinner@gmail.com>
parents:
85481
diff
changeset
|
32 fcntl = None |
|
65606
a30e75820b8d
Also guard other SOCK_NONBLOCK test
Antoine Pitrou <solipsis@pitrou.net>
parents:
65604
diff
changeset
|
33 |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46899
diff
changeset
|
34 HOST = support.HOST |
|
68142
be6c38d1817b
Normalize the encoding names for Latin-1 and UTF-8 to
Marc-André Lemburg <mal@egenix.com>
parents:
67382
diff
changeset
|
35 MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8') ## test unicode string and carriage return |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
36 |
|
61073
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
37 try: |
|
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
38 import _thread as thread |
|
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
39 import threading |
|
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
40 except ImportError: |
|
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
41 thread = None |
|
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
42 threading = None |
|
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
43 |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
44 def _have_socket_can(): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
45 """Check whether CAN sockets are supported on this host.""" |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
46 try: |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
47 s = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
48 except (AttributeError, OSError): |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
49 return False |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
50 else: |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
51 s.close() |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
52 return True |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
53 |
|
73478
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
54 def _have_socket_rds(): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
55 """Check whether RDS sockets are supported on this host.""" |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
56 try: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
57 s = socket.socket(socket.PF_RDS, socket.SOCK_SEQPACKET, 0) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
58 except (AttributeError, OSError): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
59 return False |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
60 else: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
61 s.close() |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
62 return True |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
63 |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
64 HAVE_SOCKET_CAN = _have_socket_can() |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
65 |
|
73478
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
66 HAVE_SOCKET_RDS = _have_socket_rds() |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
67 |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
68 # Size in bytes of the int type |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
69 SIZEOF_INT = array.array("i").itemsize |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
70 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
71 class SocketTCPTest(unittest.TestCase): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
72 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
73 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
74 self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46899
diff
changeset
|
75 self.port = support.bind_port(self.serv) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
76 self.serv.listen(1) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
77 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
78 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
79 self.serv.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
80 self.serv = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
81 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
82 class SocketUDPTest(unittest.TestCase): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
83 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
84 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
85 self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46899
diff
changeset
|
86 self.port = support.bind_port(self.serv) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
87 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
88 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
89 self.serv.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
90 self.serv = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
91 |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
92 class ThreadSafeCleanupTestCase(unittest.TestCase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
93 """Subclass of unittest.TestCase with thread-safe cleanup methods. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
94 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
95 This subclass protects the addCleanup() and doCleanups() methods |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
96 with a recursive lock. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
97 """ |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
98 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
99 if threading: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
100 def __init__(self, *args, **kwargs): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
101 super().__init__(*args, **kwargs) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
102 self._cleanup_lock = threading.RLock() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
103 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
104 def addCleanup(self, *args, **kwargs): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
105 with self._cleanup_lock: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
106 return super().addCleanup(*args, **kwargs) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
107 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
108 def doCleanups(self, *args, **kwargs): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
109 with self._cleanup_lock: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
110 return super().doCleanups(*args, **kwargs) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
111 |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
112 class SocketCANTest(unittest.TestCase): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
113 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
114 """To be able to run this test, a `vcan0` CAN interface can be created with |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
115 the following commands: |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
116 # modprobe vcan |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
117 # ip link add dev vcan0 type vcan |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
118 # ifconfig vcan0 up |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
119 """ |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
120 interface = 'vcan0' |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
121 bufsize = 128 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
122 |
|
82024
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
123 """The CAN frame structure is defined in <linux/can.h>: |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
124 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
125 struct can_frame { |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
126 canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
127 __u8 can_dlc; /* data length code: 0 .. 8 */ |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
128 __u8 data[8] __attribute__((aligned(8))); |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
129 }; |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
130 """ |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
131 can_frame_fmt = "=IB3x8s" |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
132 can_frame_size = struct.calcsize(can_frame_fmt) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
133 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
134 """The Broadcast Management Command frame structure is defined |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
135 in <linux/can/bcm.h>: |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
136 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
137 struct bcm_msg_head { |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
138 __u32 opcode; |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
139 __u32 flags; |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
140 __u32 count; |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
141 struct timeval ival1, ival2; |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
142 canid_t can_id; |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
143 __u32 nframes; |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
144 struct can_frame frames[0]; |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
145 } |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
146 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
147 `bcm_msg_head` must be 8 bytes aligned because of the `frames` member (see |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
148 `struct can_frame` definition). Must use native not standard types for packing. |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
149 """ |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
150 bcm_cmd_msg_fmt = "@3I4l2I" |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
151 bcm_cmd_msg_fmt += "x" * (struct.calcsize(bcm_cmd_msg_fmt) % 8) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
152 |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
153 def setUp(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
154 self.s = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) |
|
72849
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
155 self.addCleanup(self.s.close) |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
156 try: |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
157 self.s.bind((self.interface,)) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
158 except OSError: |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
159 self.skipTest('network interface `%s` does not exist' % |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
160 self.interface) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
161 |
|
73478
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
162 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
163 class SocketRDSTest(unittest.TestCase): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
164 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
165 """To be able to run this test, the `rds` kernel module must be loaded: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
166 # modprobe rds |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
167 """ |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
168 bufsize = 8192 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
169 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
170 def setUp(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
171 self.serv = socket.socket(socket.PF_RDS, socket.SOCK_SEQPACKET, 0) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
172 self.addCleanup(self.serv.close) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
173 try: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
174 self.port = support.bind_port(self.serv) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
175 except OSError: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
176 self.skipTest('unable to bind RDS socket') |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
177 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
178 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
179 class ThreadableTest: |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
180 """Threadable Test class |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
181 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
182 The ThreadableTest class makes it easy to create a threaded |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
183 client/server pair from an existing unit test. To create a |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
184 new threaded class from an existing unit test, use multiple |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
185 inheritance: |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
186 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
187 class NewClass (OldClass, ThreadableTest): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
188 pass |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
189 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
190 This class defines two new fixture functions with obvious |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
191 purposes for overriding: |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
192 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
193 clientSetUp () |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
194 clientTearDown () |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
195 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
196 Any new test functions within the class must then define |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
197 tests in pairs, where the test name is preceeded with a |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
198 '_' to indicate the client portion of the test. Ex: |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
199 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
200 def testFoo(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
201 # Server portion |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
202 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
203 def _testFoo(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
204 # Client portion |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
205 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
206 Any exceptions raised by the clients during their tests |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
207 are caught and transferred to the main thread to alert |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
208 the testing framework. |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
209 |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
210 Note, the server setup function cannot call any blocking |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
211 functions that rely on the client thread during setup, |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
212 unless serverExplicitReady() is called just before |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
213 the blocking call (such as in setting up a client/server |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
214 connection and performing the accept() in setUp(). |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
215 """ |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
216 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
217 def __init__(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
218 # Swap the true setup function |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
219 self.__setUp = self.setUp |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
220 self.__tearDown = self.tearDown |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
221 self.setUp = self._setUp |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
222 self.tearDown = self._tearDown |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
223 |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
224 def serverExplicitReady(self): |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
225 """This method allows the server to explicitly indicate that |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
226 it wants the client thread to proceed. This is useful if the |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
227 server is about to execute a blocking routine that is |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
228 dependent upon the client thread during its setup routine.""" |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
229 self.server_ready.set() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
230 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
231 def _setUp(self): |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
232 self.server_ready = threading.Event() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
233 self.client_ready = threading.Event() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
234 self.done = threading.Event() |
|
46899
bd2c95c165ea
Rename Queue module to queue.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46370
diff
changeset
|
235 self.queue = queue.Queue(1) |
|
72849
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
236 self.server_crashed = False |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
237 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
238 # Do some munging to start the client test. |
|
23815
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
239 methodname = self.id() |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
240 i = methodname.rfind('.') |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
241 methodname = methodname[i+1:] |
|
203d1412a7e8
Major overhaul of timeout sockets:
Guido van Rossum <guido@python.org>
parents:
23814
diff
changeset
|
242 test_method = getattr(self, '_' + methodname) |
|
23800
bf1555a92711
Remove some overly complicated ways to concatenate and repeat strings
Guido van Rossum <guido@python.org>
parents:
23799
diff
changeset
|
243 self.client_thread = thread.start_new_thread( |
|
bf1555a92711
Remove some overly complicated ways to concatenate and repeat strings
Guido van Rossum <guido@python.org>
parents:
23799
diff
changeset
|
244 self.clientRun, (test_method,)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
245 |
|
72849
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
246 try: |
|
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
247 self.__setUp() |
|
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
248 except: |
|
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
249 self.server_crashed = True |
|
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
250 raise |
|
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
251 finally: |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
252 self.server_ready.set() |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
253 self.client_ready.wait() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
254 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
255 def _tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
256 self.__tearDown() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
257 self.done.wait() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
258 |
|
44675
627f2e2273b9
Remove Queue.empty() and Queue.full() in favor of using qsize() or trapping the Empty and Full exceptions.
Raymond Hettinger <python@rcn.com>
parents:
44604
diff
changeset
|
259 if self.queue.qsize(): |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
260 exc = self.queue.get() |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
261 raise exc |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
262 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
263 def clientRun(self, test_func): |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
264 self.server_ready.wait() |
|
72448
aa4b9ed71538
Fix a race condition in test_socket.ThreadableTest: the client is reported as
Charles-François Natali <neologix@free.fr>
parents:
70016
diff
changeset
|
265 self.clientSetUp() |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
266 self.client_ready.set() |
|
72849
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
267 if self.server_crashed: |
|
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
268 self.clientTearDown() |
|
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
269 return |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41809
diff
changeset
|
270 if not hasattr(test_func, '__call__'): |
|
43014
9834301a2fd3
Raise statement normalization in Lib/test/.
Collin Winter <collinw@gmail.com>
parents:
42637
diff
changeset
|
271 raise TypeError("test_func must be a callable function") |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
272 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
273 test_func() |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
274 except BaseException as e: |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
275 self.queue.put(e) |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
276 finally: |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
277 self.clientTearDown() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
278 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
279 def clientSetUp(self): |
|
43014
9834301a2fd3
Raise statement normalization in Lib/test/.
Collin Winter <collinw@gmail.com>
parents:
42637
diff
changeset
|
280 raise NotImplementedError("clientSetUp must be implemented.") |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
281 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
282 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
283 self.done.set() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
284 thread.exit() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
285 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
286 class ThreadedTCPSocketTest(SocketTCPTest, ThreadableTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
287 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
288 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
289 SocketTCPTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
290 ThreadableTest.__init__(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
291 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
292 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
293 self.cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
294 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
295 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
296 self.cli.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
297 self.cli = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
298 ThreadableTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
299 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
300 class ThreadedUDPSocketTest(SocketUDPTest, ThreadableTest): |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
301 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
302 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
303 SocketUDPTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
304 ThreadableTest.__init__(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
305 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
306 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
307 self.cli = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
308 |
|
65926
8d659a5479ca
Merged revisions 86151 via svnmerge from
Brian Curtin <brian.curtin@gmail.com>
parents:
65429
diff
changeset
|
309 def clientTearDown(self): |
|
8d659a5479ca
Merged revisions 86151 via svnmerge from
Brian Curtin <brian.curtin@gmail.com>
parents:
65429
diff
changeset
|
310 self.cli.close() |
|
8d659a5479ca
Merged revisions 86151 via svnmerge from
Brian Curtin <brian.curtin@gmail.com>
parents:
65429
diff
changeset
|
311 self.cli = None |
|
8d659a5479ca
Merged revisions 86151 via svnmerge from
Brian Curtin <brian.curtin@gmail.com>
parents:
65429
diff
changeset
|
312 ThreadableTest.clientTearDown(self) |
|
8d659a5479ca
Merged revisions 86151 via svnmerge from
Brian Curtin <brian.curtin@gmail.com>
parents:
65429
diff
changeset
|
313 |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
314 class ThreadedCANSocketTest(SocketCANTest, ThreadableTest): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
315 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
316 def __init__(self, methodName='runTest'): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
317 SocketCANTest.__init__(self, methodName=methodName) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
318 ThreadableTest.__init__(self) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
319 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
320 def clientSetUp(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
321 self.cli = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
322 try: |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
323 self.cli.bind((self.interface,)) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
324 except OSError: |
|
72849
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
325 # skipTest should not be called here, and will be called in the |
|
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
326 # server instead |
|
f7f9d5ac6d60
Fix the threading infrastructure in test_socket to support skipping
Antoine Pitrou <solipsis@pitrou.net>
parents:
72758
diff
changeset
|
327 pass |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
328 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
329 def clientTearDown(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
330 self.cli.close() |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
331 self.cli = None |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
332 ThreadableTest.clientTearDown(self) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
333 |
|
73478
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
334 class ThreadedRDSSocketTest(SocketRDSTest, ThreadableTest): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
335 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
336 def __init__(self, methodName='runTest'): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
337 SocketRDSTest.__init__(self, methodName=methodName) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
338 ThreadableTest.__init__(self) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
339 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
340 def clientSetUp(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
341 self.cli = socket.socket(socket.PF_RDS, socket.SOCK_SEQPACKET, 0) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
342 try: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
343 # RDS sockets must be bound explicitly to send or receive data |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
344 self.cli.bind((HOST, 0)) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
345 self.cli_addr = self.cli.getsockname() |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
346 except OSError: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
347 # skipTest should not be called here, and will be called in the |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
348 # server instead |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
349 pass |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
350 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
351 def clientTearDown(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
352 self.cli.close() |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
353 self.cli = None |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
354 ThreadableTest.clientTearDown(self) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
355 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
356 class SocketConnectedTest(ThreadedTCPSocketTest): |
|
42434
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
357 """Socket tests for client-server connection. |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
358 |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
359 self.cli_conn is a client socket connected to the server. The |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
360 setUp() method guarantees that it is connected to the server. |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
361 """ |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
362 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
363 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
364 ThreadedTCPSocketTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
365 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
366 def setUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
367 ThreadedTCPSocketTest.setUp(self) |
|
23909
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
368 # Indicate explicitly we're ready for the client thread to |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
369 # proceed and then perform the blocking call to accept |
|
b16d4be6a232
Michael fixed the race conditions and removed the sleeps.
Guido van Rossum <guido@python.org>
parents:
23831
diff
changeset
|
370 self.serverExplicitReady() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
371 conn, addr = self.serv.accept() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
372 self.cli_conn = conn |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
373 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
374 def tearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
375 self.cli_conn.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
376 self.cli_conn = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
377 ThreadedTCPSocketTest.tearDown(self) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
378 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
379 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
380 ThreadedTCPSocketTest.clientSetUp(self) |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
381 self.cli.connect((HOST, self.port)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
382 self.serv_conn = self.cli |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
383 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
384 def clientTearDown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
385 self.serv_conn.close() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
386 self.serv_conn = None |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
387 ThreadedTCPSocketTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
388 |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
389 class SocketPairTest(unittest.TestCase, ThreadableTest): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
390 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
391 def __init__(self, methodName='runTest'): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
392 unittest.TestCase.__init__(self, methodName=methodName) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
393 ThreadableTest.__init__(self) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
394 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
395 def setUp(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
396 self.serv, self.cli = socket.socketpair() |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
397 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
398 def tearDown(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
399 self.serv.close() |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
400 self.serv = None |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
401 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
402 def clientSetUp(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
403 pass |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
404 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
405 def clientTearDown(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
406 self.cli.close() |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
407 self.cli = None |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
408 ThreadableTest.clientTearDown(self) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
409 |
|
33076
836e77266f97
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
33063
diff
changeset
|
410 |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
411 # The following classes are used by the sendmsg()/recvmsg() tests. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
412 # Combining, for instance, ConnectedStreamTestMixin and TCPTestBase |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
413 # gives a drop-in replacement for SocketConnectedTest, but different |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
414 # address families can be used, and the attributes serv_addr and |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
415 # cli_addr will be set to the addresses of the endpoints. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
416 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
417 class SocketTestBase(unittest.TestCase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
418 """A base class for socket tests. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
419 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
420 Subclasses must provide methods newSocket() to return a new socket |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
421 and bindSock(sock) to bind it to an unused address. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
422 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
423 Creates a socket self.serv and sets self.serv_addr to its address. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
424 """ |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
425 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
426 def setUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
427 self.serv = self.newSocket() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
428 self.bindServer() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
429 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
430 def bindServer(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
431 """Bind server socket and set self.serv_addr to its address.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
432 self.bindSock(self.serv) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
433 self.serv_addr = self.serv.getsockname() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
434 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
435 def tearDown(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
436 self.serv.close() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
437 self.serv = None |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
438 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
439 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
440 class SocketListeningTestMixin(SocketTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
441 """Mixin to listen on the server socket.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
442 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
443 def setUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
444 super().setUp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
445 self.serv.listen(1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
446 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
447 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
448 class ThreadedSocketTestMixin(ThreadSafeCleanupTestCase, SocketTestBase, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
449 ThreadableTest): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
450 """Mixin to add client socket and allow client/server tests. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
451 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
452 Client socket is self.cli and its address is self.cli_addr. See |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
453 ThreadableTest for usage information. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
454 """ |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
455 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
456 def __init__(self, *args, **kwargs): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
457 super().__init__(*args, **kwargs) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
458 ThreadableTest.__init__(self) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
459 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
460 def clientSetUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
461 self.cli = self.newClientSocket() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
462 self.bindClient() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
463 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
464 def newClientSocket(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
465 """Return a new socket for use as client.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
466 return self.newSocket() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
467 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
468 def bindClient(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
469 """Bind client socket and set self.cli_addr to its address.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
470 self.bindSock(self.cli) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
471 self.cli_addr = self.cli.getsockname() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
472 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
473 def clientTearDown(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
474 self.cli.close() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
475 self.cli = None |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
476 ThreadableTest.clientTearDown(self) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
477 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
478 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
479 class ConnectedStreamTestMixin(SocketListeningTestMixin, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
480 ThreadedSocketTestMixin): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
481 """Mixin to allow client/server stream tests with connected client. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
482 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
483 Server's socket representing connection to client is self.cli_conn |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
484 and client's connection to server is self.serv_conn. (Based on |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
485 SocketConnectedTest.) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
486 """ |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
487 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
488 def setUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
489 super().setUp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
490 # Indicate explicitly we're ready for the client thread to |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
491 # proceed and then perform the blocking call to accept |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
492 self.serverExplicitReady() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
493 conn, addr = self.serv.accept() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
494 self.cli_conn = conn |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
495 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
496 def tearDown(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
497 self.cli_conn.close() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
498 self.cli_conn = None |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
499 super().tearDown() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
500 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
501 def clientSetUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
502 super().clientSetUp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
503 self.cli.connect(self.serv_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
504 self.serv_conn = self.cli |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
505 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
506 def clientTearDown(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
507 self.serv_conn.close() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
508 self.serv_conn = None |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
509 super().clientTearDown() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
510 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
511 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
512 class UnixSocketTestBase(SocketTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
513 """Base class for Unix-domain socket tests.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
514 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
515 # This class is used for file descriptor passing tests, so we |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
516 # create the sockets in a private directory so that other users |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
517 # can't send anything that might be problematic for a privileged |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
518 # user running the tests. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
519 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
520 def setUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
521 self.dir_path = tempfile.mkdtemp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
522 self.addCleanup(os.rmdir, self.dir_path) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
523 super().setUp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
524 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
525 def bindSock(self, sock): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
526 path = tempfile.mktemp(dir=self.dir_path) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
527 sock.bind(path) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
528 self.addCleanup(support.unlink, path) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
529 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
530 class UnixStreamBase(UnixSocketTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
531 """Base class for Unix-domain SOCK_STREAM tests.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
532 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
533 def newSocket(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
534 return socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
535 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
536 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
537 class InetTestBase(SocketTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
538 """Base class for IPv4 socket tests.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
539 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
540 host = HOST |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
541 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
542 def setUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
543 super().setUp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
544 self.port = self.serv_addr[1] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
545 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
546 def bindSock(self, sock): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
547 support.bind_port(sock, host=self.host) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
548 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
549 class TCPTestBase(InetTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
550 """Base class for TCP-over-IPv4 tests.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
551 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
552 def newSocket(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
553 return socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
554 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
555 class UDPTestBase(InetTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
556 """Base class for UDP-over-IPv4 tests.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
557 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
558 def newSocket(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
559 return socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
560 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
561 class SCTPStreamBase(InetTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
562 """Base class for SCTP tests in one-to-one (SOCK_STREAM) mode.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
563 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
564 def newSocket(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
565 return socket.socket(socket.AF_INET, socket.SOCK_STREAM, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
566 socket.IPPROTO_SCTP) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
567 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
568 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
569 class Inet6TestBase(InetTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
570 """Base class for IPv6 socket tests.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
571 |
|
85470
f20201db7592
Use the recent support.HOSTv6 addition.
Charles-François Natali <cf.natali@gmail.com>
parents:
85454
diff
changeset
|
572 host = support.HOSTv6 |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
573 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
574 class UDP6TestBase(Inet6TestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
575 """Base class for UDP-over-IPv6 tests.""" |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
576 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
577 def newSocket(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
578 return socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
579 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
580 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
581 # Test-skipping decorators for use with ThreadableTest. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
582 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
583 def skipWithClientIf(condition, reason): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
584 """Skip decorated test if condition is true, add client_skip decorator. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
585 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
586 If the decorated object is not a class, sets its attribute |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
587 "client_skip" to a decorator which will return an empty function |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
588 if the test is to be skipped, or the original function if it is |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
589 not. This can be used to avoid running the client part of a |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
590 skipped test when using ThreadableTest. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
591 """ |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
592 def client_pass(*args, **kwargs): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
593 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
594 def skipdec(obj): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
595 retval = unittest.skip(reason)(obj) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
596 if not isinstance(obj, type): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
597 retval.client_skip = lambda f: client_pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
598 return retval |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
599 def noskipdec(obj): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
600 if not (isinstance(obj, type) or hasattr(obj, "client_skip")): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
601 obj.client_skip = lambda f: f |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
602 return obj |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
603 return skipdec if condition else noskipdec |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
604 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
605 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
606 def requireAttrs(obj, *attributes): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
607 """Skip decorated test if obj is missing any of the given attributes. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
608 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
609 Sets client_skip attribute as skipWithClientIf() does. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
610 """ |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
611 missing = [name for name in attributes if not hasattr(obj, name)] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
612 return skipWithClientIf( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
613 missing, "don't have " + ", ".join(name for name in missing)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
614 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
615 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
616 def requireSocket(*args): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
617 """Skip decorated test if a socket cannot be created with given arguments. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
618 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
619 When an argument is given as a string, will use the value of that |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
620 attribute of the socket module, or skip the test if it doesn't |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
621 exist. Sets client_skip attribute as skipWithClientIf() does. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
622 """ |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
623 err = None |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
624 missing = [obj for obj in args if |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
625 isinstance(obj, str) and not hasattr(socket, obj)] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
626 if missing: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
627 err = "don't have " + ", ".join(name for name in missing) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
628 else: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
629 callargs = [getattr(socket, obj) if isinstance(obj, str) else obj |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
630 for obj in args] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
631 try: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
632 s = socket.socket(*callargs) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
633 except OSError as e: |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
634 # XXX: check errno? |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
635 err = str(e) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
636 else: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
637 s.close() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
638 return skipWithClientIf( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
639 err is not None, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
640 "can't create socket({0}): {1}".format( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
641 ", ".join(str(o) for o in args), err)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
642 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
643 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
644 ####################################################################### |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
645 ## Begin Tests |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
646 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
647 class GeneralModuleTests(unittest.TestCase): |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
648 |
|
41941
e4ab08039c75
Simplify socket_repr() by using PyUnicode_FromFormat()
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
649 def test_repr(self): |
|
e4ab08039c75
Simplify socket_repr() by using PyUnicode_FromFormat()
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
650 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
83230
1410b7790de6
Fix issue #17675: make socket repr() provide local and remote addresses (if any).
Giampaolo Rodola' <g.rodola@gmail.com>
parents:
82844
diff
changeset
|
651 with s: |
|
1410b7790de6
Fix issue #17675: make socket repr() provide local and remote addresses (if any).
Giampaolo Rodola' <g.rodola@gmail.com>
parents:
82844
diff
changeset
|
652 self.assertIn('fd=%i' % s.fileno(), repr(s)) |
|
1410b7790de6
Fix issue #17675: make socket repr() provide local and remote addresses (if any).
Giampaolo Rodola' <g.rodola@gmail.com>
parents:
82844
diff
changeset
|
653 self.assertIn('family=%i' % socket.AF_INET, repr(s)) |
|
1410b7790de6
Fix issue #17675: make socket repr() provide local and remote addresses (if any).
Giampaolo Rodola' <g.rodola@gmail.com>
parents:
82844
diff
changeset
|
654 self.assertIn('type=%i' % socket.SOCK_STREAM, repr(s)) |
|
1410b7790de6
Fix issue #17675: make socket repr() provide local and remote addresses (if any).
Giampaolo Rodola' <g.rodola@gmail.com>
parents:
82844
diff
changeset
|
655 self.assertIn('proto=0', repr(s)) |
|
1410b7790de6
Fix issue #17675: make socket repr() provide local and remote addresses (if any).
Giampaolo Rodola' <g.rodola@gmail.com>
parents:
82844
diff
changeset
|
656 self.assertNotIn('raddr', repr(s)) |
|
1410b7790de6
Fix issue #17675: make socket repr() provide local and remote addresses (if any).
Giampaolo Rodola' <g.rodola@gmail.com>
parents:
82844
diff
changeset
|
657 s.bind(('127.0.0.1', 0)) |
|
83274
e68bd20b5434
attempt to fix bb failure as per http://bugs.python.org/issue17675#msg186595
Giampaolo Rodola' <g.rodola@gmail.com>
parents:
83230
diff
changeset
|
658 self.assertIn('laddr', repr(s)) |
|
83230
1410b7790de6
Fix issue #17675: make socket repr() provide local and remote addresses (if any).
Giampaolo Rodola' <g.rodola@gmail.com>
parents:
82844
diff
changeset
|
659 self.assertIn(str(s.getsockname()), repr(s)) |
|
1410b7790de6
Fix issue #17675: make socket repr() provide local and remote addresses (if any).
Giampaolo Rodola' <g.rodola@gmail.com>
parents:
82844
diff
changeset
|
660 self.assertIn('[closed]', repr(s)) |
|
1410b7790de6
Fix issue #17675: make socket repr() provide local and remote addresses (if any).
Giampaolo Rodola' <g.rodola@gmail.com>
parents:
82844
diff
changeset
|
661 self.assertNotIn('laddr', repr(s)) |
|
41941
e4ab08039c75
Simplify socket_repr() by using PyUnicode_FromFormat()
Walter Dörwald <walter@livinglogic.de>
parents:
41824
diff
changeset
|
662 |
|
32160
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
663 def test_weakref(self): |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
664 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
665 p = proxy(s) |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
666 self.assertEqual(p.fileno(), s.fileno()) |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
667 s.close() |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
668 s = None |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
669 try: |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
670 p.fileno() |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
671 except ReferenceError: |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
672 pass |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
673 else: |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
674 self.fail('Socket proxy still exists') |
|
aec9c98a47d2
Add weakref support to sockets and re pattern objects.
Raymond Hettinger <python@rcn.com>
parents:
31833
diff
changeset
|
675 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
676 def testSocketError(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
677 # Testing socket module exceptions |
|
69940
9af64d83c217
Refactor buggy test to correctly use the msg argument of assertRaises.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69918
diff
changeset
|
678 msg = "Error raising socket exception (%s)." |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
679 with self.assertRaises(OSError, msg=msg % 'OSError'): |
|
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
680 raise OSError |
|
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
681 with self.assertRaises(OSError, msg=msg % 'socket.herror'): |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
682 raise socket.herror |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
683 with self.assertRaises(OSError, msg=msg % 'socket.gaierror'): |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
684 raise socket.gaierror |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
685 |
| 69916 | 686 def testSendtoErrors(self): |
| 687 # Testing that sendto doens't masks failures. See #10169. | |
| 688 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
| 689 self.addCleanup(s.close) | |
| 690 s.bind(('', 0)) | |
| 691 sockname = s.getsockname() | |
| 692 # 2 args | |
| 69917 | 693 with self.assertRaises(TypeError) as cm: |
| 69916 | 694 s.sendto('\u2620', sockname) |
| 69917 | 695 self.assertEqual(str(cm.exception), |
| 696 "'str' does not support the buffer interface") | |
| 697 with self.assertRaises(TypeError) as cm: | |
| 69916 | 698 s.sendto(5j, sockname) |
| 69917 | 699 self.assertEqual(str(cm.exception), |
| 700 "'complex' does not support the buffer interface") | |
| 701 with self.assertRaises(TypeError) as cm: | |
| 69916 | 702 s.sendto(b'foo', None) |
| 69917 | 703 self.assertIn('not NoneType',str(cm.exception)) |
| 69916 | 704 # 3 args |
| 69917 | 705 with self.assertRaises(TypeError) as cm: |
| 69916 | 706 s.sendto('\u2620', 0, sockname) |
| 69917 | 707 self.assertEqual(str(cm.exception), |
| 708 "'str' does not support the buffer interface") | |
| 709 with self.assertRaises(TypeError) as cm: | |
| 69916 | 710 s.sendto(5j, 0, sockname) |
| 69917 | 711 self.assertEqual(str(cm.exception), |
| 712 "'complex' does not support the buffer interface") | |
| 713 with self.assertRaises(TypeError) as cm: | |
| 69916 | 714 s.sendto(b'foo', 0, None) |
| 69917 | 715 self.assertIn('not NoneType', str(cm.exception)) |
| 716 with self.assertRaises(TypeError) as cm: | |
| 69916 | 717 s.sendto(b'foo', 'bar', sockname) |
| 69917 | 718 self.assertIn('an integer is required', str(cm.exception)) |
| 719 with self.assertRaises(TypeError) as cm: | |
| 69916 | 720 s.sendto(b'foo', None, None) |
| 69917 | 721 self.assertIn('an integer is required', str(cm.exception)) |
| 69916 | 722 # wrong number of args |
| 69917 | 723 with self.assertRaises(TypeError) as cm: |
| 69916 | 724 s.sendto(b'foo') |
| 69917 | 725 self.assertIn('(1 given)', str(cm.exception)) |
| 726 with self.assertRaises(TypeError) as cm: | |
| 69916 | 727 s.sendto(b'foo', 0, sockname, 4) |
| 69917 | 728 self.assertIn('(4 given)', str(cm.exception)) |
| 69916 | 729 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
730 def testCrucialConstants(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
731 # Testing for mission critical constants |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
732 socket.AF_INET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
733 socket.SOCK_STREAM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
734 socket.SOCK_DGRAM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
735 socket.SOCK_RAW |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
736 socket.SOCK_RDM |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
737 socket.SOCK_SEQPACKET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
738 socket.SOL_SOCKET |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
739 socket.SO_REUSEADDR |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
740 |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
741 def testHostnameRes(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
742 # Testing hostname resolution mechanisms |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
743 hostname = socket.gethostname() |
|
26799
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
744 try: |
|
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
745 ip = socket.gethostbyname(hostname) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
746 except OSError: |
|
26799
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
747 # Probably name lookup wasn't set up right; skip this test |
|
507aa96a128f
Skip testHostnameRes() if gethostbyname() raises an exception.
Guido van Rossum <guido@python.org>
parents:
25285
diff
changeset
|
748 return |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
749 self.assertTrue(ip.find('.') >= 0, "Error resolving host to ip.") |
|
26800
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
750 try: |
|
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
751 hname, aliases, ipaddrs = socket.gethostbyaddr(ip) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
752 except OSError: |
|
26800
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
753 # Probably a similar problem as above; skip this test |
|
b2b4797052c6
Also skip testHostnameRes() if gethostbyaddr() raises an exception.
Guido van Rossum <guido@python.org>
parents:
26799
diff
changeset
|
754 return |
|
34739
0c82a7ef9554
Fix test_socket's test for socket.getfqdn() to also accept the result from
Brett Cannon <bcannon@gmail.com>
parents:
34014
diff
changeset
|
755 all_host_names = [hostname, hname] + aliases |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
756 fqhn = socket.getfqdn(ip) |
|
23831
f7306ae8662d
Temporarily disable the timeout and socket tests.
Guido van Rossum <guido@python.org>
parents:
23819
diff
changeset
|
757 if not fqhn in all_host_names: |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
758 self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqhn, repr(all_host_names))) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
759 |
|
85679
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
760 def test_host_resolution(self): |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
761 for addr in ['0.1.1.~1', '1+.1.1.1', '::1q', '::1::2', |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
762 '1:1:1:1:1:1:1:1:1']: |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
763 self.assertRaises(OSError, socket.gethostbyname, addr) |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
764 self.assertRaises(OSError, socket.gethostbyaddr, addr) |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
765 |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
766 for addr in [support.HOST, '10.0.0.1', '255.255.255.255']: |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
767 self.assertEqual(socket.gethostbyname(addr), addr) |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
768 |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
769 # we don't test support.HOSTv6 because there's a chance it doesn't have |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
770 # a matching name entry (e.g. 'ip6-localhost') |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
771 for host in [support.HOST]: |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
772 self.assertIn(host, socket.gethostbyaddr(host)[2]) |
|
540a9c69c2ea
Issue #16201: socket: Use inet_pton()/inet_addr() instead of ad-hoc parsing for
Charles-François Natali <cf.natali@gmail.com>
parents:
85624
diff
changeset
|
773 |
|
68194
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
774 @unittest.skipUnless(hasattr(socket, 'sethostname'), "test needs socket.sethostname()") |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
775 @unittest.skipUnless(hasattr(socket, 'gethostname'), "test needs socket.gethostname()") |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
776 def test_sethostname(self): |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
777 oldhn = socket.gethostname() |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
778 try: |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
779 socket.sethostname('new') |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
780 except OSError as e: |
|
68194
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
781 if e.errno == errno.EPERM: |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
782 self.skipTest("test should be run as root") |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
783 else: |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
784 raise |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
785 try: |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
786 # running test as root! |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
787 self.assertEqual(socket.gethostname(), 'new') |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
788 # Should work with bytes objects too |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
789 socket.sethostname(b'bar') |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
790 self.assertEqual(socket.gethostname(), 'bar') |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
791 finally: |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
792 socket.sethostname(oldhn) |
|
a2d61117c2d2
Issue #10866: Add socket.sethostname(). Initial patch by Ross Lagerwall.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68159
diff
changeset
|
793 |
|
70136
c2515cb23d9b
Issue #1746656: Add if_nameindex, if_nametoindex, if_indextoname
Gregory P. Smith <greg@krypto.org>
parents:
70017
diff
changeset
|
794 @unittest.skipUnless(hasattr(socket, 'if_nameindex'), |
|
c2515cb23d9b
Issue #1746656: Add if_nameindex, if_nametoindex, if_indextoname
Gregory P. Smith <greg@krypto.org>
parents:
70017
diff
changeset
|
795 'socket.if_nameindex() not available.') |
|
c2515cb23d9b
Issue #1746656: Add if_nameindex, if_nametoindex, if_indextoname
Gregory P. Smith <greg@krypto.org>
parents:
70017
diff
changeset
|
796 def testInterfaceNameIndex(self): |
|
c2515cb23d9b
Issue #1746656: Add if_nameindex, if_nametoindex, if_indextoname
Gregory P. Smith <greg@krypto.org>
parents:
70017
diff
changeset
|
797 interfaces = socket.if_nameindex() |
|
c2515cb23d9b
Issue #1746656: Add if_nameindex, if_nametoindex, if_indextoname
Gregory P. Smith <greg@krypto.org>
parents:
70017
diff
changeset
|
798 for index, name in interfaces: |
|
70226
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
799 self.assertIsInstance(index, int) |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
800 self.assertIsInstance(name, str) |
|
70136
c2515cb23d9b
Issue #1746656: Add if_nameindex, if_nametoindex, if_indextoname
Gregory P. Smith <greg@krypto.org>
parents:
70017
diff
changeset
|
801 # interface indices are non-zero integers |
|
c2515cb23d9b
Issue #1746656: Add if_nameindex, if_nametoindex, if_indextoname
Gregory P. Smith <greg@krypto.org>
parents:
70017
diff
changeset
|
802 self.assertGreater(index, 0) |
|
70226
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
803 _index = socket.if_nametoindex(name) |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
804 self.assertIsInstance(_index, int) |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
805 self.assertEqual(index, _index) |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
806 _name = socket.if_indextoname(index) |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
807 self.assertIsInstance(_name, str) |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
808 self.assertEqual(name, _name) |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
809 |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
810 @unittest.skipUnless(hasattr(socket, 'if_nameindex'), |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
811 'socket.if_nameindex() not available.') |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
812 def testInvalidInterfaceNameIndex(self): |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
813 # test nonexistent interface index/name |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
814 self.assertRaises(OSError, socket.if_indextoname, 0) |
|
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
815 self.assertRaises(OSError, socket.if_nametoindex, '_DEADBEEF') |
|
70226
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
816 # test with invalid values |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
817 self.assertRaises(TypeError, socket.if_nametoindex, 0) |
|
cc60d0283fad
Issue #1746656: make if_nameindex(), if_indextoname() and if_nametoindex()
Charles-François Natali <neologix@free.fr>
parents:
70136
diff
changeset
|
818 self.assertRaises(TypeError, socket.if_indextoname, '_DEADBEEF') |
|
70136
c2515cb23d9b
Issue #1746656: Add if_nameindex, if_nametoindex, if_indextoname
Gregory P. Smith <greg@krypto.org>
parents:
70017
diff
changeset
|
819 |
|
23799
2ad13ee6d850
Don't test for Java, test for sys.getrefcount.
Guido van Rossum <guido@python.org>
parents:
23798
diff
changeset
|
820 def testRefCountGetNameInfo(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
821 # Testing reference count for getnameinfo |
|
23799
2ad13ee6d850
Don't test for Java, test for sys.getrefcount.
Guido van Rossum <guido@python.org>
parents:
23798
diff
changeset
|
822 if hasattr(sys, "getrefcount"): |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
823 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
824 # On some versions, this loses a reference |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
825 orig = sys.getrefcount(__name__) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
826 socket.getnameinfo(__name__,0) |
|
56368
c9bd62efe6ce
Merged revisions 75231 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
55593
diff
changeset
|
827 except TypeError: |
|
39648
efe3f2c0da5e
Killed the <> operator. You must now use !=.
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
828 if sys.getrefcount(__name__) != orig: |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
829 self.fail("socket.getnameinfo loses a reference") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
830 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
831 def testInterpreterCrash(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
832 # Making sure getnameinfo doesn't crash the interpreter |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
833 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
834 # On some versions, this crashes the interpreter. |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
835 socket.getnameinfo(('x', 0, 0, 0), 0) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
836 except OSError: |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
837 pass |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
838 |
|
25285
4d6f8204234a
Since it tests both ntohl and ntohs, the test should not be called
Guido van Rossum <guido@python.org>
parents:
25256
diff
changeset
|
839 def testNtoH(self): |
|
25256
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
840 # This just checks that htons etc. are their own inverse, |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
841 # when looking at the lower 16 or 32 bits. |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
842 sizes = {socket.htonl: 32, socket.ntohl: 32, |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
843 socket.htons: 16, socket.ntohs: 16} |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
844 for func, size in sizes.items(): |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40638
diff
changeset
|
845 mask = (1<<size) - 1 |
|
25256
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
846 for i in (0, 1, 0xffff, ~0xffff, 2, 0x01234567, 0x76543210): |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
847 self.assertEqual(i & mask, func(func(i&mask)) & mask) |
|
24450
747fa65a9b47
Repair testNtoH for large long arguments.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24375
diff
changeset
|
848 |
|
25256
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
849 swapped = func(mask) |
|
04a541e68964
Maybe this fixes test_socket on 64-bit Linux.
Guido van Rossum <guido@python.org>
parents:
25152
diff
changeset
|
850 self.assertEqual(swapped & mask, mask) |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40638
diff
changeset
|
851 self.assertRaises(OverflowError, func, 1<<34) |
|
24375
89ce62126664
Extended socket.htonl and ntohl to accept longs.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24374
diff
changeset
|
852 |
|
40638
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
853 def testNtoHErrors(self): |
|
40644
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40638
diff
changeset
|
854 good_values = [ 1, 2, 3, 1, 2, 3 ] |
|
1c26505c1de6
Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents:
40638
diff
changeset
|
855 bad_values = [ -1, -2, -3, -1, -2, -3 ] |
|
40638
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
856 for k in good_values: |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
857 socket.ntohl(k) |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
858 socket.ntohs(k) |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
859 socket.htonl(k) |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
860 socket.htons(k) |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
861 for k in bad_values: |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
862 self.assertRaises(OverflowError, socket.ntohl, k) |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
863 self.assertRaises(OverflowError, socket.ntohs, k) |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
864 self.assertRaises(OverflowError, socket.htonl, k) |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
865 self.assertRaises(OverflowError, socket.htons, k) |
|
86ce1df6a88e
Merged revisions 53434 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
866 |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
867 def testGetServBy(self): |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
868 eq = self.assertEqual |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
869 # Find one service that exists, then check all the related interfaces. |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
870 # I've ordered this by protocols that have both a tcp and udp |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
871 # protocol, at least for modern Linuxes. |
|
72011
b5ccdf7c032a
Issue #12326: refactor usage of sys.platform
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71897
diff
changeset
|
872 if (sys.platform.startswith(('freebsd', 'netbsd')) |
|
b5ccdf7c032a
Issue #12326: refactor usage of sys.platform
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71897
diff
changeset
|
873 or sys.platform in ('linux', 'darwin')): |
|
32630
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
874 # avoid the 'echo' service on this platform, as there is an |
|
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
875 # assumption breaking non-standard port/protocol entry |
|
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
876 services = ('daytime', 'qotd', 'domain') |
|
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
877 else: |
|
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
878 services = ('echo', 'daytime', 'domain') |
|
059dae06585b
FreeBSD's services file contains an additional echo service entry, with
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents:
32508
diff
changeset
|
879 for service in services: |
|
24485
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
880 try: |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
881 port = socket.getservbyname(service, 'tcp') |
|
24485
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
882 break |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
883 except OSError: |
|
24485
f05a311d7988
testGetServByName shouldn't check for getservbyname - the socket module
Skip Montanaro <skip@pobox.com>
parents:
24470
diff
changeset
|
884 pass |
|
31503
eb48b2503f20
Fix indentation error in testGetServByName and rewrite loop to avoid clumsy
Skip Montanaro <skip@pobox.com>
parents:
29662
diff
changeset
|
885 else: |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
886 raise OSError |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
887 # Try same call with optional protocol omitted |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
888 port2 = socket.getservbyname(service) |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
889 eq(port, port2) |
|
82618
3f5f961262ec
Issue #17047: remove doubled words found in 2.7 to 3.4 Lib/*,
Terry Jan Reedy <tjreedy@udel.edu>
parents:
81587
diff
changeset
|
890 # Try udp, but don't barf if it doesn't exist |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
891 try: |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
892 udpport = socket.getservbyname(service, 'udp') |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
893 except OSError: |
|
32429
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
894 udpport = None |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
895 else: |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
896 eq(udpport, port) |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
897 # Now make sure the lookup by port returns the same service name |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
898 eq(socket.getservbyport(port2), service) |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
899 eq(socket.getservbyport(port, 'tcp'), service) |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
900 if udpport is not None: |
|
d8abf582f893
Added socket.getservbyport(), and make its second argument and that of
Barry Warsaw <barry@python.org>
parents:
32160
diff
changeset
|
901 eq(socket.getservbyport(udpport, 'udp'), service) |
|
51382
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
902 # Make sure getservbyport does not accept out of range ports. |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
903 self.assertRaises(OverflowError, socket.getservbyport, -1) |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
904 self.assertRaises(OverflowError, socket.getservbyport, 65536) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
905 |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
906 def testDefaultTimeout(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
907 # Testing default timeout |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
908 # The default timeout should initially be None |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
909 self.assertEqual(socket.getdefaulttimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
910 s = socket.socket() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
911 self.assertEqual(s.gettimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
912 s.close() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
913 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
914 # Set the default timeout to 10, and see if it propagates |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
915 socket.setdefaulttimeout(10) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
916 self.assertEqual(socket.getdefaulttimeout(), 10) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
917 s = socket.socket() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
918 self.assertEqual(s.gettimeout(), 10) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
919 s.close() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
920 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
921 # Reset the default timeout to None, and see if it propagates |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
922 socket.setdefaulttimeout(None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
923 self.assertEqual(socket.getdefaulttimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
924 s = socket.socket() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
925 self.assertEqual(s.gettimeout(), None) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
926 s.close() |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
927 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
928 # Check that setting it to an invalid value raises ValueError |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
929 self.assertRaises(ValueError, socket.setdefaulttimeout, -1) |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
930 |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
931 # Check that setting it to an invalid type raises TypeError |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
932 self.assertRaises(TypeError, socket.setdefaulttimeout, "spam") |
|
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
933 |
|
51579
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51382
diff
changeset
|
934 def testIPv4_inet_aton_fourbytes(self): |
|
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51382
diff
changeset
|
935 if not hasattr(socket, 'inet_aton'): |
|
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51382
diff
changeset
|
936 return # No inet_aton, nothing to check |
|
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51382
diff
changeset
|
937 # Test that issue1008086 and issue767150 are fixed. |
|
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51382
diff
changeset
|
938 # It must return 4 bytes. |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
939 self.assertEqual(b'\x00'*4, socket.inet_aton('0.0.0.0')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
940 self.assertEqual(b'\xff'*4, socket.inet_aton('255.255.255.255')) |
|
51579
648e07dd0825
Merged revisions 69364-69365,69409-69410,69413,69417,69435,69442,69447,69495,69519-69521 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51382
diff
changeset
|
941 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
942 def testIPv4toString(self): |
|
28833
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
943 if not hasattr(socket, 'inet_pton'): |
|
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
944 return # No inet_pton() on this platform |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
945 from socket import inet_aton as f, inet_pton, AF_INET |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
946 g = lambda a: inet_pton(AF_INET, a) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
947 |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
948 assertInvalid = lambda func,a: self.assertRaises( |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
949 (OSError, ValueError), func, a |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
950 ) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
951 |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
952 self.assertEqual(b'\x00\x00\x00\x00', f('0.0.0.0')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
953 self.assertEqual(b'\xff\x00\xff\x00', f('255.0.255.0')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
954 self.assertEqual(b'\xaa\xaa\xaa\xaa', f('170.170.170.170')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
955 self.assertEqual(b'\x01\x02\x03\x04', f('1.2.3.4')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
956 self.assertEqual(b'\xff\xff\xff\xff', f('255.255.255.255')) |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
957 assertInvalid(f, '0.0.0.') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
958 assertInvalid(f, '300.0.0.0') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
959 assertInvalid(f, 'a.0.0.0') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
960 assertInvalid(f, '1.2.3.4.5') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
961 assertInvalid(f, '::1') |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
962 |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
963 self.assertEqual(b'\x00\x00\x00\x00', g('0.0.0.0')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
964 self.assertEqual(b'\xff\x00\xff\x00', g('255.0.255.0')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
965 self.assertEqual(b'\xaa\xaa\xaa\xaa', g('170.170.170.170')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
966 self.assertEqual(b'\xff\xff\xff\xff', g('255.255.255.255')) |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
967 assertInvalid(g, '0.0.0.') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
968 assertInvalid(g, '300.0.0.0') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
969 assertInvalid(g, 'a.0.0.0') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
970 assertInvalid(g, '1.2.3.4.5') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
971 assertInvalid(g, '::1') |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
972 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
973 def testIPv6toString(self): |
|
28833
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
974 if not hasattr(socket, 'inet_pton'): |
|
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
975 return # No inet_pton() on this platform |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
976 try: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
977 from socket import inet_pton, AF_INET6, has_ipv6 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
978 if not has_ipv6: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
979 return |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
980 except ImportError: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
981 return |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
982 f = lambda a: inet_pton(AF_INET6, a) |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
983 assertInvalid = lambda a: self.assertRaises( |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
984 (OSError, ValueError), f, a |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
985 ) |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
986 |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
987 self.assertEqual(b'\x00' * 16, f('::')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
988 self.assertEqual(b'\x00' * 16, f('0::0')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
989 self.assertEqual(b'\x00\x01' + b'\x00' * 14, f('1::')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
990 self.assertEqual( |
|
42169
e38047550383
Fix test_socket.py. Simple str/bytes issue with IPV6 addresse.
Guido van Rossum <guido@python.org>
parents:
41941
diff
changeset
|
991 b'\x45\xef\x76\xcb\x00\x1a\x56\xef\xaf\xeb\x0b\xac\x19\x24\xae\xae', |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
992 f('45ef:76cb:1a:56ef:afeb:bac:1924:aeae') |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
993 ) |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
994 self.assertEqual( |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
995 b'\xad\x42\x0a\xbc' + b'\x00' * 4 + b'\x01\x27\x00\x00\x02\x54\x00\x02', |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
996 f('ad42:abc::127:0:254:2') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
997 ) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
998 self.assertEqual(b'\x00\x12\x00\x0a' + b'\x00' * 12, f('12:a::')) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
999 assertInvalid('0x20::') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1000 assertInvalid(':::') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1001 assertInvalid('::0::') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1002 assertInvalid('1::abc::') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1003 assertInvalid('1::abc::def') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1004 assertInvalid('1:2:3:4:5:6:') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1005 assertInvalid('1:2:3:4:5:6') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1006 assertInvalid('1:2:3:4:5:6:7:8:') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1007 assertInvalid('1:2:3:4:5:6:7:8:0') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1008 |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1009 self.assertEqual(b'\x00' * 12 + b'\xfe\x2a\x17\x40', |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1010 f('::254.42.23.64') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1011 ) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1012 self.assertEqual( |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1013 b'\x00\x42' + b'\x00' * 8 + b'\xa2\x9b\xfe\x2a\x17\x40', |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1014 f('42::a29b:254.42.23.64') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1015 ) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1016 self.assertEqual( |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1017 b'\x00\x42\xa8\xb9\x00\x00\x00\x02\xff\xff\xa2\x9b\xfe\x2a\x17\x40', |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1018 f('42:a8b9:0:2:ffff:a29b:254.42.23.64') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1019 ) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1020 assertInvalid('255.254.253.252') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1021 assertInvalid('1::260.2.3.0') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1022 assertInvalid('1::0.be.e.0') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1023 assertInvalid('1:2:3:4:5:6:7:1.2.3.4') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1024 assertInvalid('::1.2.3.4:0') |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1025 assertInvalid('0.100.200.0:3:4:5:6:7:8') |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
1026 |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1027 def testStringToIPv4(self): |
|
28833
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
1028 if not hasattr(socket, 'inet_ntop'): |
|
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
1029 return # No inet_ntop() on this platform |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1030 from socket import inet_ntoa as f, inet_ntop, AF_INET |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1031 g = lambda a: inet_ntop(AF_INET, a) |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1032 assertInvalid = lambda func,a: self.assertRaises( |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
1033 (OSError, ValueError), func, a |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1034 ) |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1035 |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
1036 self.assertEqual('1.0.1.0', f(b'\x01\x00\x01\x00')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
1037 self.assertEqual('170.85.170.85', f(b'\xaa\x55\xaa\x55')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
1038 self.assertEqual('255.255.255.255', f(b'\xff\xff\xff\xff')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
1039 self.assertEqual('1.2.3.4', f(b'\x01\x02\x03\x04')) |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1040 assertInvalid(f, b'\x00' * 3) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1041 assertInvalid(f, b'\x00' * 5) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1042 assertInvalid(f, b'\x00' * 16) |
|
29087
526f37fb380d
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
28917
diff
changeset
|
1043 |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
1044 self.assertEqual('1.0.1.0', g(b'\x01\x00\x01\x00')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
1045 self.assertEqual('170.85.170.85', g(b'\xaa\x55\xaa\x55')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
1046 self.assertEqual('255.255.255.255', g(b'\xff\xff\xff\xff')) |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1047 assertInvalid(g, b'\x00' * 3) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1048 assertInvalid(g, b'\x00' * 5) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1049 assertInvalid(g, b'\x00' * 16) |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1050 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1051 def testStringToIPv6(self): |
|
28833
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
1052 if not hasattr(socket, 'inet_ntop'): |
|
fa159fef2730
Skip testing inet_ntop() an inet_pton() if they aren't defined.
Guido van Rossum <guido@python.org>
parents:
28818
diff
changeset
|
1053 return # No inet_ntop() on this platform |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1054 try: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1055 from socket import inet_ntop, AF_INET6, has_ipv6 |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1056 if not has_ipv6: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1057 return |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1058 except ImportError: |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1059 return |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1060 f = lambda a: inet_ntop(AF_INET6, a) |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1061 assertInvalid = lambda a: self.assertRaises( |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
1062 (OSError, ValueError), f, a |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1063 ) |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1064 |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
1065 self.assertEqual('::', f(b'\x00' * 16)) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
1066 self.assertEqual('::1', f(b'\x00' * 15 + b'\x01')) |
|
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
1067 self.assertEqual( |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1068 'aef:b01:506:1001:ffff:9997:55:170', |
|
42169
e38047550383
Fix test_socket.py. Simple str/bytes issue with IPV6 addresse.
Guido van Rossum <guido@python.org>
parents:
41941
diff
changeset
|
1069 f(b'\x0a\xef\x0b\x01\x05\x06\x10\x01\xff\xff\x99\x97\x00\x55\x01\x70') |
|
28818
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1070 ) |
|
57e61588571b
Patch by Jp Calderone:
Guido van Rossum <guido@python.org>
parents:
26800
diff
changeset
|
1071 |
|
74082
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1072 assertInvalid(b'\x12' * 15) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1073 assertInvalid(b'\x12' * 17) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1074 assertInvalid(b'\x12' * 4) |
|
71e5a083f9b1
Issue #5424: add tests for inet_ntoa, inet_ntop, inet_aton and inet_pton.
Antoine Pitrou <solipsis@pitrou.net>
parents:
73612
diff
changeset
|
1075 |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
1076 # XXX The following don't test module-level functionality... |
|
24293
640370f08e2a
Add default timeout functionality. This adds setdefaulttimeout() and
Guido van Rossum <guido@python.org>
parents:
23931
diff
changeset
|
1077 |
|
51382
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1078 def testSockName(self): |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1079 # Testing getsockname() |
|
70016
695a7acae392
Issue #12054: use support.find_unused_port() instead of reinventing the wheel
Antoine Pitrou <solipsis@pitrou.net>
parents:
70012
diff
changeset
|
1080 port = support.find_unused_port() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1081 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
1082 self.addCleanup(sock.close) |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
1083 sock.bind(("0.0.0.0", port)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1084 name = sock.getsockname() |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
1085 # XXX(nnorwitz): http://tinyurl.com/os5jz seems to indicate |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
1086 # it reasonable to get the host's addr in addition to 0.0.0.0. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
1087 # At least for eCos. This is required for the S/390 to pass. |
|
66478
7281937b2d65
Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents:
66340
diff
changeset
|
1088 try: |
|
7281937b2d65
Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents:
66340
diff
changeset
|
1089 my_ip_addr = socket.gethostbyname(socket.gethostname()) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
1090 except OSError: |
|
66478
7281937b2d65
Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents:
66340
diff
changeset
|
1091 # Probably name lookup wasn't set up right; skip this test |
|
7281937b2d65
Merged revisions 86134,86315-86316,86390,86424-86425,86428,86550,86561-86562,86564-86565,86705,86708,86713 via svnmerge from
Georg Brandl <georg@python.org>
parents:
66340
diff
changeset
|
1092 return |
|
58415
f6a626f34840
use assert[Not]In where appropriate
Benjamin Peterson <benjamin@python.org>
parents:
58146
diff
changeset
|
1093 self.assertIn(name[0], ("0.0.0.0", my_ip_addr), '%s invalid' % name[0]) |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
1094 self.assertEqual(name[1], port) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1095 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1096 def testGetSockOpt(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1097 # Testing getsockopt() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1098 # We know a socket should start without reuse==0 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1099 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
1100 self.addCleanup(sock.close) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1101 reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
1102 self.assertFalse(reuse != 0, "initial mode is reuse") |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1103 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1104 def testSetSockOpt(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1105 # Testing setsockopt() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1106 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
1107 self.addCleanup(sock.close) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1108 sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1109 reuse = sock.getsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
1110 self.assertFalse(reuse == 0, "failed to set reuse mode") |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1111 |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
1112 def testSendAfterClose(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1113 # testing send() after close() with timeout |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
1114 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
1115 sock.settimeout(1) |
|
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
1116 sock.close() |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
1117 self.assertRaises(OSError, sock.send, b"spam") |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
1118 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
1119 def testNewAttributes(self): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
1120 # testing .family, .type and .protocol |
|
85420
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
1121 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
1122 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
1123 self.assertEqual(sock.family, socket.AF_INET) |
|
85420
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
1124 if hasattr(socket, 'SOCK_CLOEXEC'): |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
1125 self.assertIn(sock.type, |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
1126 (socket.SOCK_STREAM | socket.SOCK_CLOEXEC, |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
1127 socket.SOCK_STREAM)) |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
1128 else: |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
1129 self.assertEqual(sock.type, socket.SOCK_STREAM) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
1130 self.assertEqual(sock.proto, 0) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
1131 sock.close() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
1132 |
|
51382
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1133 def test_getsockaddrarg(self): |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1134 host = '0.0.0.0' |
|
70016
695a7acae392
Issue #12054: use support.find_unused_port() instead of reinventing the wheel
Antoine Pitrou <solipsis@pitrou.net>
parents:
70012
diff
changeset
|
1135 port = support.find_unused_port() |
|
51382
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1136 big_port = port + 65536 |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1137 neg_port = port - 65536 |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1138 sock = socket.socket() |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1139 try: |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1140 self.assertRaises(OverflowError, sock.bind, (host, big_port)) |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1141 self.assertRaises(OverflowError, sock.bind, (host, neg_port)) |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1142 sock.bind((host, port)) |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1143 finally: |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1144 sock.close() |
|
7e28a2b0c1b1
Merged revisions 69129-69131,69139-69140,69143,69154-69159,69169,69288-69289,69293,69297-69301,69348 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50800
diff
changeset
|
1145 |
|
65975
e213e465a2dc
Add socket cleanup for ResourceWarning and update test to use skip decorator
Brian Curtin <brian.curtin@gmail.com>
parents:
65925
diff
changeset
|
1146 @unittest.skipUnless(os.name == "nt", "Windows specific") |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
1147 def test_sock_ioctl(self): |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
1148 self.assertTrue(hasattr(socket.socket, 'ioctl')) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
1149 self.assertTrue(hasattr(socket, 'SIO_RCVALL')) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
1150 self.assertTrue(hasattr(socket, 'RCVALL_ON')) |
|
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
1151 self.assertTrue(hasattr(socket, 'RCVALL_OFF')) |
|
56252
debb245ebb40
http://bugs.python.org/issue6971
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
55593
diff
changeset
|
1152 self.assertTrue(hasattr(socket, 'SIO_KEEPALIVE_VALS')) |
|
debb245ebb40
http://bugs.python.org/issue6971
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
55593
diff
changeset
|
1153 s = socket.socket() |
|
65975
e213e465a2dc
Add socket cleanup for ResourceWarning and update test to use skip decorator
Brian Curtin <brian.curtin@gmail.com>
parents:
65925
diff
changeset
|
1154 self.addCleanup(s.close) |
|
56252
debb245ebb40
http://bugs.python.org/issue6971
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
55593
diff
changeset
|
1155 self.assertRaises(ValueError, s.ioctl, -1, None) |
|
debb245ebb40
http://bugs.python.org/issue6971
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
55593
diff
changeset
|
1156 s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100)) |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
1157 |
|
64000
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1158 def testGetaddrinfo(self): |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1159 try: |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1160 socket.getaddrinfo('localhost', 80) |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1161 except socket.gaierror as err: |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1162 if err.errno == socket.EAI_SERVICE: |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1163 # see http://bugs.python.org/issue1282647 |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1164 self.skipTest("buggy libc version") |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1165 raise |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1166 # len of every sequence is supposed to be == 5 |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1167 for info in socket.getaddrinfo(HOST, None): |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1168 self.assertEqual(len(info), 5) |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1169 # host can be a domain name, a string representation of an |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1170 # IPv4/v6 address or None |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1171 socket.getaddrinfo('localhost', 80) |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1172 socket.getaddrinfo('127.0.0.1', 80) |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1173 socket.getaddrinfo(None, 80) |
|
69672
0518f32cb747
Issue #11811: Factor out detection of IPv6 support on the current host
Antoine Pitrou <solipsis@pitrou.net>
parents:
69123
diff
changeset
|
1174 if support.IPV6_ENABLED: |
|
64000
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1175 socket.getaddrinfo('::1', 80) |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1176 # port can be a string service name such as "http", a numeric |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1177 # port number or None |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1178 socket.getaddrinfo(HOST, "http") |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1179 socket.getaddrinfo(HOST, 80) |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1180 socket.getaddrinfo(HOST, None) |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1181 # test family and socktype filters |
|
85481
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1182 infos = socket.getaddrinfo(HOST, 80, socket.AF_INET, socket.SOCK_STREAM) |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1183 for family, type, _, _, _ in infos: |
|
64000
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1184 self.assertEqual(family, socket.AF_INET) |
|
85481
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1185 self.assertEqual(str(family), 'AddressFamily.AF_INET') |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1186 self.assertEqual(type, socket.SOCK_STREAM) |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1187 self.assertEqual(str(type), 'SocketType.SOCK_STREAM') |
|
64000
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1188 infos = socket.getaddrinfo(HOST, None, 0, socket.SOCK_STREAM) |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1189 for _, socktype, _, _, _ in infos: |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1190 self.assertEqual(socktype, socket.SOCK_STREAM) |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1191 # test proto and flags arguments |
|
64060
bf18dd70c180
Merged revisions 84089 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64000
diff
changeset
|
1192 socket.getaddrinfo(HOST, None, 0, 0, socket.SOL_TCP) |
|
64000
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1193 socket.getaddrinfo(HOST, None, 0, 0, 0, socket.AI_PASSIVE) |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1194 # a server willing to support both IPv4 and IPv6 will |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1195 # usually do this |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1196 socket.getaddrinfo(None, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, |
|
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1197 socket.AI_PASSIVE) |
|
64113
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1198 # test keyword arguments |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1199 a = socket.getaddrinfo(HOST, None) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1200 b = socket.getaddrinfo(host=HOST, port=None) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1201 self.assertEqual(a, b) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1202 a = socket.getaddrinfo(HOST, None, socket.AF_INET) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1203 b = socket.getaddrinfo(HOST, None, family=socket.AF_INET) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1204 self.assertEqual(a, b) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1205 a = socket.getaddrinfo(HOST, None, 0, socket.SOCK_STREAM) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1206 b = socket.getaddrinfo(HOST, None, type=socket.SOCK_STREAM) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1207 self.assertEqual(a, b) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1208 a = socket.getaddrinfo(HOST, None, 0, 0, socket.SOL_TCP) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1209 b = socket.getaddrinfo(HOST, None, proto=socket.SOL_TCP) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1210 self.assertEqual(a, b) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1211 a = socket.getaddrinfo(HOST, None, 0, 0, 0, socket.AI_PASSIVE) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1212 b = socket.getaddrinfo(HOST, None, flags=socket.AI_PASSIVE) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1213 self.assertEqual(a, b) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1214 a = socket.getaddrinfo(None, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1215 socket.AI_PASSIVE) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1216 b = socket.getaddrinfo(host=None, port=0, family=socket.AF_UNSPEC, |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1217 type=socket.SOCK_STREAM, proto=0, |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1218 flags=socket.AI_PASSIVE) |
|
ca2a859e9bf6
fix issue #8866: parameters passed to socket.getaddrinfo can now be specified as single keyword arguments.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64059
diff
changeset
|
1219 self.assertEqual(a, b) |
|
66799
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66310
diff
changeset
|
1220 # Issue #6697. |
|
50d170bb71c7
Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents:
66310
diff
changeset
|
1221 self.assertRaises(UnicodeEncodeError, socket.getaddrinfo, 'localhost', '\uD800') |
|
64000
9bd082701776
Merged revisions 84024 via svnmerge from
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
56368
diff
changeset
|
1222 |
|
83907
3c4a5dc29417
Issue #17269: Workaround for a platform bug in getaddrinfo on OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
82619
diff
changeset
|
1223 # Issue 17269 |
|
84075
ef103e7e7af2
Ensure that the fix for #17269 also works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
83907
diff
changeset
|
1224 if hasattr(socket, 'AI_NUMERICSERV'): |
|
ef103e7e7af2
Ensure that the fix for #17269 also works on OSX 10.4
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
83907
diff
changeset
|
1225 socket.getaddrinfo("localhost", None, 0, 0, 0, socket.AI_NUMERICSERV) |
|
83907
3c4a5dc29417
Issue #17269: Workaround for a platform bug in getaddrinfo on OSX
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
82619
diff
changeset
|
1226 |
|
64277
2ccd043aad5c
Issue #1027206: getnameinfo is now restricted to numeric addresses as input.
Martin v. Löwis <martin@v.loewis.de>
parents:
64241
diff
changeset
|
1227 def test_getnameinfo(self): |
|
2ccd043aad5c
Issue #1027206: getnameinfo is now restricted to numeric addresses as input.
Martin v. Löwis <martin@v.loewis.de>
parents:
64241
diff
changeset
|
1228 # only IP addresses are allowed |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
1229 self.assertRaises(OSError, socket.getnameinfo, ('mail.python.org',0), 0) |
|
64277
2ccd043aad5c
Issue #1027206: getnameinfo is now restricted to numeric addresses as input.
Martin v. Löwis <martin@v.loewis.de>
parents:
64241
diff
changeset
|
1230 |
|
64593
6f14f02359e8
Skip socket tests that require the network, if the network resource is not enabled
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents:
64574
diff
changeset
|
1231 @unittest.skipUnless(support.is_resource_enabled('network'), |
|
6f14f02359e8
Skip socket tests that require the network, if the network resource is not enabled
Daniel Stutzbach <daniel@stutzbachenterprises.com>
parents:
64574
diff
changeset
|
1232 'network is not enabled') |
|
64230
35304c2fe9e0
Issue #1027206: Support IDNA in gethostbyname, gethostbyname_ex and
Martin v. Löwis <martin@v.loewis.de>
parents:
64113
diff
changeset
|
1233 def test_idna(self): |
|
74607
585d3664da89
Issue #12804: Fix test failures on systems without internet access.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
74606
diff
changeset
|
1234 # Check for internet access before running test (issue #12804). |
|
585d3664da89
Issue #12804: Fix test failures on systems without internet access.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
74606
diff
changeset
|
1235 try: |
|
585d3664da89
Issue #12804: Fix test failures on systems without internet access.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
74606
diff
changeset
|
1236 socket.gethostbyname('python.org') |
|
585d3664da89
Issue #12804: Fix test failures on systems without internet access.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
74606
diff
changeset
|
1237 except socket.gaierror as e: |
|
585d3664da89
Issue #12804: Fix test failures on systems without internet access.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
74606
diff
changeset
|
1238 if e.errno == socket.EAI_NODATA: |
|
585d3664da89
Issue #12804: Fix test failures on systems without internet access.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
74606
diff
changeset
|
1239 self.skipTest('internet access required for this test') |
|
64230
35304c2fe9e0
Issue #1027206: Support IDNA in gethostbyname, gethostbyname_ex and
Martin v. Löwis <martin@v.loewis.de>
parents:
64113
diff
changeset
|
1240 # these should all be successful |
|
35304c2fe9e0
Issue #1027206: Support IDNA in gethostbyname, gethostbyname_ex and
Martin v. Löwis <martin@v.loewis.de>
parents:
64113
diff
changeset
|
1241 socket.gethostbyname('испытание.python.org') |
|
35304c2fe9e0
Issue #1027206: Support IDNA in gethostbyname, gethostbyname_ex and
Martin v. Löwis <martin@v.loewis.de>
parents:
64113
diff
changeset
|
1242 socket.gethostbyname_ex('испытание.python.org') |
|
64241
7e1e343b708b
Explicitly pass socket type and family for getaddrinfo,
Martin v. Löwis <martin@v.loewis.de>
parents:
64231
diff
changeset
|
1243 socket.getaddrinfo('испытание.python.org',0,socket.AF_UNSPEC,socket.SOCK_STREAM) |
|
7e1e343b708b
Explicitly pass socket type and family for getaddrinfo,
Martin v. Löwis <martin@v.loewis.de>
parents:
64231
diff
changeset
|
1244 # this may not work if the forward lookup choses the IPv6 address, as that doesn't |
|
7e1e343b708b
Explicitly pass socket type and family for getaddrinfo,
Martin v. Löwis <martin@v.loewis.de>
parents:
64231
diff
changeset
|
1245 # have a reverse entry yet |
|
7e1e343b708b
Explicitly pass socket type and family for getaddrinfo,
Martin v. Löwis <martin@v.loewis.de>
parents:
64231
diff
changeset
|
1246 # socket.gethostbyaddr('испытание.python.org') |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
43954
diff
changeset
|
1247 |
|
64961
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1248 def check_sendall_interrupted(self, with_timeout): |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1249 # socketpair() is not stricly required, but it makes things easier. |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1250 if not hasattr(signal, 'alarm') or not hasattr(socket, 'socketpair'): |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1251 self.skipTest("signal.alarm and socket.socketpair required for this test") |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1252 # Our signal handlers clobber the C errno by calling a math function |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1253 # with an invalid domain value. |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1254 def ok_handler(*args): |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1255 self.assertRaises(ValueError, math.acosh, 0) |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1256 def raising_handler(*args): |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1257 self.assertRaises(ValueError, math.acosh, 0) |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1258 1 // 0 |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1259 c, s = socket.socketpair() |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1260 old_alarm = signal.signal(signal.SIGALRM, raising_handler) |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1261 try: |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1262 if with_timeout: |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1263 # Just above the one second minimum for signal.alarm |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1264 c.settimeout(1.5) |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1265 with self.assertRaises(ZeroDivisionError): |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1266 signal.alarm(1) |
|
85450
498957c97c2b
Issue #18643: Fix some test_socket failures due to large default socket buffer
Charles-François Natali <cf.natali@gmail.com>
parents:
85360
diff
changeset
|
1267 c.sendall(b"x" * support.SOCK_MAX_SIZE) |
|
64961
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1268 if with_timeout: |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1269 signal.signal(signal.SIGALRM, ok_handler) |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1270 signal.alarm(1) |
|
85450
498957c97c2b
Issue #18643: Fix some test_socket failures due to large default socket buffer
Charles-François Natali <cf.natali@gmail.com>
parents:
85360
diff
changeset
|
1271 self.assertRaises(socket.timeout, c.sendall, |
|
498957c97c2b
Issue #18643: Fix some test_socket failures due to large default socket buffer
Charles-François Natali <cf.natali@gmail.com>
parents:
85360
diff
changeset
|
1272 b"x" * support.SOCK_MAX_SIZE) |
|
64961
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1273 finally: |
|
85360
75728ef3d0c9
test_socket: cancel scheduled alarm on test failure
Victor Stinner <victor.stinner@gmail.com>
parents:
85019
diff
changeset
|
1274 signal.alarm(0) |
|
64961
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1275 signal.signal(signal.SIGALRM, old_alarm) |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1276 c.close() |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1277 s.close() |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1278 |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1279 def test_sendall_interrupted(self): |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1280 self.check_sendall_interrupted(False) |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1281 |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1282 def test_sendall_interrupted_with_timeout(self): |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1283 self.check_sendall_interrupted(True) |
|
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1284 |
|
65707
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1285 def test_dealloc_warn(self): |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1286 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1287 r = repr(sock) |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1288 with self.assertWarns(ResourceWarning) as cm: |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1289 sock = None |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1290 support.gc_collect() |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1291 self.assertIn(r, str(cm.warning.args[0])) |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1292 # An open socket file object gets dereferenced after the socket |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1293 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1294 f = sock.makefile('rb') |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1295 r = repr(sock) |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1296 sock = None |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1297 support.gc_collect() |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1298 with self.assertWarns(ResourceWarning): |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1299 f = None |
|
cff78ffb932a
Issue #10093: ResourceWarnings are now issued when files and sockets are
Antoine Pitrou <solipsis@pitrou.net>
parents:
65606
diff
changeset
|
1300 support.gc_collect() |
|
64961
5a7bb85a5d99
Merged revisions 85032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64536
diff
changeset
|
1301 |
|
67344
f4a808f5a66d
Issue #10819: SocketIO.name property returns -1 when its closed, instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67299
diff
changeset
|
1302 def test_name_closed_socketio(self): |
|
f4a808f5a66d
Issue #10819: SocketIO.name property returns -1 when its closed, instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67299
diff
changeset
|
1303 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: |
|
f4a808f5a66d
Issue #10819: SocketIO.name property returns -1 when its closed, instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67299
diff
changeset
|
1304 fp = sock.makefile("rb") |
|
f4a808f5a66d
Issue #10819: SocketIO.name property returns -1 when its closed, instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67299
diff
changeset
|
1305 fp.close() |
|
f4a808f5a66d
Issue #10819: SocketIO.name property returns -1 when its closed, instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67299
diff
changeset
|
1306 self.assertEqual(repr(fp), "<_io.BufferedReader name=-1>") |
|
f4a808f5a66d
Issue #10819: SocketIO.name property returns -1 when its closed, instead of
Victor Stinner <victor.stinner@haypocalc.com>
parents:
67299
diff
changeset
|
1307 |
|
79026
fad797916266
Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76033
diff
changeset
|
1308 def test_unusable_closed_socketio(self): |
|
fad797916266
Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76033
diff
changeset
|
1309 with socket.socket() as sock: |
|
fad797916266
Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76033
diff
changeset
|
1310 fp = sock.makefile("rb", buffering=0) |
|
fad797916266
Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76033
diff
changeset
|
1311 self.assertTrue(fp.readable()) |
|
fad797916266
Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76033
diff
changeset
|
1312 self.assertFalse(fp.writable()) |
|
fad797916266
Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76033
diff
changeset
|
1313 self.assertFalse(fp.seekable()) |
|
fad797916266
Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76033
diff
changeset
|
1314 fp.close() |
|
fad797916266
Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76033
diff
changeset
|
1315 self.assertRaises(ValueError, fp.readable) |
|
fad797916266
Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76033
diff
changeset
|
1316 self.assertRaises(ValueError, fp.writable) |
|
fad797916266
Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76033
diff
changeset
|
1317 self.assertRaises(ValueError, fp.seekable) |
|
fad797916266
Issue #15842: the SocketIO.{readable,writable,seekable} methods now raise ValueError when the file-like object is closed.
Antoine Pitrou <solipsis@pitrou.net>
parents:
76033
diff
changeset
|
1318 |
|
68774
5e13e5e6df30
Issue #11127: Raise a TypeError when trying to pickle a socket object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68258
diff
changeset
|
1319 def test_pickle(self): |
|
5e13e5e6df30
Issue #11127: Raise a TypeError when trying to pickle a socket object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68258
diff
changeset
|
1320 sock = socket.socket() |
|
5e13e5e6df30
Issue #11127: Raise a TypeError when trying to pickle a socket object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68258
diff
changeset
|
1321 with sock: |
|
5e13e5e6df30
Issue #11127: Raise a TypeError when trying to pickle a socket object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68258
diff
changeset
|
1322 for protocol in range(pickle.HIGHEST_PROTOCOL + 1): |
|
5e13e5e6df30
Issue #11127: Raise a TypeError when trying to pickle a socket object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68258
diff
changeset
|
1323 self.assertRaises(TypeError, pickle.dumps, sock, protocol) |
|
5e13e5e6df30
Issue #11127: Raise a TypeError when trying to pickle a socket object.
Antoine Pitrou <solipsis@pitrou.net>
parents:
68258
diff
changeset
|
1324 |
|
81587
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1325 def test_listen_backlog(self): |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1326 for backlog in 0, -1: |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1327 srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1328 srv.bind((HOST, 0)) |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1329 srv.listen(backlog) |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1330 srv.close() |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1331 |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1332 # Issue 15989 |
|
70012
713006ecee0c
Issue #8498: In socket.accept(), allow to specify 0 as a backlog value in
Antoine Pitrou <solipsis@pitrou.net>
parents:
69917
diff
changeset
|
1333 srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
713006ecee0c
Issue #8498: In socket.accept(), allow to specify 0 as a backlog value in
Antoine Pitrou <solipsis@pitrou.net>
parents:
69917
diff
changeset
|
1334 srv.bind((HOST, 0)) |
|
81587
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1335 self.assertRaises(OverflowError, srv.listen, _testcapi.INT_MAX + 1) |
|
70012
713006ecee0c
Issue #8498: In socket.accept(), allow to specify 0 as a backlog value in
Antoine Pitrou <solipsis@pitrou.net>
parents:
69917
diff
changeset
|
1336 srv.close() |
|
713006ecee0c
Issue #8498: In socket.accept(), allow to specify 0 as a backlog value in
Antoine Pitrou <solipsis@pitrou.net>
parents:
69917
diff
changeset
|
1337 |
|
74234
9222b8e7a7bc
Issue #9975: socket: Fix incorrect use of flowinfo and scope_id. Patch by
Charles-François Natali <neologix@free.fr>
diff
changeset
|
1338 @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.') |
|
74233
cc346a672091
Issue #9975: socket: Fix incorrect use of flowinfo and scope_id. Patch by
Charles-François Natali <neologix@free.fr>
parents:
74082
diff
changeset
|
1339 def test_flowinfo(self): |
|
cc346a672091
Issue #9975: socket: Fix incorrect use of flowinfo and scope_id. Patch by
Charles-François Natali <neologix@free.fr>
parents:
74082
diff
changeset
|
1340 self.assertRaises(OverflowError, socket.getnameinfo, |
|
85470
f20201db7592
Use the recent support.HOSTv6 addition.
Charles-François Natali <cf.natali@gmail.com>
parents:
85454
diff
changeset
|
1341 (support.HOSTv6, 0, 0xffffffff), 0) |
|
74233
cc346a672091
Issue #9975: socket: Fix incorrect use of flowinfo and scope_id. Patch by
Charles-François Natali <neologix@free.fr>
parents:
74082
diff
changeset
|
1342 with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s: |
|
85470
f20201db7592
Use the recent support.HOSTv6 addition.
Charles-François Natali <cf.natali@gmail.com>
parents:
85454
diff
changeset
|
1343 self.assertRaises(OverflowError, s.bind, (support.HOSTv6, 0, -10)) |
|
74233
cc346a672091
Issue #9975: socket: Fix incorrect use of flowinfo and scope_id. Patch by
Charles-François Natali <neologix@free.fr>
parents:
74082
diff
changeset
|
1344 |
|
85481
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1345 def test_str_for_enums(self): |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1346 # Make sure that the AF_* and SOCK_* constants have enum-like string |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1347 # reprs. |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1348 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1349 self.assertEqual(str(s.family), 'AddressFamily.AF_INET') |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1350 self.assertEqual(str(s.type), 'SocketType.SOCK_STREAM') |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1351 |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1352 @unittest.skipIf(os.name == 'nt', 'Will not work on Windows') |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1353 def test_uknown_socket_family_repr(self): |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1354 # Test that when created with a family that's not one of the known |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1355 # AF_*/SOCK_* constants, socket.family just returns the number. |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1356 # |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1357 # To do this we fool socket.socket into believing it already has an |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1358 # open fd because on this path it doesn't actually verify the family and |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1359 # type and populates the socket object. |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1360 # |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1361 # On Windows this trick won't work, so the test is skipped. |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1362 fd, _ = tempfile.mkstemp() |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1363 with socket.socket(family=42424, type=13331, fileno=fd) as s: |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1364 self.assertEqual(s.family, 42424) |
|
038543d34166
Switch the AF_* and SOCK_* constants in the socket module to IntEnum.
Eli Bendersky <eliben@gmail.com>
parents:
85470
diff
changeset
|
1365 self.assertEqual(s.type, 13331) |
|
64959
aed04b3f0fe3
Issue #9950: Fix socket.sendall() crash or misbehaviour when a signal is
Antoine Pitrou <solipsis@pitrou.net>
parents:
64817
diff
changeset
|
1366 |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1367 @unittest.skipUnless(HAVE_SOCKET_CAN, 'SocketCan required for this test.') |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1368 class BasicCANTest(unittest.TestCase): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1369 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1370 def testCrucialConstants(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1371 socket.AF_CAN |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1372 socket.PF_CAN |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1373 socket.CAN_RAW |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1374 |
|
82024
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1375 @unittest.skipUnless(hasattr(socket, "CAN_BCM"), |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1376 'socket.CAN_BCM required for this test.') |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1377 def testBCMConstants(self): |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1378 socket.CAN_BCM |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1379 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1380 # opcodes |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1381 socket.CAN_BCM_TX_SETUP # create (cyclic) transmission task |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1382 socket.CAN_BCM_TX_DELETE # remove (cyclic) transmission task |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1383 socket.CAN_BCM_TX_READ # read properties of (cyclic) transmission task |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1384 socket.CAN_BCM_TX_SEND # send one CAN frame |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1385 socket.CAN_BCM_RX_SETUP # create RX content filter subscription |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1386 socket.CAN_BCM_RX_DELETE # remove RX content filter subscription |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1387 socket.CAN_BCM_RX_READ # read properties of RX content filter subscription |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1388 socket.CAN_BCM_TX_STATUS # reply to TX_READ request |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1389 socket.CAN_BCM_TX_EXPIRED # notification on performed transmissions (count=0) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1390 socket.CAN_BCM_RX_STATUS # reply to RX_READ request |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1391 socket.CAN_BCM_RX_TIMEOUT # cyclic message is absent |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1392 socket.CAN_BCM_RX_CHANGED # updated CAN frame (detected content change) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1393 |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1394 def testCreateSocket(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1395 with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1396 pass |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1397 |
|
82024
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1398 @unittest.skipUnless(hasattr(socket, "CAN_BCM"), |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1399 'socket.CAN_BCM required for this test.') |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1400 def testCreateBCMSocket(self): |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1401 with socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_BCM) as s: |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1402 pass |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1403 |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1404 def testBindAny(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1405 with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1406 s.bind(('', )) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1407 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1408 def testTooLongInterfaceName(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1409 # most systems limit IFNAMSIZ to 16, take 1024 to be sure |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1410 with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
1411 self.assertRaisesRegex(OSError, 'interface name too long', |
|
72870
e2cb12decd9f
Fix deprecation warning
Antoine Pitrou <solipsis@pitrou.net>
parents:
72849
diff
changeset
|
1412 s.bind, ('x' * 1024,)) |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1413 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1414 @unittest.skipUnless(hasattr(socket, "CAN_RAW_LOOPBACK"), |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1415 'socket.CAN_RAW_LOOPBACK required for this test.') |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1416 def testLoopback(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1417 with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1418 for loopback in (0, 1): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1419 s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_LOOPBACK, |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1420 loopback) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1421 self.assertEqual(loopback, |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1422 s.getsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_LOOPBACK)) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1423 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1424 @unittest.skipUnless(hasattr(socket, "CAN_RAW_FILTER"), |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1425 'socket.CAN_RAW_FILTER required for this test.') |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1426 def testFilter(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1427 can_id, can_mask = 0x200, 0x700 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1428 can_filter = struct.pack("=II", can_id, can_mask) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1429 with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s: |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1430 s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, can_filter) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1431 self.assertEqual(can_filter, |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1432 s.getsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, 8)) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1433 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1434 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1435 @unittest.skipUnless(HAVE_SOCKET_CAN, 'SocketCan required for this test.') |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1436 class CANTest(ThreadedCANSocketTest): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1437 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1438 def __init__(self, methodName='runTest'): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1439 ThreadedCANSocketTest.__init__(self, methodName=methodName) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1440 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1441 @classmethod |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1442 def build_can_frame(cls, can_id, data): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1443 """Build a CAN frame.""" |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1444 can_dlc = len(data) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1445 data = data.ljust(8, b'\x00') |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1446 return struct.pack(cls.can_frame_fmt, can_id, can_dlc, data) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1447 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1448 @classmethod |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1449 def dissect_can_frame(cls, frame): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1450 """Dissect a CAN frame.""" |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1451 can_id, can_dlc, data = struct.unpack(cls.can_frame_fmt, frame) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1452 return (can_id, can_dlc, data[:can_dlc]) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1453 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1454 def testSendFrame(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1455 cf, addr = self.s.recvfrom(self.bufsize) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1456 self.assertEqual(self.cf, cf) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1457 self.assertEqual(addr[0], self.interface) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1458 self.assertEqual(addr[1], socket.AF_CAN) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1459 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1460 def _testSendFrame(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1461 self.cf = self.build_can_frame(0x00, b'\x01\x02\x03\x04\x05') |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1462 self.cli.send(self.cf) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1463 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1464 def testSendMaxFrame(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1465 cf, addr = self.s.recvfrom(self.bufsize) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1466 self.assertEqual(self.cf, cf) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1467 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1468 def _testSendMaxFrame(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1469 self.cf = self.build_can_frame(0x00, b'\x07' * 8) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1470 self.cli.send(self.cf) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1471 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1472 def testSendMultiFrames(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1473 cf, addr = self.s.recvfrom(self.bufsize) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1474 self.assertEqual(self.cf1, cf) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1475 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1476 cf, addr = self.s.recvfrom(self.bufsize) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1477 self.assertEqual(self.cf2, cf) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1478 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1479 def _testSendMultiFrames(self): |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1480 self.cf1 = self.build_can_frame(0x07, b'\x44\x33\x22\x11') |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1481 self.cli.send(self.cf1) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1482 |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1483 self.cf2 = self.build_can_frame(0x12, b'\x99\x22\x33') |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1484 self.cli.send(self.cf2) |
|
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1485 |
|
82024
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1486 @unittest.skipUnless(hasattr(socket, "CAN_BCM"), |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1487 'socket.CAN_BCM required for this test.') |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1488 def _testBCM(self): |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1489 cf, addr = self.cli.recvfrom(self.bufsize) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1490 self.assertEqual(self.cf, cf) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1491 can_id, can_dlc, data = self.dissect_can_frame(cf) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1492 self.assertEqual(self.can_id, can_id) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1493 self.assertEqual(self.data, data) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1494 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1495 @unittest.skipUnless(hasattr(socket, "CAN_BCM"), |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1496 'socket.CAN_BCM required for this test.') |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1497 def testBCM(self): |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1498 bcm = socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_BCM) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1499 self.addCleanup(bcm.close) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1500 bcm.connect((self.interface,)) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1501 self.can_id = 0x123 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1502 self.data = bytes([0xc0, 0xff, 0xee]) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1503 self.cf = self.build_can_frame(self.can_id, self.data) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1504 opcode = socket.CAN_BCM_TX_SEND |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1505 flags = 0 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1506 count = 0 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1507 ival1_seconds = ival1_usec = ival2_seconds = ival2_usec = 0 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1508 bcm_can_id = 0x0222 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1509 nframes = 1 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1510 assert len(self.cf) == 16 |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1511 header = struct.pack(self.bcm_cmd_msg_fmt, |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1512 opcode, |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1513 flags, |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1514 count, |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1515 ival1_seconds, |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1516 ival1_usec, |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1517 ival2_seconds, |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1518 ival2_usec, |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1519 bcm_can_id, |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1520 nframes, |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1521 ) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1522 header_plus_frame = header + self.cf |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1523 bytes_sent = bcm.send(header_plus_frame) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1524 self.assertEqual(bytes_sent, len(header_plus_frame)) |
|
f714af60508d
Issue #15359: Add CAN_BCM protocol support to the socket module. Patch by Brian
Charles-François Natali <cf.natali@gmail.com>
parents:
81589
diff
changeset
|
1525 |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
1526 |
|
73478
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1527 @unittest.skipUnless(HAVE_SOCKET_RDS, 'RDS sockets required for this test.') |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1528 class BasicRDSTest(unittest.TestCase): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1529 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1530 def testCrucialConstants(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1531 socket.AF_RDS |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1532 socket.PF_RDS |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1533 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1534 def testCreateSocket(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1535 with socket.socket(socket.PF_RDS, socket.SOCK_SEQPACKET, 0) as s: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1536 pass |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1537 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1538 def testSocketBufferSize(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1539 bufsize = 16384 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1540 with socket.socket(socket.PF_RDS, socket.SOCK_SEQPACKET, 0) as s: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1541 s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, bufsize) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1542 s.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, bufsize) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1543 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1544 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1545 @unittest.skipUnless(HAVE_SOCKET_RDS, 'RDS sockets required for this test.') |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1546 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1547 class RDSTest(ThreadedRDSSocketTest): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1548 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1549 def __init__(self, methodName='runTest'): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1550 ThreadedRDSSocketTest.__init__(self, methodName=methodName) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1551 |
|
73485
fa9bbfc0bcec
Fix test_socket when built whithout threads.
Charles-François Natali <neologix@free.fr>
parents:
73478
diff
changeset
|
1552 def setUp(self): |
|
fa9bbfc0bcec
Fix test_socket when built whithout threads.
Charles-François Natali <neologix@free.fr>
parents:
73478
diff
changeset
|
1553 super().setUp() |
|
fa9bbfc0bcec
Fix test_socket when built whithout threads.
Charles-François Natali <neologix@free.fr>
parents:
73478
diff
changeset
|
1554 self.evt = threading.Event() |
|
fa9bbfc0bcec
Fix test_socket when built whithout threads.
Charles-François Natali <neologix@free.fr>
parents:
73478
diff
changeset
|
1555 |
|
73478
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1556 def testSendAndRecv(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1557 data, addr = self.serv.recvfrom(self.bufsize) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1558 self.assertEqual(self.data, data) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1559 self.assertEqual(self.cli_addr, addr) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1560 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1561 def _testSendAndRecv(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1562 self.data = b'spam' |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1563 self.cli.sendto(self.data, 0, (HOST, self.port)) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1564 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1565 def testPeek(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1566 data, addr = self.serv.recvfrom(self.bufsize, socket.MSG_PEEK) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1567 self.assertEqual(self.data, data) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1568 data, addr = self.serv.recvfrom(self.bufsize) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1569 self.assertEqual(self.data, data) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1570 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1571 def _testPeek(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1572 self.data = b'spam' |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1573 self.cli.sendto(self.data, 0, (HOST, self.port)) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1574 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1575 @requireAttrs(socket.socket, 'recvmsg') |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1576 def testSendAndRecvMsg(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1577 data, ancdata, msg_flags, addr = self.serv.recvmsg(self.bufsize) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1578 self.assertEqual(self.data, data) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1579 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1580 @requireAttrs(socket.socket, 'sendmsg') |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1581 def _testSendAndRecvMsg(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1582 self.data = b'hello ' * 10 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1583 self.cli.sendmsg([self.data], (), 0, (HOST, self.port)) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1584 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1585 def testSendAndRecvMulti(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1586 data, addr = self.serv.recvfrom(self.bufsize) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1587 self.assertEqual(self.data1, data) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1588 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1589 data, addr = self.serv.recvfrom(self.bufsize) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1590 self.assertEqual(self.data2, data) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1591 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1592 def _testSendAndRecvMulti(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1593 self.data1 = b'bacon' |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1594 self.cli.sendto(self.data1, 0, (HOST, self.port)) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1595 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1596 self.data2 = b'egg' |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1597 self.cli.sendto(self.data2, 0, (HOST, self.port)) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1598 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1599 def testSelect(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1600 r, w, x = select.select([self.serv], [], [], 3.0) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1601 self.assertIn(self.serv, r) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1602 data, addr = self.serv.recvfrom(self.bufsize) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1603 self.assertEqual(self.data, data) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1604 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1605 def _testSelect(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1606 self.data = b'select' |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1607 self.cli.sendto(self.data, 0, (HOST, self.port)) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1608 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1609 def testCongestion(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1610 # wait until the sender is done |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1611 self.evt.wait() |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1612 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1613 def _testCongestion(self): |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1614 # test the behavior in case of congestion |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1615 self.data = b'fill' |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1616 self.cli.setblocking(False) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1617 try: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1618 # try to lower the receiver's socket buffer size |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1619 self.cli.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 16384) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1620 except OSError: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1621 pass |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1622 with self.assertRaises(OSError) as cm: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1623 try: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1624 # fill the receiver's socket buffer |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1625 while True: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1626 self.cli.sendto(self.data, 0, (HOST, self.port)) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1627 finally: |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1628 # signal the receiver we're done |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1629 self.evt.set() |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1630 # sendto() should have failed with ENOBUFS |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1631 self.assertEqual(cm.exception.errno, errno.ENOBUFS) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1632 # and we should have received a congestion notification through poll |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1633 r, w, x = select.select([self.serv], [], [], 3.0) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1634 self.assertIn(self.serv, r) |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1635 |
|
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
1636 |
|
61073
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
1637 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1638 class BasicTCPTest(SocketConnectedTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1639 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1640 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1641 SocketConnectedTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1642 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1643 def testRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1644 # Testing large receive over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1645 msg = self.cli_conn.recv(1024) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
1646 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1647 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1648 def _testRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1649 self.serv_conn.send(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1650 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1651 def testOverFlowRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1652 # Testing receive in chunks over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1653 seg1 = self.cli_conn.recv(len(MSG) - 3) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1654 seg2 = self.cli_conn.recv(1024) |
|
23800
bf1555a92711
Remove some overly complicated ways to concatenate and repeat strings
Guido van Rossum <guido@python.org>
parents:
23799
diff
changeset
|
1655 msg = seg1 + seg2 |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
1656 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1657 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1658 def _testOverFlowRecv(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1659 self.serv_conn.send(MSG) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1660 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1661 def testRecvFrom(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1662 # Testing large recvfrom() over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1663 msg, addr = self.cli_conn.recvfrom(1024) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
1664 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1665 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1666 def _testRecvFrom(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1667 self.serv_conn.send(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1668 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1669 def testOverFlowRecvFrom(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1670 # Testing recvfrom() in chunks over TCP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1671 seg1, addr = self.cli_conn.recvfrom(len(MSG)-3) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1672 seg2, addr = self.cli_conn.recvfrom(1024) |
|
23800
bf1555a92711
Remove some overly complicated ways to concatenate and repeat strings
Guido van Rossum <guido@python.org>
parents:
23799
diff
changeset
|
1673 msg = seg1 + seg2 |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
1674 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1675 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1676 def _testOverFlowRecvFrom(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1677 self.serv_conn.send(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1678 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1679 def testSendAll(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1680 # Testing sendall() with a 2048 byte string over TCP |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
1681 msg = b'' |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1682 while 1: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1683 read = self.cli_conn.recv(1024) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1684 if not read: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1685 break |
|
24675
fec0b0aef14b
testSendAll(): loop until all data is read; this was necessary at
Guido van Rossum <guido@python.org>
parents:
24674
diff
changeset
|
1686 msg += read |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
1687 self.assertEqual(msg, b'f' * 2048) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1688 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1689 def _testSendAll(self): |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
1690 big_chunk = b'f' * 2048 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1691 self.serv_conn.sendall(big_chunk) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1692 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1693 def testFromFd(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1694 # Testing fromfd() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1695 fd = self.cli_conn.fileno() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1696 sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
1697 self.addCleanup(sock.close) |
|
64747
534853ba8cd3
Issue #1552: socket.socketpair() now returns regular socket.socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
64593
diff
changeset
|
1698 self.assertIsInstance(sock, socket.socket) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1699 msg = sock.recv(1024) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
1700 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1701 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1702 def _testFromFd(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1703 self.serv_conn.send(MSG) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1704 |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43734
diff
changeset
|
1705 def testDup(self): |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43734
diff
changeset
|
1706 # Testing dup() |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43734
diff
changeset
|
1707 sock = self.cli_conn.dup() |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
1708 self.addCleanup(sock.close) |
|
43881
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43734
diff
changeset
|
1709 msg = sock.recv(1024) |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43734
diff
changeset
|
1710 self.assertEqual(msg, MSG) |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43734
diff
changeset
|
1711 |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43734
diff
changeset
|
1712 def _testDup(self): |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43734
diff
changeset
|
1713 self.serv_conn.send(MSG) |
|
70cfc7b504c2
This is roughly socket2.diff from issue 1378, with a few changes applied
Guido van Rossum <guido@python.org>
parents:
43734
diff
changeset
|
1714 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1715 def testShutdown(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1716 # Testing shutdown() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1717 msg = self.cli_conn.recv(1024) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
1718 self.assertEqual(msg, MSG) |
|
50800
b17ec4c4a7c3
Merged revisions 68611-68613 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50741
diff
changeset
|
1719 # wait for _testShutdown to finish: on OS X, when the server |
|
b17ec4c4a7c3
Merged revisions 68611-68613 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50741
diff
changeset
|
1720 # closes the connection the client also becomes disconnected, |
|
b17ec4c4a7c3
Merged revisions 68611-68613 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50741
diff
changeset
|
1721 # and the client's shutdown call will fail. (Issue #4397.) |
|
b17ec4c4a7c3
Merged revisions 68611-68613 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50741
diff
changeset
|
1722 self.done.wait() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1723 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1724 def _testShutdown(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1725 self.serv_conn.send(MSG) |
|
81587
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1726 # Issue 15989 |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1727 self.assertRaises(OverflowError, self.serv_conn.shutdown, |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1728 _testcapi.INT_MAX + 1) |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1729 self.assertRaises(OverflowError, self.serv_conn.shutdown, |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
1730 2 + (_testcapi.UINT_MAX + 1)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1731 self.serv_conn.shutdown(2) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1732 |
|
63890
60076f28c023
Followup to r83869 and issue #8524: rename socket.forget() to socket.detach()
Antoine Pitrou <solipsis@pitrou.net>
parents:
63856
diff
changeset
|
1733 def testDetach(self): |
|
60076f28c023
Followup to r83869 and issue #8524: rename socket.forget() to socket.detach()
Antoine Pitrou <solipsis@pitrou.net>
parents:
63856
diff
changeset
|
1734 # Testing detach() |
|
60076f28c023
Followup to r83869 and issue #8524: rename socket.forget() to socket.detach()
Antoine Pitrou <solipsis@pitrou.net>
parents:
63856
diff
changeset
|
1735 fileno = self.cli_conn.fileno() |
|
60076f28c023
Followup to r83869 and issue #8524: rename socket.forget() to socket.detach()
Antoine Pitrou <solipsis@pitrou.net>
parents:
63856
diff
changeset
|
1736 f = self.cli_conn.detach() |
|
60076f28c023
Followup to r83869 and issue #8524: rename socket.forget() to socket.detach()
Antoine Pitrou <solipsis@pitrou.net>
parents:
63856
diff
changeset
|
1737 self.assertEqual(f, fileno) |
|
60076f28c023
Followup to r83869 and issue #8524: rename socket.forget() to socket.detach()
Antoine Pitrou <solipsis@pitrou.net>
parents:
63856
diff
changeset
|
1738 # cli_conn cannot be used anymore... |
|
76033
3a220feafa15
Issue #13872: socket.detach() now marks the socket closed (as mirrored in the socket repr()).
Antoine Pitrou <solipsis@pitrou.net>
parents:
74233
diff
changeset
|
1739 self.assertTrue(self.cli_conn._closed) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
1740 self.assertRaises(OSError, self.cli_conn.recv, 1024) |
|
63856
3f8cef837f07
Issue #8524: Add a forget() method to socket objects, so as to put the
Antoine Pitrou <solipsis@pitrou.net>
parents:
61259
diff
changeset
|
1741 self.cli_conn.close() |
|
63890
60076f28c023
Followup to r83869 and issue #8524: rename socket.forget() to socket.detach()
Antoine Pitrou <solipsis@pitrou.net>
parents:
63856
diff
changeset
|
1742 # ...but we can create another socket using the (still open) |
|
60076f28c023
Followup to r83869 and issue #8524: rename socket.forget() to socket.detach()
Antoine Pitrou <solipsis@pitrou.net>
parents:
63856
diff
changeset
|
1743 # file descriptor |
|
63856
3f8cef837f07
Issue #8524: Add a forget() method to socket objects, so as to put the
Antoine Pitrou <solipsis@pitrou.net>
parents:
61259
diff
changeset
|
1744 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, fileno=f) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
1745 self.addCleanup(sock.close) |
|
63856
3f8cef837f07
Issue #8524: Add a forget() method to socket objects, so as to put the
Antoine Pitrou <solipsis@pitrou.net>
parents:
61259
diff
changeset
|
1746 msg = sock.recv(1024) |
|
3f8cef837f07
Issue #8524: Add a forget() method to socket objects, so as to put the
Antoine Pitrou <solipsis@pitrou.net>
parents:
61259
diff
changeset
|
1747 self.assertEqual(msg, MSG) |
|
3f8cef837f07
Issue #8524: Add a forget() method to socket objects, so as to put the
Antoine Pitrou <solipsis@pitrou.net>
parents:
61259
diff
changeset
|
1748 |
|
63890
60076f28c023
Followup to r83869 and issue #8524: rename socket.forget() to socket.detach()
Antoine Pitrou <solipsis@pitrou.net>
parents:
63856
diff
changeset
|
1749 def _testDetach(self): |
|
63856
3f8cef837f07
Issue #8524: Add a forget() method to socket objects, so as to put the
Antoine Pitrou <solipsis@pitrou.net>
parents:
61259
diff
changeset
|
1750 self.serv_conn.send(MSG) |
|
3f8cef837f07
Issue #8524: Add a forget() method to socket objects, so as to put the
Antoine Pitrou <solipsis@pitrou.net>
parents:
61259
diff
changeset
|
1751 |
|
61073
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
1752 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1753 class BasicUDPTest(ThreadedUDPSocketTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1754 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1755 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1756 ThreadedUDPSocketTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1757 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1758 def testSendtoAndRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1759 # Testing sendto() and Recv() over UDP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1760 msg = self.serv.recv(len(MSG)) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
1761 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1762 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1763 def _testSendtoAndRecv(self): |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
1764 self.cli.sendto(MSG, 0, (HOST, self.port)) |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
1765 |
|
23798
1da6d67f4a05
Some provisional changes to get more tests to run on Windows (I hope).
Guido van Rossum <guido@python.org>
parents:
23797
diff
changeset
|
1766 def testRecvFrom(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
1767 # Testing recvfrom() over UDP |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1768 msg, addr = self.serv.recvfrom(len(MSG)) |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
1769 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1770 |
|
23798
1da6d67f4a05
Some provisional changes to get more tests to run on Windows (I hope).
Guido van Rossum <guido@python.org>
parents:
23797
diff
changeset
|
1771 def _testRecvFrom(self): |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
1772 self.cli.sendto(MSG, 0, (HOST, self.port)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
1773 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1774 def testRecvFromNegative(self): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1775 # Negative lengths passed to recvfrom should give ValueError. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1776 self.assertRaises(ValueError, self.serv.recvfrom, -1) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1777 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1778 def _testRecvFromNegative(self): |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
1779 self.cli.sendto(MSG, 0, (HOST, self.port)) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1780 |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1781 # Tests for the sendmsg()/recvmsg() interface. Where possible, the |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1782 # same test code is used with different families and types of socket |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1783 # (e.g. stream, datagram), and tests using recvmsg() are repeated |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1784 # using recvmsg_into(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1785 # |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1786 # The generic test classes such as SendmsgTests and |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1787 # RecvmsgGenericTests inherit from SendrecvmsgBase and expect to be |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1788 # supplied with sockets cli_sock and serv_sock representing the |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1789 # client's and the server's end of the connection respectively, and |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1790 # attributes cli_addr and serv_addr holding their (numeric where |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1791 # appropriate) addresses. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1792 # |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1793 # The final concrete test classes combine these with subclasses of |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1794 # SocketTestBase which set up client and server sockets of a specific |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1795 # type, and with subclasses of SendrecvmsgBase such as |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1796 # SendrecvmsgDgramBase and SendrecvmsgConnectedBase which map these |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1797 # sockets to cli_sock and serv_sock and override the methods and |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1798 # attributes of SendrecvmsgBase to fill in destination addresses if |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1799 # needed when sending, check for specific flags in msg_flags, etc. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1800 # |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1801 # RecvmsgIntoMixin provides a version of doRecvmsg() implemented using |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1802 # recvmsg_into(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1803 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1804 # XXX: like the other datagram (UDP) tests in this module, the code |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1805 # here assumes that datagram delivery on the local machine will be |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1806 # reliable. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1807 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1808 class SendrecvmsgBase(ThreadSafeCleanupTestCase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1809 # Base class for sendmsg()/recvmsg() tests. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1810 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1811 # Time in seconds to wait before considering a test failed, or |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1812 # None for no timeout. Not all tests actually set a timeout. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1813 fail_timeout = 3.0 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1814 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1815 def setUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1816 self.misc_event = threading.Event() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1817 super().setUp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1818 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1819 def sendToServer(self, msg): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1820 # Send msg to the server. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1821 return self.cli_sock.send(msg) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1822 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1823 # Tuple of alternative default arguments for sendmsg() when called |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1824 # via sendmsgToServer() (e.g. to include a destination address). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1825 sendmsg_to_server_defaults = () |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1826 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1827 def sendmsgToServer(self, *args): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1828 # Call sendmsg() on self.cli_sock with the given arguments, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1829 # filling in any arguments which are not supplied with the |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1830 # corresponding items of self.sendmsg_to_server_defaults, if |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1831 # any. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1832 return self.cli_sock.sendmsg( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1833 *(args + self.sendmsg_to_server_defaults[len(args):])) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1834 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1835 def doRecvmsg(self, sock, bufsize, *args): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1836 # Call recvmsg() on sock with given arguments and return its |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1837 # result. Should be used for tests which can use either |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1838 # recvmsg() or recvmsg_into() - RecvmsgIntoMixin overrides |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1839 # this method with one which emulates it using recvmsg_into(), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1840 # thus allowing the same test to be used for both methods. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1841 result = sock.recvmsg(bufsize, *args) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1842 self.registerRecvmsgResult(result) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1843 return result |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1844 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1845 def registerRecvmsgResult(self, result): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1846 # Called by doRecvmsg() with the return value of recvmsg() or |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1847 # recvmsg_into(). Can be overridden to arrange cleanup based |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1848 # on the returned ancillary data, for instance. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1849 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1850 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1851 def checkRecvmsgAddress(self, addr1, addr2): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1852 # Called to compare the received address with the address of |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1853 # the peer. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1854 self.assertEqual(addr1, addr2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1855 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1856 # Flags that are normally unset in msg_flags |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1857 msg_flags_common_unset = 0 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1858 for name in ("MSG_CTRUNC", "MSG_OOB"): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1859 msg_flags_common_unset |= getattr(socket, name, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1860 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1861 # Flags that are normally set |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1862 msg_flags_common_set = 0 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1863 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1864 # Flags set when a complete record has been received (e.g. MSG_EOR |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1865 # for SCTP) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1866 msg_flags_eor_indicator = 0 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1867 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1868 # Flags set when a complete record has not been received |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1869 # (e.g. MSG_TRUNC for datagram sockets) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1870 msg_flags_non_eor_indicator = 0 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1871 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1872 def checkFlags(self, flags, eor=None, checkset=0, checkunset=0, ignore=0): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1873 # Method to check the value of msg_flags returned by recvmsg[_into](). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1874 # |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1875 # Checks that all bits in msg_flags_common_set attribute are |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1876 # set in "flags" and all bits in msg_flags_common_unset are |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1877 # unset. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1878 # |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1879 # The "eor" argument specifies whether the flags should |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1880 # indicate that a full record (or datagram) has been received. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1881 # If "eor" is None, no checks are done; otherwise, checks |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1882 # that: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1883 # |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1884 # * if "eor" is true, all bits in msg_flags_eor_indicator are |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1885 # set and all bits in msg_flags_non_eor_indicator are unset |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1886 # |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1887 # * if "eor" is false, all bits in msg_flags_non_eor_indicator |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1888 # are set and all bits in msg_flags_eor_indicator are unset |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1889 # |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1890 # If "checkset" and/or "checkunset" are supplied, they require |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1891 # the given bits to be set or unset respectively, overriding |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1892 # what the attributes require for those bits. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1893 # |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1894 # If any bits are set in "ignore", they will not be checked, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1895 # regardless of the other inputs. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1896 # |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1897 # Will raise Exception if the inputs require a bit to be both |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1898 # set and unset, and it is not ignored. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1899 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1900 defaultset = self.msg_flags_common_set |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1901 defaultunset = self.msg_flags_common_unset |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1902 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1903 if eor: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1904 defaultset |= self.msg_flags_eor_indicator |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1905 defaultunset |= self.msg_flags_non_eor_indicator |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1906 elif eor is not None: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1907 defaultset |= self.msg_flags_non_eor_indicator |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1908 defaultunset |= self.msg_flags_eor_indicator |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1909 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1910 # Function arguments override defaults |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1911 defaultset &= ~checkunset |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1912 defaultunset &= ~checkset |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1913 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1914 # Merge arguments with remaining defaults, and check for conflicts |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1915 checkset |= defaultset |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1916 checkunset |= defaultunset |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1917 inboth = checkset & checkunset & ~ignore |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1918 if inboth: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1919 raise Exception("contradictory set, unset requirements for flags " |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1920 "{0:#x}".format(inboth)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1921 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1922 # Compare with given msg_flags value |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1923 mask = (checkset | checkunset) & ~ignore |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1924 self.assertEqual(flags & mask, checkset & mask) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1925 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1926 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1927 class RecvmsgIntoMixin(SendrecvmsgBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1928 # Mixin to implement doRecvmsg() using recvmsg_into(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1929 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1930 def doRecvmsg(self, sock, bufsize, *args): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1931 buf = bytearray(bufsize) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1932 result = sock.recvmsg_into([buf], *args) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1933 self.registerRecvmsgResult(result) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1934 self.assertGreaterEqual(result[0], 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1935 self.assertLessEqual(result[0], bufsize) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1936 return (bytes(buf[:result[0]]),) + result[1:] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1937 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1938 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1939 class SendrecvmsgDgramFlagsBase(SendrecvmsgBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1940 # Defines flags to be checked in msg_flags for datagram sockets. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1941 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1942 @property |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1943 def msg_flags_non_eor_indicator(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1944 return super().msg_flags_non_eor_indicator | socket.MSG_TRUNC |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1945 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1946 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1947 class SendrecvmsgSCTPFlagsBase(SendrecvmsgBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1948 # Defines flags to be checked in msg_flags for SCTP sockets. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1949 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1950 @property |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1951 def msg_flags_eor_indicator(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1952 return super().msg_flags_eor_indicator | socket.MSG_EOR |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1953 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1954 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1955 class SendrecvmsgConnectionlessBase(SendrecvmsgBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1956 # Base class for tests on connectionless-mode sockets. Users must |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1957 # supply sockets on attributes cli and serv to be mapped to |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1958 # cli_sock and serv_sock respectively. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1959 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1960 @property |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1961 def serv_sock(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1962 return self.serv |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1963 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1964 @property |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1965 def cli_sock(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1966 return self.cli |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1967 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1968 @property |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1969 def sendmsg_to_server_defaults(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1970 return ([], [], 0, self.serv_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1971 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1972 def sendToServer(self, msg): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1973 return self.cli_sock.sendto(msg, self.serv_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1974 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1975 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1976 class SendrecvmsgConnectedBase(SendrecvmsgBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1977 # Base class for tests on connected sockets. Users must supply |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1978 # sockets on attributes serv_conn and cli_conn (representing the |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1979 # connections *to* the server and the client), to be mapped to |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1980 # cli_sock and serv_sock respectively. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1981 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1982 @property |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1983 def serv_sock(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1984 return self.cli_conn |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1985 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1986 @property |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1987 def cli_sock(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1988 return self.serv_conn |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1989 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1990 def checkRecvmsgAddress(self, addr1, addr2): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1991 # Address is currently "unspecified" for a connected socket, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1992 # so we don't examine it |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1993 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1994 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1995 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1996 class SendrecvmsgServerTimeoutBase(SendrecvmsgBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1997 # Base class to set a timeout on server's socket. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1998 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
1999 def setUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2000 super().setUp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2001 self.serv_sock.settimeout(self.fail_timeout) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2002 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2003 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2004 class SendmsgTests(SendrecvmsgServerTimeoutBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2005 # Tests for sendmsg() which can use any socket type and do not |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2006 # involve recvmsg() or recvmsg_into(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2007 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2008 def testSendmsg(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2009 # Send a simple message with sendmsg(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2010 self.assertEqual(self.serv_sock.recv(len(MSG)), MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2011 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2012 def _testSendmsg(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2013 self.assertEqual(self.sendmsgToServer([MSG]), len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2014 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2015 def testSendmsgDataGenerator(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2016 # Send from buffer obtained from a generator (not a sequence). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2017 self.assertEqual(self.serv_sock.recv(len(MSG)), MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2018 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2019 def _testSendmsgDataGenerator(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2020 self.assertEqual(self.sendmsgToServer((o for o in [MSG])), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2021 len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2022 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2023 def testSendmsgAncillaryGenerator(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2024 # Gather (empty) ancillary data from a generator. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2025 self.assertEqual(self.serv_sock.recv(len(MSG)), MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2026 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2027 def _testSendmsgAncillaryGenerator(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2028 self.assertEqual(self.sendmsgToServer([MSG], (o for o in [])), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2029 len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2030 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2031 def testSendmsgArray(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2032 # Send data from an array instead of the usual bytes object. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2033 self.assertEqual(self.serv_sock.recv(len(MSG)), MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2034 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2035 def _testSendmsgArray(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2036 self.assertEqual(self.sendmsgToServer([array.array("B", MSG)]), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2037 len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2038 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2039 def testSendmsgGather(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2040 # Send message data from more than one buffer (gather write). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2041 self.assertEqual(self.serv_sock.recv(len(MSG)), MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2042 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2043 def _testSendmsgGather(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2044 self.assertEqual(self.sendmsgToServer([MSG[:3], MSG[3:]]), len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2045 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2046 def testSendmsgBadArgs(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2047 # Check that sendmsg() rejects invalid arguments. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2048 self.assertEqual(self.serv_sock.recv(1000), b"done") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2049 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2050 def _testSendmsgBadArgs(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2051 self.assertRaises(TypeError, self.cli_sock.sendmsg) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2052 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2053 b"not in an iterable") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2054 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2055 object()) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2056 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2057 [object()]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2058 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2059 [MSG, object()]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2060 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2061 [MSG], object()) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2062 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2063 [MSG], [], object()) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2064 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2065 [MSG], [], 0, object()) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2066 self.sendToServer(b"done") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2067 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2068 def testSendmsgBadCmsg(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2069 # Check that invalid ancillary data items are rejected. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2070 self.assertEqual(self.serv_sock.recv(1000), b"done") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2071 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2072 def _testSendmsgBadCmsg(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2073 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2074 [MSG], [object()]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2075 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2076 [MSG], [(object(), 0, b"data")]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2077 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2078 [MSG], [(0, object(), b"data")]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2079 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2080 [MSG], [(0, 0, object())]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2081 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2082 [MSG], [(0, 0)]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2083 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2084 [MSG], [(0, 0, b"data", 42)]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2085 self.sendToServer(b"done") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2086 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2087 @requireAttrs(socket, "CMSG_SPACE") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2088 def testSendmsgBadMultiCmsg(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2089 # Check that invalid ancillary data items are rejected when |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2090 # more than one item is present. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2091 self.assertEqual(self.serv_sock.recv(1000), b"done") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2092 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2093 @testSendmsgBadMultiCmsg.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2094 def _testSendmsgBadMultiCmsg(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2095 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2096 [MSG], [0, 0, b""]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2097 self.assertRaises(TypeError, self.sendmsgToServer, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2098 [MSG], [(0, 0, b""), object()]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2099 self.sendToServer(b"done") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2100 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2101 def testSendmsgExcessCmsgReject(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2102 # Check that sendmsg() rejects excess ancillary data items |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2103 # when the number that can be sent is limited. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2104 self.assertEqual(self.serv_sock.recv(1000), b"done") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2105 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2106 def _testSendmsgExcessCmsgReject(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2107 if not hasattr(socket, "CMSG_SPACE"): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2108 # Can only send one item |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
2109 with self.assertRaises(OSError) as cm: |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2110 self.sendmsgToServer([MSG], [(0, 0, b""), (0, 0, b"")]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2111 self.assertIsNone(cm.exception.errno) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2112 self.sendToServer(b"done") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2113 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2114 def testSendmsgAfterClose(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2115 # Check that sendmsg() fails on a closed socket. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2116 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2117 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2118 def _testSendmsgAfterClose(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2119 self.cli_sock.close() |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
2120 self.assertRaises(OSError, self.sendmsgToServer, [MSG]) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2121 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2122 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2123 class SendmsgStreamTests(SendmsgTests): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2124 # Tests for sendmsg() which require a stream socket and do not |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2125 # involve recvmsg() or recvmsg_into(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2126 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2127 def testSendmsgExplicitNoneAddr(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2128 # Check that peer address can be specified as None. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2129 self.assertEqual(self.serv_sock.recv(len(MSG)), MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2130 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2131 def _testSendmsgExplicitNoneAddr(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2132 self.assertEqual(self.sendmsgToServer([MSG], [], 0, None), len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2133 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2134 def testSendmsgTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2135 # Check that timeout works with sendmsg(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2136 self.assertEqual(self.serv_sock.recv(512), b"a"*512) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2137 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2138 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2139 def _testSendmsgTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2140 try: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2141 self.cli_sock.settimeout(0.03) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2142 with self.assertRaises(socket.timeout): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2143 while True: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2144 self.sendmsgToServer([b"a"*512]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2145 finally: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2146 self.misc_event.set() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2147 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2148 # XXX: would be nice to have more tests for sendmsg flags argument. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2149 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2150 # Linux supports MSG_DONTWAIT when sending, but in general, it |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2151 # only works when receiving. Could add other platforms if they |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2152 # support it too. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2153 @skipWithClientIf(sys.platform not in {"linux2"}, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2154 "MSG_DONTWAIT not known to work on this platform when " |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2155 "sending") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2156 def testSendmsgDontWait(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2157 # Check that MSG_DONTWAIT in flags causes non-blocking behaviour. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2158 self.assertEqual(self.serv_sock.recv(512), b"a"*512) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2159 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2160 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2161 @testSendmsgDontWait.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2162 def _testSendmsgDontWait(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2163 try: |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
2164 with self.assertRaises(OSError) as cm: |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2165 while True: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2166 self.sendmsgToServer([b"a"*512], [], socket.MSG_DONTWAIT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2167 self.assertIn(cm.exception.errno, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2168 (errno.EAGAIN, errno.EWOULDBLOCK)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2169 finally: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2170 self.misc_event.set() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2171 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2172 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2173 class SendmsgConnectionlessTests(SendmsgTests): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2174 # Tests for sendmsg() which require a connectionless-mode |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2175 # (e.g. datagram) socket, and do not involve recvmsg() or |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2176 # recvmsg_into(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2177 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2178 def testSendmsgNoDestAddr(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2179 # Check that sendmsg() fails when no destination address is |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2180 # given for unconnected socket. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2181 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2182 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2183 def _testSendmsgNoDestAddr(self): |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
2184 self.assertRaises(OSError, self.cli_sock.sendmsg, |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2185 [MSG]) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
2186 self.assertRaises(OSError, self.cli_sock.sendmsg, |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2187 [MSG], [], 0, None) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2188 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2189 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2190 class RecvmsgGenericTests(SendrecvmsgBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2191 # Tests for recvmsg() which can also be emulated using |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2192 # recvmsg_into(), and can use any socket type. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2193 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2194 def testRecvmsg(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2195 # Receive a simple message with recvmsg[_into](). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2196 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2197 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2198 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2199 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2200 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2201 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2202 def _testRecvmsg(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2203 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2204 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2205 def testRecvmsgExplicitDefaults(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2206 # Test recvmsg[_into]() with default arguments provided explicitly. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2207 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2208 len(MSG), 0, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2209 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2210 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2211 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2212 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2213 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2214 def _testRecvmsgExplicitDefaults(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2215 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2216 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2217 def testRecvmsgShorter(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2218 # Receive a message smaller than buffer. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2219 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2220 len(MSG) + 42) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2221 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2222 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2223 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2224 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2225 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2226 def _testRecvmsgShorter(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2227 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2228 |
|
72619
4378bae6b8dc
Issue #13001: Fix test_socket.testRecvmsgTrunc failure on FreeBSD < 8, which
Charles-François Natali <neologix@free.fr>
parents:
72587
diff
changeset
|
2229 # FreeBSD < 8 doesn't always set the MSG_TRUNC flag when a truncated |
|
4378bae6b8dc
Issue #13001: Fix test_socket.testRecvmsgTrunc failure on FreeBSD < 8, which
Charles-François Natali <neologix@free.fr>
parents:
72587
diff
changeset
|
2230 # datagram is received (issue #13001). |
|
4378bae6b8dc
Issue #13001: Fix test_socket.testRecvmsgTrunc failure on FreeBSD < 8, which
Charles-François Natali <neologix@free.fr>
parents:
72587
diff
changeset
|
2231 @support.requires_freebsd_version(8) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2232 def testRecvmsgTrunc(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2233 # Receive part of message, check for truncation indicators. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2234 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2235 len(MSG) - 3) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2236 self.assertEqual(msg, MSG[:-3]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2237 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2238 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2239 self.checkFlags(flags, eor=False) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2240 |
|
72619
4378bae6b8dc
Issue #13001: Fix test_socket.testRecvmsgTrunc failure on FreeBSD < 8, which
Charles-François Natali <neologix@free.fr>
parents:
72587
diff
changeset
|
2241 @support.requires_freebsd_version(8) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2242 def _testRecvmsgTrunc(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2243 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2244 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2245 def testRecvmsgShortAncillaryBuf(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2246 # Test ancillary data buffer too small to hold any ancillary data. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2247 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2248 len(MSG), 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2249 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2250 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2251 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2252 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2253 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2254 def _testRecvmsgShortAncillaryBuf(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2255 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2256 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2257 def testRecvmsgLongAncillaryBuf(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2258 # Test large ancillary data buffer. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2259 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2260 len(MSG), 10240) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2261 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2262 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2263 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2264 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2265 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2266 def _testRecvmsgLongAncillaryBuf(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2267 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2268 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2269 def testRecvmsgAfterClose(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2270 # Check that recvmsg[_into]() fails on a closed socket. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2271 self.serv_sock.close() |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
2272 self.assertRaises(OSError, self.doRecvmsg, self.serv_sock, 1024) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2273 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2274 def _testRecvmsgAfterClose(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2275 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2276 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2277 def testRecvmsgTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2278 # Check that timeout works. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2279 try: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2280 self.serv_sock.settimeout(0.03) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2281 self.assertRaises(socket.timeout, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2282 self.doRecvmsg, self.serv_sock, len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2283 finally: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2284 self.misc_event.set() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2285 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2286 def _testRecvmsgTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2287 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2288 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2289 @requireAttrs(socket, "MSG_PEEK") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2290 def testRecvmsgPeek(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2291 # Check that MSG_PEEK in flags enables examination of pending |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2292 # data without consuming it. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2293 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2294 # Receive part of data with MSG_PEEK. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2295 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2296 len(MSG) - 3, 0, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2297 socket.MSG_PEEK) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2298 self.assertEqual(msg, MSG[:-3]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2299 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2300 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2301 # Ignoring MSG_TRUNC here (so this test is the same for stream |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2302 # and datagram sockets). Some wording in POSIX seems to |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2303 # suggest that it needn't be set when peeking, but that may |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2304 # just be a slip. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2305 self.checkFlags(flags, eor=False, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2306 ignore=getattr(socket, "MSG_TRUNC", 0)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2307 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2308 # Receive all data with MSG_PEEK. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2309 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2310 len(MSG), 0, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2311 socket.MSG_PEEK) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2312 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2313 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2314 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2315 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2316 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2317 # Check that the same data can still be received normally. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2318 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2319 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2320 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2321 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2322 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2323 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2324 @testRecvmsgPeek.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2325 def _testRecvmsgPeek(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2326 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2327 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2328 @requireAttrs(socket.socket, "sendmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2329 def testRecvmsgFromSendmsg(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2330 # Test receiving with recvmsg[_into]() when message is sent |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2331 # using sendmsg(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2332 self.serv_sock.settimeout(self.fail_timeout) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2333 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2334 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2335 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2336 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2337 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2338 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2339 @testRecvmsgFromSendmsg.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2340 def _testRecvmsgFromSendmsg(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2341 self.assertEqual(self.sendmsgToServer([MSG[:3], MSG[3:]]), len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2342 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2343 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2344 class RecvmsgGenericStreamTests(RecvmsgGenericTests): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2345 # Tests which require a stream socket and can use either recvmsg() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2346 # or recvmsg_into(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2347 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2348 def testRecvmsgEOF(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2349 # Receive end-of-stream indicator (b"", peer socket closed). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2350 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, 1024) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2351 self.assertEqual(msg, b"") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2352 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2353 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2354 self.checkFlags(flags, eor=None) # Might not have end-of-record marker |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2355 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2356 def _testRecvmsgEOF(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2357 self.cli_sock.close() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2358 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2359 def testRecvmsgOverflow(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2360 # Receive a message in more than one chunk. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2361 seg1, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2362 len(MSG) - 3) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2363 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2364 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2365 self.checkFlags(flags, eor=False) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2366 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2367 seg2, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, 1024) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2368 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2369 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2370 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2371 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2372 msg = seg1 + seg2 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2373 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2374 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2375 def _testRecvmsgOverflow(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2376 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2377 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2378 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2379 class RecvmsgTests(RecvmsgGenericTests): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2380 # Tests for recvmsg() which can use any socket type. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2381 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2382 def testRecvmsgBadArgs(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2383 # Check that recvmsg() rejects invalid arguments. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2384 self.assertRaises(TypeError, self.serv_sock.recvmsg) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2385 self.assertRaises(ValueError, self.serv_sock.recvmsg, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2386 -1, 0, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2387 self.assertRaises(ValueError, self.serv_sock.recvmsg, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2388 len(MSG), -1, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2389 self.assertRaises(TypeError, self.serv_sock.recvmsg, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2390 [bytearray(10)], 0, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2391 self.assertRaises(TypeError, self.serv_sock.recvmsg, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2392 object(), 0, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2393 self.assertRaises(TypeError, self.serv_sock.recvmsg, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2394 len(MSG), object(), 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2395 self.assertRaises(TypeError, self.serv_sock.recvmsg, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2396 len(MSG), 0, object()) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2397 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2398 msg, ancdata, flags, addr = self.serv_sock.recvmsg(len(MSG), 0, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2399 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2400 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2401 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2402 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2403 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2404 def _testRecvmsgBadArgs(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2405 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2406 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2407 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2408 class RecvmsgIntoTests(RecvmsgIntoMixin, RecvmsgGenericTests): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2409 # Tests for recvmsg_into() which can use any socket type. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2410 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2411 def testRecvmsgIntoBadArgs(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2412 # Check that recvmsg_into() rejects invalid arguments. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2413 buf = bytearray(len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2414 self.assertRaises(TypeError, self.serv_sock.recvmsg_into) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2415 self.assertRaises(TypeError, self.serv_sock.recvmsg_into, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2416 len(MSG), 0, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2417 self.assertRaises(TypeError, self.serv_sock.recvmsg_into, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2418 buf, 0, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2419 self.assertRaises(TypeError, self.serv_sock.recvmsg_into, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2420 [object()], 0, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2421 self.assertRaises(TypeError, self.serv_sock.recvmsg_into, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2422 [b"I'm not writable"], 0, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2423 self.assertRaises(TypeError, self.serv_sock.recvmsg_into, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2424 [buf, object()], 0, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2425 self.assertRaises(ValueError, self.serv_sock.recvmsg_into, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2426 [buf], -1, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2427 self.assertRaises(TypeError, self.serv_sock.recvmsg_into, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2428 [buf], object(), 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2429 self.assertRaises(TypeError, self.serv_sock.recvmsg_into, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2430 [buf], 0, object()) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2431 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2432 nbytes, ancdata, flags, addr = self.serv_sock.recvmsg_into([buf], 0, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2433 self.assertEqual(nbytes, len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2434 self.assertEqual(buf, bytearray(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2435 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2436 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2437 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2438 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2439 def _testRecvmsgIntoBadArgs(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2440 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2441 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2442 def testRecvmsgIntoGenerator(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2443 # Receive into buffer obtained from a generator (not a sequence). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2444 buf = bytearray(len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2445 nbytes, ancdata, flags, addr = self.serv_sock.recvmsg_into( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2446 (o for o in [buf])) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2447 self.assertEqual(nbytes, len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2448 self.assertEqual(buf, bytearray(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2449 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2450 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2451 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2452 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2453 def _testRecvmsgIntoGenerator(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2454 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2455 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2456 def testRecvmsgIntoArray(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2457 # Receive into an array rather than the usual bytearray. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2458 buf = array.array("B", [0] * len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2459 nbytes, ancdata, flags, addr = self.serv_sock.recvmsg_into([buf]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2460 self.assertEqual(nbytes, len(MSG)) |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
2461 self.assertEqual(buf.tobytes(), MSG) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2462 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2463 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2464 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2465 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2466 def _testRecvmsgIntoArray(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2467 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2468 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2469 def testRecvmsgIntoScatter(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2470 # Receive into multiple buffers (scatter write). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2471 b1 = bytearray(b"----") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2472 b2 = bytearray(b"0123456789") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2473 b3 = bytearray(b"--------------") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2474 nbytes, ancdata, flags, addr = self.serv_sock.recvmsg_into( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2475 [b1, memoryview(b2)[2:9], b3]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2476 self.assertEqual(nbytes, len(b"Mary had a little lamb")) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2477 self.assertEqual(b1, bytearray(b"Mary")) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2478 self.assertEqual(b2, bytearray(b"01 had a 9")) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2479 self.assertEqual(b3, bytearray(b"little lamb---")) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2480 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2481 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2482 self.checkFlags(flags, eor=True) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2483 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2484 def _testRecvmsgIntoScatter(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2485 self.sendToServer(b"Mary had a little lamb") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2486 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2487 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2488 class CmsgMacroTests(unittest.TestCase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2489 # Test the functions CMSG_LEN() and CMSG_SPACE(). Tests |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2490 # assumptions used by sendmsg() and recvmsg[_into](), which share |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2491 # code with these functions. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2492 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2493 # Match the definition in socketmodule.c |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2494 socklen_t_limit = min(0x7fffffff, _testcapi.INT_MAX) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2495 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2496 @requireAttrs(socket, "CMSG_LEN") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2497 def testCMSG_LEN(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2498 # Test CMSG_LEN() with various valid and invalid values, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2499 # checking the assumptions used by recvmsg() and sendmsg(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2500 toobig = self.socklen_t_limit - socket.CMSG_LEN(0) + 1 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2501 values = list(range(257)) + list(range(toobig - 257, toobig)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2502 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2503 # struct cmsghdr has at least three members, two of which are ints |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2504 self.assertGreater(socket.CMSG_LEN(0), array.array("i").itemsize * 2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2505 for n in values: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2506 ret = socket.CMSG_LEN(n) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2507 # This is how recvmsg() calculates the data size |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2508 self.assertEqual(ret - socket.CMSG_LEN(0), n) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2509 self.assertLessEqual(ret, self.socklen_t_limit) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2510 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2511 self.assertRaises(OverflowError, socket.CMSG_LEN, -1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2512 # sendmsg() shares code with these functions, and requires |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2513 # that it reject values over the limit. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2514 self.assertRaises(OverflowError, socket.CMSG_LEN, toobig) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2515 self.assertRaises(OverflowError, socket.CMSG_LEN, sys.maxsize) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2516 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2517 @requireAttrs(socket, "CMSG_SPACE") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2518 def testCMSG_SPACE(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2519 # Test CMSG_SPACE() with various valid and invalid values, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2520 # checking the assumptions used by sendmsg(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2521 toobig = self.socklen_t_limit - socket.CMSG_SPACE(1) + 1 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2522 values = list(range(257)) + list(range(toobig - 257, toobig)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2523 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2524 last = socket.CMSG_SPACE(0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2525 # struct cmsghdr has at least three members, two of which are ints |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2526 self.assertGreater(last, array.array("i").itemsize * 2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2527 for n in values: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2528 ret = socket.CMSG_SPACE(n) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2529 self.assertGreaterEqual(ret, last) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2530 self.assertGreaterEqual(ret, socket.CMSG_LEN(n)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2531 self.assertGreaterEqual(ret, n + socket.CMSG_LEN(0)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2532 self.assertLessEqual(ret, self.socklen_t_limit) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2533 last = ret |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2534 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2535 self.assertRaises(OverflowError, socket.CMSG_SPACE, -1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2536 # sendmsg() shares code with these functions, and requires |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2537 # that it reject values over the limit. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2538 self.assertRaises(OverflowError, socket.CMSG_SPACE, toobig) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2539 self.assertRaises(OverflowError, socket.CMSG_SPACE, sys.maxsize) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2540 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2541 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2542 class SCMRightsTest(SendrecvmsgServerTimeoutBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2543 # Tests for file descriptor passing on Unix-domain sockets. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2544 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2545 # Invalid file descriptor value that's unlikely to evaluate to a |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2546 # real FD even if one of its bytes is replaced with a different |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2547 # value (which shouldn't actually happen). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2548 badfd = -0x5555 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2549 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2550 def newFDs(self, n): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2551 # Return a list of n file descriptors for newly-created files |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2552 # containing their list indices as ASCII numbers. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2553 fds = [] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2554 for i in range(n): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2555 fd, path = tempfile.mkstemp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2556 self.addCleanup(os.unlink, path) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2557 self.addCleanup(os.close, fd) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2558 os.write(fd, str(i).encode()) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2559 fds.append(fd) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2560 return fds |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2561 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2562 def checkFDs(self, fds): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2563 # Check that the file descriptors in the given list contain |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2564 # their correct list indices as ASCII numbers. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2565 for n, fd in enumerate(fds): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2566 os.lseek(fd, 0, os.SEEK_SET) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2567 self.assertEqual(os.read(fd, 1024), str(n).encode()) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2568 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2569 def registerRecvmsgResult(self, result): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2570 self.addCleanup(self.closeRecvmsgFDs, result) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2571 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2572 def closeRecvmsgFDs(self, recvmsg_result): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2573 # Close all file descriptors specified in the ancillary data |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2574 # of the given return value from recvmsg() or recvmsg_into(). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2575 for cmsg_level, cmsg_type, cmsg_data in recvmsg_result[1]: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2576 if (cmsg_level == socket.SOL_SOCKET and |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2577 cmsg_type == socket.SCM_RIGHTS): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2578 fds = array.array("i") |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
2579 fds.frombytes(cmsg_data[: |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2580 len(cmsg_data) - (len(cmsg_data) % fds.itemsize)]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2581 for fd in fds: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2582 os.close(fd) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2583 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2584 def createAndSendFDs(self, n): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2585 # Send n new file descriptors created by newFDs() to the |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2586 # server, with the constant MSG as the non-ancillary data. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2587 self.assertEqual( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2588 self.sendmsgToServer([MSG], |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2589 [(socket.SOL_SOCKET, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2590 socket.SCM_RIGHTS, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2591 array.array("i", self.newFDs(n)))]), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2592 len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2593 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2594 def checkRecvmsgFDs(self, numfds, result, maxcmsgs=1, ignoreflags=0): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2595 # Check that constant MSG was received with numfds file |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2596 # descriptors in a maximum of maxcmsgs control messages (which |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2597 # must contain only complete integers). By default, check |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2598 # that MSG_CTRUNC is unset, but ignore any flags in |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2599 # ignoreflags. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2600 msg, ancdata, flags, addr = result |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2601 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2602 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2603 self.checkFlags(flags, eor=True, checkunset=socket.MSG_CTRUNC, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2604 ignore=ignoreflags) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2605 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2606 self.assertIsInstance(ancdata, list) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2607 self.assertLessEqual(len(ancdata), maxcmsgs) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2608 fds = array.array("i") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2609 for item in ancdata: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2610 self.assertIsInstance(item, tuple) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2611 cmsg_level, cmsg_type, cmsg_data = item |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2612 self.assertEqual(cmsg_level, socket.SOL_SOCKET) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2613 self.assertEqual(cmsg_type, socket.SCM_RIGHTS) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2614 self.assertIsInstance(cmsg_data, bytes) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2615 self.assertEqual(len(cmsg_data) % SIZEOF_INT, 0) |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
2616 fds.frombytes(cmsg_data) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2617 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2618 self.assertEqual(len(fds), numfds) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2619 self.checkFDs(fds) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2620 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2621 def testFDPassSimple(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2622 # Pass a single FD (array read from bytes object). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2623 self.checkRecvmsgFDs(1, self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2624 len(MSG), 10240)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2625 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2626 def _testFDPassSimple(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2627 self.assertEqual( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2628 self.sendmsgToServer( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2629 [MSG], |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2630 [(socket.SOL_SOCKET, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2631 socket.SCM_RIGHTS, |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
2632 array.array("i", self.newFDs(1)).tobytes())]), |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2633 len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2634 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2635 def testMultipleFDPass(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2636 # Pass multiple FDs in a single array. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2637 self.checkRecvmsgFDs(4, self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2638 len(MSG), 10240)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2639 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2640 def _testMultipleFDPass(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2641 self.createAndSendFDs(4) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2642 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2643 @requireAttrs(socket, "CMSG_SPACE") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2644 def testFDPassCMSG_SPACE(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2645 # Test using CMSG_SPACE() to calculate ancillary buffer size. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2646 self.checkRecvmsgFDs( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2647 4, self.doRecvmsg(self.serv_sock, len(MSG), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2648 socket.CMSG_SPACE(4 * SIZEOF_INT))) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2649 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2650 @testFDPassCMSG_SPACE.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2651 def _testFDPassCMSG_SPACE(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2652 self.createAndSendFDs(4) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2653 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2654 def testFDPassCMSG_LEN(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2655 # Test using CMSG_LEN() to calculate ancillary buffer size. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2656 self.checkRecvmsgFDs(1, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2657 self.doRecvmsg(self.serv_sock, len(MSG), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2658 socket.CMSG_LEN(4 * SIZEOF_INT)), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2659 # RFC 3542 says implementations may set |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2660 # MSG_CTRUNC if there isn't enough space |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2661 # for trailing padding. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2662 ignoreflags=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2663 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2664 def _testFDPassCMSG_LEN(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2665 self.createAndSendFDs(1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2666 |
|
85019
b7d764807343
Issue #17684: Fix some test_socket failures due to limited FD passing support
Charles-Francois Natali <cf.natali@gmail.com>
parents:
84527
diff
changeset
|
2667 @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2668 @requireAttrs(socket, "CMSG_SPACE") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2669 def testFDPassSeparate(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2670 # Pass two FDs in two separate arrays. Arrays may be combined |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2671 # into a single control message by the OS. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2672 self.checkRecvmsgFDs(2, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2673 self.doRecvmsg(self.serv_sock, len(MSG), 10240), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2674 maxcmsgs=2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2675 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2676 @testFDPassSeparate.client_skip |
|
85019
b7d764807343
Issue #17684: Fix some test_socket failures due to limited FD passing support
Charles-Francois Natali <cf.natali@gmail.com>
parents:
84527
diff
changeset
|
2677 @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2678 def _testFDPassSeparate(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2679 fd0, fd1 = self.newFDs(2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2680 self.assertEqual( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2681 self.sendmsgToServer([MSG], [(socket.SOL_SOCKET, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2682 socket.SCM_RIGHTS, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2683 array.array("i", [fd0])), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2684 (socket.SOL_SOCKET, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2685 socket.SCM_RIGHTS, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2686 array.array("i", [fd1]))]), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2687 len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2688 |
|
85019
b7d764807343
Issue #17684: Fix some test_socket failures due to limited FD passing support
Charles-Francois Natali <cf.natali@gmail.com>
parents:
84527
diff
changeset
|
2689 @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2690 @requireAttrs(socket, "CMSG_SPACE") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2691 def testFDPassSeparateMinSpace(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2692 # Pass two FDs in two separate arrays, receiving them into the |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2693 # minimum space for two arrays. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2694 self.checkRecvmsgFDs(2, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2695 self.doRecvmsg(self.serv_sock, len(MSG), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2696 socket.CMSG_SPACE(SIZEOF_INT) + |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2697 socket.CMSG_LEN(SIZEOF_INT)), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2698 maxcmsgs=2, ignoreflags=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2699 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2700 @testFDPassSeparateMinSpace.client_skip |
|
85019
b7d764807343
Issue #17684: Fix some test_socket failures due to limited FD passing support
Charles-Francois Natali <cf.natali@gmail.com>
parents:
84527
diff
changeset
|
2701 @unittest.skipIf(sys.platform == "darwin", "skipping, see issue #12958") |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2702 def _testFDPassSeparateMinSpace(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2703 fd0, fd1 = self.newFDs(2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2704 self.assertEqual( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2705 self.sendmsgToServer([MSG], [(socket.SOL_SOCKET, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2706 socket.SCM_RIGHTS, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2707 array.array("i", [fd0])), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2708 (socket.SOL_SOCKET, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2709 socket.SCM_RIGHTS, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2710 array.array("i", [fd1]))]), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2711 len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2712 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2713 def sendAncillaryIfPossible(self, msg, ancdata): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2714 # Try to send msg and ancdata to server, but if the system |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2715 # call fails, just send msg with no ancillary data. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2716 try: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2717 nbytes = self.sendmsgToServer([msg], ancdata) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
2718 except OSError as e: |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2719 # Check that it was the system call that failed |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2720 self.assertIsInstance(e.errno, int) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2721 nbytes = self.sendmsgToServer([msg]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2722 self.assertEqual(nbytes, len(msg)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2723 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2724 def testFDPassEmpty(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2725 # Try to pass an empty FD array. Can receive either no array |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2726 # or an empty array. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2727 self.checkRecvmsgFDs(0, self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2728 len(MSG), 10240), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2729 ignoreflags=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2730 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2731 def _testFDPassEmpty(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2732 self.sendAncillaryIfPossible(MSG, [(socket.SOL_SOCKET, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2733 socket.SCM_RIGHTS, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2734 b"")]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2735 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2736 def testFDPassPartialInt(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2737 # Try to pass a truncated FD array. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2738 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2739 len(MSG), 10240) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2740 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2741 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2742 self.checkFlags(flags, eor=True, ignore=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2743 self.assertLessEqual(len(ancdata), 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2744 for cmsg_level, cmsg_type, cmsg_data in ancdata: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2745 self.assertEqual(cmsg_level, socket.SOL_SOCKET) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2746 self.assertEqual(cmsg_type, socket.SCM_RIGHTS) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2747 self.assertLess(len(cmsg_data), SIZEOF_INT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2748 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2749 def _testFDPassPartialInt(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2750 self.sendAncillaryIfPossible( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2751 MSG, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2752 [(socket.SOL_SOCKET, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2753 socket.SCM_RIGHTS, |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
2754 array.array("i", [self.badfd]).tobytes()[:-1])]) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2755 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2756 @requireAttrs(socket, "CMSG_SPACE") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2757 def testFDPassPartialIntInMiddle(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2758 # Try to pass two FD arrays, the first of which is truncated. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2759 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2760 len(MSG), 10240) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2761 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2762 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2763 self.checkFlags(flags, eor=True, ignore=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2764 self.assertLessEqual(len(ancdata), 2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2765 fds = array.array("i") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2766 # Arrays may have been combined in a single control message |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2767 for cmsg_level, cmsg_type, cmsg_data in ancdata: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2768 self.assertEqual(cmsg_level, socket.SOL_SOCKET) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2769 self.assertEqual(cmsg_type, socket.SCM_RIGHTS) |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
2770 fds.frombytes(cmsg_data[: |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2771 len(cmsg_data) - (len(cmsg_data) % fds.itemsize)]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2772 self.assertLessEqual(len(fds), 2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2773 self.checkFDs(fds) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2774 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2775 @testFDPassPartialIntInMiddle.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2776 def _testFDPassPartialIntInMiddle(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2777 fd0, fd1 = self.newFDs(2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2778 self.sendAncillaryIfPossible( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2779 MSG, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2780 [(socket.SOL_SOCKET, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2781 socket.SCM_RIGHTS, |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
2782 array.array("i", [fd0, self.badfd]).tobytes()[:-1]), |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2783 (socket.SOL_SOCKET, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2784 socket.SCM_RIGHTS, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2785 array.array("i", [fd1]))]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2786 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2787 def checkTruncatedHeader(self, result, ignoreflags=0): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2788 # Check that no ancillary data items are returned when data is |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2789 # truncated inside the cmsghdr structure. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2790 msg, ancdata, flags, addr = result |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2791 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2792 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2793 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2794 self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2795 ignore=ignoreflags) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2796 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2797 def testCmsgTruncNoBufSize(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2798 # Check that no ancillary data is received when no buffer size |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2799 # is specified. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2800 self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG)), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2801 # BSD seems to set MSG_CTRUNC only |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2802 # if an item has been partially |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2803 # received. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2804 ignoreflags=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2805 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2806 def _testCmsgTruncNoBufSize(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2807 self.createAndSendFDs(1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2808 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2809 def testCmsgTrunc0(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2810 # Check that no ancillary data is received when buffer size is 0. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2811 self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG), 0), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2812 ignoreflags=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2813 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2814 def _testCmsgTrunc0(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2815 self.createAndSendFDs(1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2816 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2817 # Check that no ancillary data is returned for various non-zero |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2818 # (but still too small) buffer sizes. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2819 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2820 def testCmsgTrunc1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2821 self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG), 1)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2822 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2823 def _testCmsgTrunc1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2824 self.createAndSendFDs(1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2825 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2826 def testCmsgTrunc2Int(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2827 # The cmsghdr structure has at least three members, two of |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2828 # which are ints, so we still shouldn't see any ancillary |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2829 # data. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2830 self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2831 SIZEOF_INT * 2)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2832 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2833 def _testCmsgTrunc2Int(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2834 self.createAndSendFDs(1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2835 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2836 def testCmsgTruncLen0Minus1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2837 self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2838 socket.CMSG_LEN(0) - 1)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2839 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2840 def _testCmsgTruncLen0Minus1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2841 self.createAndSendFDs(1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2842 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2843 # The following tests try to truncate the control message in the |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2844 # middle of the FD array. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2845 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2846 def checkTruncatedArray(self, ancbuf, maxdata, mindata=0): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2847 # Check that file descriptor data is truncated to between |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2848 # mindata and maxdata bytes when received with buffer size |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2849 # ancbuf, and that any complete file descriptor numbers are |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2850 # valid. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2851 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2852 len(MSG), ancbuf) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2853 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2854 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2855 self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2856 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2857 if mindata == 0 and ancdata == []: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2858 return |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2859 self.assertEqual(len(ancdata), 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2860 cmsg_level, cmsg_type, cmsg_data = ancdata[0] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2861 self.assertEqual(cmsg_level, socket.SOL_SOCKET) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2862 self.assertEqual(cmsg_type, socket.SCM_RIGHTS) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2863 self.assertGreaterEqual(len(cmsg_data), mindata) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2864 self.assertLessEqual(len(cmsg_data), maxdata) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2865 fds = array.array("i") |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
2866 fds.frombytes(cmsg_data[: |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2867 len(cmsg_data) - (len(cmsg_data) % fds.itemsize)]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2868 self.checkFDs(fds) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2869 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2870 def testCmsgTruncLen0(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2871 self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(0), maxdata=0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2872 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2873 def _testCmsgTruncLen0(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2874 self.createAndSendFDs(1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2875 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2876 def testCmsgTruncLen0Plus1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2877 self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(0) + 1, maxdata=1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2878 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2879 def _testCmsgTruncLen0Plus1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2880 self.createAndSendFDs(2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2881 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2882 def testCmsgTruncLen1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2883 self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(SIZEOF_INT), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2884 maxdata=SIZEOF_INT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2885 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2886 def _testCmsgTruncLen1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2887 self.createAndSendFDs(2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2888 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2889 def testCmsgTruncLen2Minus1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2890 self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(2 * SIZEOF_INT) - 1, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2891 maxdata=(2 * SIZEOF_INT) - 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2892 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2893 def _testCmsgTruncLen2Minus1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2894 self.createAndSendFDs(2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2895 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2896 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2897 class RFC3542AncillaryTest(SendrecvmsgServerTimeoutBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2898 # Test sendmsg() and recvmsg[_into]() using the ancillary data |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2899 # features of the RFC 3542 Advanced Sockets API for IPv6. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2900 # Currently we can only handle certain data items (e.g. traffic |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2901 # class, hop limit, MTU discovery and fragmentation settings) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2902 # without resorting to unportable means such as the struct module, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2903 # but the tests here are aimed at testing the ancillary data |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2904 # handling in sendmsg() and recvmsg() rather than the IPv6 API |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2905 # itself. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2906 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2907 # Test value to use when setting hop limit of packet |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2908 hop_limit = 2 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2909 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2910 # Test value to use when setting traffic class of packet. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2911 # -1 means "use kernel default". |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2912 traffic_class = -1 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2913 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2914 def ancillaryMapping(self, ancdata): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2915 # Given ancillary data list ancdata, return a mapping from |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2916 # pairs (cmsg_level, cmsg_type) to corresponding cmsg_data. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2917 # Check that no (level, type) pair appears more than once. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2918 d = {} |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2919 for cmsg_level, cmsg_type, cmsg_data in ancdata: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2920 self.assertNotIn((cmsg_level, cmsg_type), d) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2921 d[(cmsg_level, cmsg_type)] = cmsg_data |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2922 return d |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2923 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2924 def checkHopLimit(self, ancbufsize, maxhop=255, ignoreflags=0): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2925 # Receive hop limit into ancbufsize bytes of ancillary data |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2926 # space. Check that data is MSG, ancillary data is not |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2927 # truncated (but ignore any flags in ignoreflags), and hop |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2928 # limit is between 0 and maxhop inclusive. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2929 self.serv_sock.setsockopt(socket.IPPROTO_IPV6, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2930 socket.IPV6_RECVHOPLIMIT, 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2931 self.misc_event.set() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2932 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2933 len(MSG), ancbufsize) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2934 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2935 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2936 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2937 self.checkFlags(flags, eor=True, checkunset=socket.MSG_CTRUNC, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2938 ignore=ignoreflags) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2939 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2940 self.assertEqual(len(ancdata), 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2941 self.assertIsInstance(ancdata[0], tuple) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2942 cmsg_level, cmsg_type, cmsg_data = ancdata[0] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2943 self.assertEqual(cmsg_level, socket.IPPROTO_IPV6) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2944 self.assertEqual(cmsg_type, socket.IPV6_HOPLIMIT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2945 self.assertIsInstance(cmsg_data, bytes) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2946 self.assertEqual(len(cmsg_data), SIZEOF_INT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2947 a = array.array("i") |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
2948 a.frombytes(cmsg_data) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2949 self.assertGreaterEqual(a[0], 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2950 self.assertLessEqual(a[0], maxhop) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2951 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2952 @requireAttrs(socket, "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2953 def testRecvHopLimit(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2954 # Test receiving the packet hop limit as ancillary data. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2955 self.checkHopLimit(ancbufsize=10240) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2956 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2957 @testRecvHopLimit.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2958 def _testRecvHopLimit(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2959 # Need to wait until server has asked to receive ancillary |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2960 # data, as implementations are not required to buffer it |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2961 # otherwise. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2962 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2963 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2964 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2965 @requireAttrs(socket, "CMSG_SPACE", "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2966 def testRecvHopLimitCMSG_SPACE(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2967 # Test receiving hop limit, using CMSG_SPACE to calculate buffer size. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2968 self.checkHopLimit(ancbufsize=socket.CMSG_SPACE(SIZEOF_INT)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2969 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2970 @testRecvHopLimitCMSG_SPACE.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2971 def _testRecvHopLimitCMSG_SPACE(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2972 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2973 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2974 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2975 # Could test receiving into buffer sized using CMSG_LEN, but RFC |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2976 # 3542 says portable applications must provide space for trailing |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2977 # padding. Implementations may set MSG_CTRUNC if there isn't |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2978 # enough space for the padding. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2979 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2980 @requireAttrs(socket.socket, "sendmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2981 @requireAttrs(socket, "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2982 def testSetHopLimit(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2983 # Test setting hop limit on outgoing packet and receiving it |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2984 # at the other end. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2985 self.checkHopLimit(ancbufsize=10240, maxhop=self.hop_limit) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2986 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2987 @testSetHopLimit.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2988 def _testSetHopLimit(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2989 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2990 self.assertEqual( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2991 self.sendmsgToServer([MSG], |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2992 [(socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2993 array.array("i", [self.hop_limit]))]), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2994 len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2995 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2996 def checkTrafficClassAndHopLimit(self, ancbufsize, maxhop=255, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2997 ignoreflags=0): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2998 # Receive traffic class and hop limit into ancbufsize bytes of |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
2999 # ancillary data space. Check that data is MSG, ancillary |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3000 # data is not truncated (but ignore any flags in ignoreflags), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3001 # and traffic class and hop limit are in range (hop limit no |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3002 # more than maxhop). |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3003 self.serv_sock.setsockopt(socket.IPPROTO_IPV6, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3004 socket.IPV6_RECVHOPLIMIT, 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3005 self.serv_sock.setsockopt(socket.IPPROTO_IPV6, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3006 socket.IPV6_RECVTCLASS, 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3007 self.misc_event.set() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3008 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3009 len(MSG), ancbufsize) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3010 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3011 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3012 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3013 self.checkFlags(flags, eor=True, checkunset=socket.MSG_CTRUNC, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3014 ignore=ignoreflags) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3015 self.assertEqual(len(ancdata), 2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3016 ancmap = self.ancillaryMapping(ancdata) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3017 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3018 tcdata = ancmap[(socket.IPPROTO_IPV6, socket.IPV6_TCLASS)] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3019 self.assertEqual(len(tcdata), SIZEOF_INT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3020 a = array.array("i") |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
3021 a.frombytes(tcdata) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3022 self.assertGreaterEqual(a[0], 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3023 self.assertLessEqual(a[0], 255) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3024 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3025 hldata = ancmap[(socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT)] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3026 self.assertEqual(len(hldata), SIZEOF_INT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3027 a = array.array("i") |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
3028 a.frombytes(hldata) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3029 self.assertGreaterEqual(a[0], 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3030 self.assertLessEqual(a[0], maxhop) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3031 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3032 @requireAttrs(socket, "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT", |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3033 "IPV6_RECVTCLASS", "IPV6_TCLASS") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3034 def testRecvTrafficClassAndHopLimit(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3035 # Test receiving traffic class and hop limit as ancillary data. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3036 self.checkTrafficClassAndHopLimit(ancbufsize=10240) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3037 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3038 @testRecvTrafficClassAndHopLimit.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3039 def _testRecvTrafficClassAndHopLimit(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3040 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3041 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3042 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3043 @requireAttrs(socket, "CMSG_SPACE", "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT", |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3044 "IPV6_RECVTCLASS", "IPV6_TCLASS") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3045 def testRecvTrafficClassAndHopLimitCMSG_SPACE(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3046 # Test receiving traffic class and hop limit, using |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3047 # CMSG_SPACE() to calculate buffer size. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3048 self.checkTrafficClassAndHopLimit( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3049 ancbufsize=socket.CMSG_SPACE(SIZEOF_INT) * 2) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3050 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3051 @testRecvTrafficClassAndHopLimitCMSG_SPACE.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3052 def _testRecvTrafficClassAndHopLimitCMSG_SPACE(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3053 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3054 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3055 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3056 @requireAttrs(socket.socket, "sendmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3057 @requireAttrs(socket, "CMSG_SPACE", "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT", |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3058 "IPV6_RECVTCLASS", "IPV6_TCLASS") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3059 def testSetTrafficClassAndHopLimit(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3060 # Test setting traffic class and hop limit on outgoing packet, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3061 # and receiving them at the other end. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3062 self.checkTrafficClassAndHopLimit(ancbufsize=10240, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3063 maxhop=self.hop_limit) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3064 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3065 @testSetTrafficClassAndHopLimit.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3066 def _testSetTrafficClassAndHopLimit(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3067 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3068 self.assertEqual( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3069 self.sendmsgToServer([MSG], |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3070 [(socket.IPPROTO_IPV6, socket.IPV6_TCLASS, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3071 array.array("i", [self.traffic_class])), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3072 (socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3073 array.array("i", [self.hop_limit]))]), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3074 len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3075 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3076 @requireAttrs(socket.socket, "sendmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3077 @requireAttrs(socket, "CMSG_SPACE", "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT", |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3078 "IPV6_RECVTCLASS", "IPV6_TCLASS") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3079 def testOddCmsgSize(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3080 # Try to send ancillary data with first item one byte too |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3081 # long. Fall back to sending with correct size if this fails, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3082 # and check that second item was handled correctly. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3083 self.checkTrafficClassAndHopLimit(ancbufsize=10240, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3084 maxhop=self.hop_limit) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3085 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3086 @testOddCmsgSize.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3087 def _testOddCmsgSize(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3088 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3089 try: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3090 nbytes = self.sendmsgToServer( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3091 [MSG], |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3092 [(socket.IPPROTO_IPV6, socket.IPV6_TCLASS, |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
3093 array.array("i", [self.traffic_class]).tobytes() + b"\x00"), |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3094 (socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3095 array.array("i", [self.hop_limit]))]) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
3096 except OSError as e: |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3097 self.assertIsInstance(e.errno, int) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3098 nbytes = self.sendmsgToServer( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3099 [MSG], |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3100 [(socket.IPPROTO_IPV6, socket.IPV6_TCLASS, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3101 array.array("i", [self.traffic_class])), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3102 (socket.IPPROTO_IPV6, socket.IPV6_HOPLIMIT, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3103 array.array("i", [self.hop_limit]))]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3104 self.assertEqual(nbytes, len(MSG)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3105 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3106 # Tests for proper handling of truncated ancillary data |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3107 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3108 def checkHopLimitTruncatedHeader(self, ancbufsize, ignoreflags=0): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3109 # Receive hop limit into ancbufsize bytes of ancillary data |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3110 # space, which should be too small to contain the ancillary |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3111 # data header (if ancbufsize is None, pass no second argument |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3112 # to recvmsg()). Check that data is MSG, MSG_CTRUNC is set |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3113 # (unless included in ignoreflags), and no ancillary data is |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3114 # returned. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3115 self.serv_sock.setsockopt(socket.IPPROTO_IPV6, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3116 socket.IPV6_RECVHOPLIMIT, 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3117 self.misc_event.set() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3118 args = () if ancbufsize is None else (ancbufsize,) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3119 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3120 len(MSG), *args) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3121 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3122 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3123 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3124 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3125 self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3126 ignore=ignoreflags) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3127 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3128 @requireAttrs(socket, "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3129 def testCmsgTruncNoBufSize(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3130 # Check that no ancillary data is received when no ancillary |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3131 # buffer size is provided. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3132 self.checkHopLimitTruncatedHeader(ancbufsize=None, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3133 # BSD seems to set |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3134 # MSG_CTRUNC only if an item |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3135 # has been partially |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3136 # received. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3137 ignoreflags=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3138 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3139 @testCmsgTruncNoBufSize.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3140 def _testCmsgTruncNoBufSize(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3141 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3142 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3143 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3144 @requireAttrs(socket, "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3145 def testSingleCmsgTrunc0(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3146 # Check that no ancillary data is received when ancillary |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3147 # buffer size is zero. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3148 self.checkHopLimitTruncatedHeader(ancbufsize=0, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3149 ignoreflags=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3150 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3151 @testSingleCmsgTrunc0.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3152 def _testSingleCmsgTrunc0(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3153 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3154 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3155 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3156 # Check that no ancillary data is returned for various non-zero |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3157 # (but still too small) buffer sizes. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3158 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3159 @requireAttrs(socket, "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3160 def testSingleCmsgTrunc1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3161 self.checkHopLimitTruncatedHeader(ancbufsize=1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3162 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3163 @testSingleCmsgTrunc1.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3164 def _testSingleCmsgTrunc1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3165 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3166 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3167 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3168 @requireAttrs(socket, "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3169 def testSingleCmsgTrunc2Int(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3170 self.checkHopLimitTruncatedHeader(ancbufsize=2 * SIZEOF_INT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3171 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3172 @testSingleCmsgTrunc2Int.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3173 def _testSingleCmsgTrunc2Int(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3174 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3175 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3176 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3177 @requireAttrs(socket, "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3178 def testSingleCmsgTruncLen0Minus1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3179 self.checkHopLimitTruncatedHeader(ancbufsize=socket.CMSG_LEN(0) - 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3180 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3181 @testSingleCmsgTruncLen0Minus1.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3182 def _testSingleCmsgTruncLen0Minus1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3183 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3184 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3185 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3186 @requireAttrs(socket, "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3187 def testSingleCmsgTruncInData(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3188 # Test truncation of a control message inside its associated |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3189 # data. The message may be returned with its data truncated, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3190 # or not returned at all. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3191 self.serv_sock.setsockopt(socket.IPPROTO_IPV6, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3192 socket.IPV6_RECVHOPLIMIT, 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3193 self.misc_event.set() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3194 msg, ancdata, flags, addr = self.doRecvmsg( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3195 self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3196 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3197 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3198 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3199 self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3200 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3201 self.assertLessEqual(len(ancdata), 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3202 if ancdata: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3203 cmsg_level, cmsg_type, cmsg_data = ancdata[0] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3204 self.assertEqual(cmsg_level, socket.IPPROTO_IPV6) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3205 self.assertEqual(cmsg_type, socket.IPV6_HOPLIMIT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3206 self.assertLess(len(cmsg_data), SIZEOF_INT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3207 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3208 @testSingleCmsgTruncInData.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3209 def _testSingleCmsgTruncInData(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3210 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3211 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3212 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3213 def checkTruncatedSecondHeader(self, ancbufsize, ignoreflags=0): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3214 # Receive traffic class and hop limit into ancbufsize bytes of |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3215 # ancillary data space, which should be large enough to |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3216 # contain the first item, but too small to contain the header |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3217 # of the second. Check that data is MSG, MSG_CTRUNC is set |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3218 # (unless included in ignoreflags), and only one ancillary |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3219 # data item is returned. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3220 self.serv_sock.setsockopt(socket.IPPROTO_IPV6, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3221 socket.IPV6_RECVHOPLIMIT, 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3222 self.serv_sock.setsockopt(socket.IPPROTO_IPV6, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3223 socket.IPV6_RECVTCLASS, 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3224 self.misc_event.set() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3225 msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3226 len(MSG), ancbufsize) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3227 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3228 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3229 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3230 self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3231 ignore=ignoreflags) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3232 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3233 self.assertEqual(len(ancdata), 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3234 cmsg_level, cmsg_type, cmsg_data = ancdata[0] |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3235 self.assertEqual(cmsg_level, socket.IPPROTO_IPV6) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3236 self.assertIn(cmsg_type, {socket.IPV6_TCLASS, socket.IPV6_HOPLIMIT}) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3237 self.assertEqual(len(cmsg_data), SIZEOF_INT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3238 a = array.array("i") |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
3239 a.frombytes(cmsg_data) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3240 self.assertGreaterEqual(a[0], 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3241 self.assertLessEqual(a[0], 255) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3242 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3243 # Try the above test with various buffer sizes. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3244 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3245 @requireAttrs(socket, "CMSG_SPACE", "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT", |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3246 "IPV6_RECVTCLASS", "IPV6_TCLASS") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3247 def testSecondCmsgTrunc0(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3248 self.checkTruncatedSecondHeader(socket.CMSG_SPACE(SIZEOF_INT), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3249 ignoreflags=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3250 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3251 @testSecondCmsgTrunc0.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3252 def _testSecondCmsgTrunc0(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3253 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3254 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3255 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3256 @requireAttrs(socket, "CMSG_SPACE", "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT", |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3257 "IPV6_RECVTCLASS", "IPV6_TCLASS") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3258 def testSecondCmsgTrunc1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3259 self.checkTruncatedSecondHeader(socket.CMSG_SPACE(SIZEOF_INT) + 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3260 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3261 @testSecondCmsgTrunc1.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3262 def _testSecondCmsgTrunc1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3263 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3264 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3265 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3266 @requireAttrs(socket, "CMSG_SPACE", "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT", |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3267 "IPV6_RECVTCLASS", "IPV6_TCLASS") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3268 def testSecondCmsgTrunc2Int(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3269 self.checkTruncatedSecondHeader(socket.CMSG_SPACE(SIZEOF_INT) + |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3270 2 * SIZEOF_INT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3271 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3272 @testSecondCmsgTrunc2Int.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3273 def _testSecondCmsgTrunc2Int(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3274 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3275 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3276 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3277 @requireAttrs(socket, "CMSG_SPACE", "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT", |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3278 "IPV6_RECVTCLASS", "IPV6_TCLASS") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3279 def testSecondCmsgTruncLen0Minus1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3280 self.checkTruncatedSecondHeader(socket.CMSG_SPACE(SIZEOF_INT) + |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3281 socket.CMSG_LEN(0) - 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3282 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3283 @testSecondCmsgTruncLen0Minus1.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3284 def _testSecondCmsgTruncLen0Minus1(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3285 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3286 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3287 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3288 @requireAttrs(socket, "CMSG_SPACE", "IPV6_RECVHOPLIMIT", "IPV6_HOPLIMIT", |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3289 "IPV6_RECVTCLASS", "IPV6_TCLASS") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3290 def testSecomdCmsgTruncInData(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3291 # Test truncation of the second of two control messages inside |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3292 # its associated data. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3293 self.serv_sock.setsockopt(socket.IPPROTO_IPV6, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3294 socket.IPV6_RECVHOPLIMIT, 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3295 self.serv_sock.setsockopt(socket.IPPROTO_IPV6, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3296 socket.IPV6_RECVTCLASS, 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3297 self.misc_event.set() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3298 msg, ancdata, flags, addr = self.doRecvmsg( |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3299 self.serv_sock, len(MSG), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3300 socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3301 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3302 self.assertEqual(msg, MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3303 self.checkRecvmsgAddress(addr, self.cli_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3304 self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3305 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3306 cmsg_types = {socket.IPV6_TCLASS, socket.IPV6_HOPLIMIT} |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3307 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3308 cmsg_level, cmsg_type, cmsg_data = ancdata.pop(0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3309 self.assertEqual(cmsg_level, socket.IPPROTO_IPV6) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3310 cmsg_types.remove(cmsg_type) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3311 self.assertEqual(len(cmsg_data), SIZEOF_INT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3312 a = array.array("i") |
|
72034
d49cf0800c14
Fix deprecation warnings in test_socket.
Nadeem Vawda <nadeem.vawda@gmail.com>
parents:
72029
diff
changeset
|
3313 a.frombytes(cmsg_data) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3314 self.assertGreaterEqual(a[0], 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3315 self.assertLessEqual(a[0], 255) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3316 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3317 if ancdata: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3318 cmsg_level, cmsg_type, cmsg_data = ancdata.pop(0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3319 self.assertEqual(cmsg_level, socket.IPPROTO_IPV6) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3320 cmsg_types.remove(cmsg_type) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3321 self.assertLess(len(cmsg_data), SIZEOF_INT) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3322 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3323 self.assertEqual(ancdata, []) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3324 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3325 @testSecomdCmsgTruncInData.client_skip |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3326 def _testSecomdCmsgTruncInData(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3327 self.assertTrue(self.misc_event.wait(timeout=self.fail_timeout)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3328 self.sendToServer(MSG) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3329 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3330 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3331 # Derive concrete test classes for different socket types. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3332 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3333 class SendrecvmsgUDPTestBase(SendrecvmsgDgramFlagsBase, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3334 SendrecvmsgConnectionlessBase, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3335 ThreadedSocketTestMixin, UDPTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3336 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3337 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3338 @requireAttrs(socket.socket, "sendmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3339 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3340 class SendmsgUDPTest(SendmsgConnectionlessTests, SendrecvmsgUDPTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3341 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3342 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3343 @requireAttrs(socket.socket, "recvmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3344 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3345 class RecvmsgUDPTest(RecvmsgTests, SendrecvmsgUDPTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3346 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3347 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3348 @requireAttrs(socket.socket, "recvmsg_into") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3349 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3350 class RecvmsgIntoUDPTest(RecvmsgIntoTests, SendrecvmsgUDPTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3351 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3352 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3353 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3354 class SendrecvmsgUDP6TestBase(SendrecvmsgDgramFlagsBase, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3355 SendrecvmsgConnectionlessBase, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3356 ThreadedSocketTestMixin, UDP6TestBase): |
|
84527
330c7aa2922b
Issue #18308: don't take the scope ID into account when comparing IPv6
Charles-François Natali <cf.natali@gmail.com>
parents:
84075
diff
changeset
|
3357 |
|
330c7aa2922b
Issue #18308: don't take the scope ID into account when comparing IPv6
Charles-François Natali <cf.natali@gmail.com>
parents:
84075
diff
changeset
|
3358 def checkRecvmsgAddress(self, addr1, addr2): |
|
330c7aa2922b
Issue #18308: don't take the scope ID into account when comparing IPv6
Charles-François Natali <cf.natali@gmail.com>
parents:
84075
diff
changeset
|
3359 # Called to compare the received address with the address of |
|
330c7aa2922b
Issue #18308: don't take the scope ID into account when comparing IPv6
Charles-François Natali <cf.natali@gmail.com>
parents:
84075
diff
changeset
|
3360 # the peer, ignoring scope ID |
|
330c7aa2922b
Issue #18308: don't take the scope ID into account when comparing IPv6
Charles-François Natali <cf.natali@gmail.com>
parents:
84075
diff
changeset
|
3361 self.assertEqual(addr1[:-1], addr2[:-1]) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3362 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3363 @requireAttrs(socket.socket, "sendmsg") |
|
77988
b71dc2e9e00d
#15284: Skip {send,recv}msg tests with disabled IPv6
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
77662
diff
changeset
|
3364 @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.') |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3365 @requireSocket("AF_INET6", "SOCK_DGRAM") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3366 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3367 class SendmsgUDP6Test(SendmsgConnectionlessTests, SendrecvmsgUDP6TestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3368 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3369 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3370 @requireAttrs(socket.socket, "recvmsg") |
|
77988
b71dc2e9e00d
#15284: Skip {send,recv}msg tests with disabled IPv6
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
77662
diff
changeset
|
3371 @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.') |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3372 @requireSocket("AF_INET6", "SOCK_DGRAM") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3373 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3374 class RecvmsgUDP6Test(RecvmsgTests, SendrecvmsgUDP6TestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3375 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3376 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3377 @requireAttrs(socket.socket, "recvmsg_into") |
|
77988
b71dc2e9e00d
#15284: Skip {send,recv}msg tests with disabled IPv6
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
77662
diff
changeset
|
3378 @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.') |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3379 @requireSocket("AF_INET6", "SOCK_DGRAM") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3380 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3381 class RecvmsgIntoUDP6Test(RecvmsgIntoTests, SendrecvmsgUDP6TestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3382 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3383 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3384 @requireAttrs(socket.socket, "recvmsg") |
|
77988
b71dc2e9e00d
#15284: Skip {send,recv}msg tests with disabled IPv6
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
77662
diff
changeset
|
3385 @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.') |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3386 @requireAttrs(socket, "IPPROTO_IPV6") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3387 @requireSocket("AF_INET6", "SOCK_DGRAM") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3388 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3389 class RecvmsgRFC3542AncillaryUDP6Test(RFC3542AncillaryTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3390 SendrecvmsgUDP6TestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3391 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3392 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3393 @requireAttrs(socket.socket, "recvmsg_into") |
|
77988
b71dc2e9e00d
#15284: Skip {send,recv}msg tests with disabled IPv6
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
77662
diff
changeset
|
3394 @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.') |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3395 @requireAttrs(socket, "IPPROTO_IPV6") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3396 @requireSocket("AF_INET6", "SOCK_DGRAM") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3397 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3398 class RecvmsgIntoRFC3542AncillaryUDP6Test(RecvmsgIntoMixin, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3399 RFC3542AncillaryTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3400 SendrecvmsgUDP6TestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3401 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3402 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3403 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3404 class SendrecvmsgTCPTestBase(SendrecvmsgConnectedBase, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3405 ConnectedStreamTestMixin, TCPTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3406 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3407 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3408 @requireAttrs(socket.socket, "sendmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3409 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3410 class SendmsgTCPTest(SendmsgStreamTests, SendrecvmsgTCPTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3411 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3412 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3413 @requireAttrs(socket.socket, "recvmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3414 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3415 class RecvmsgTCPTest(RecvmsgTests, RecvmsgGenericStreamTests, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3416 SendrecvmsgTCPTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3417 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3418 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3419 @requireAttrs(socket.socket, "recvmsg_into") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3420 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3421 class RecvmsgIntoTCPTest(RecvmsgIntoTests, RecvmsgGenericStreamTests, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3422 SendrecvmsgTCPTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3423 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3424 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3425 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3426 class SendrecvmsgSCTPStreamTestBase(SendrecvmsgSCTPFlagsBase, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3427 SendrecvmsgConnectedBase, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3428 ConnectedStreamTestMixin, SCTPStreamBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3429 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3430 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3431 @requireAttrs(socket.socket, "sendmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3432 @requireSocket("AF_INET", "SOCK_STREAM", "IPPROTO_SCTP") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3433 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3434 class SendmsgSCTPStreamTest(SendmsgStreamTests, SendrecvmsgSCTPStreamTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3435 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3436 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3437 @requireAttrs(socket.socket, "recvmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3438 @requireSocket("AF_INET", "SOCK_STREAM", "IPPROTO_SCTP") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3439 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3440 class RecvmsgSCTPStreamTest(RecvmsgTests, RecvmsgGenericStreamTests, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3441 SendrecvmsgSCTPStreamTestBase): |
|
80889
391bda06fa65
Silence sporadic failure in RecvmsgSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79785
diff
changeset
|
3442 |
|
391bda06fa65
Silence sporadic failure in RecvmsgSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79785
diff
changeset
|
3443 def testRecvmsgEOF(self): |
|
391bda06fa65
Silence sporadic failure in RecvmsgSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79785
diff
changeset
|
3444 try: |
|
391bda06fa65
Silence sporadic failure in RecvmsgSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79785
diff
changeset
|
3445 super(RecvmsgSCTPStreamTest, self).testRecvmsgEOF() |
|
391bda06fa65
Silence sporadic failure in RecvmsgSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79785
diff
changeset
|
3446 except OSError as e: |
|
391bda06fa65
Silence sporadic failure in RecvmsgSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79785
diff
changeset
|
3447 if e.errno != errno.ENOTCONN: |
|
391bda06fa65
Silence sporadic failure in RecvmsgSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79785
diff
changeset
|
3448 raise |
|
391bda06fa65
Silence sporadic failure in RecvmsgSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
79785
diff
changeset
|
3449 self.skipTest("sporadic ENOTCONN (kernel issue?) - see issue #13876") |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3450 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3451 @requireAttrs(socket.socket, "recvmsg_into") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3452 @requireSocket("AF_INET", "SOCK_STREAM", "IPPROTO_SCTP") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3453 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3454 class RecvmsgIntoSCTPStreamTest(RecvmsgIntoTests, RecvmsgGenericStreamTests, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3455 SendrecvmsgSCTPStreamTestBase): |
|
80941
13d8c33de8ff
Silence sporadic failure in RecvmsgIntoSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
80889
diff
changeset
|
3456 |
|
13d8c33de8ff
Silence sporadic failure in RecvmsgIntoSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
80889
diff
changeset
|
3457 def testRecvmsgEOF(self): |
|
13d8c33de8ff
Silence sporadic failure in RecvmsgIntoSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
80889
diff
changeset
|
3458 try: |
|
13d8c33de8ff
Silence sporadic failure in RecvmsgIntoSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
80889
diff
changeset
|
3459 super(RecvmsgIntoSCTPStreamTest, self).testRecvmsgEOF() |
|
13d8c33de8ff
Silence sporadic failure in RecvmsgIntoSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
80889
diff
changeset
|
3460 except OSError as e: |
|
13d8c33de8ff
Silence sporadic failure in RecvmsgIntoSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
80889
diff
changeset
|
3461 if e.errno != errno.ENOTCONN: |
|
13d8c33de8ff
Silence sporadic failure in RecvmsgIntoSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
80889
diff
changeset
|
3462 raise |
|
13d8c33de8ff
Silence sporadic failure in RecvmsgIntoSCTPStreamTest.testRecvmsgEOF (issue #13876) - probably not Python-related.
Antoine Pitrou <solipsis@pitrou.net>
parents:
80889
diff
changeset
|
3463 self.skipTest("sporadic ENOTCONN (kernel issue?) - see issue #13876") |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3464 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3465 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3466 class SendrecvmsgUnixStreamTestBase(SendrecvmsgConnectedBase, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3467 ConnectedStreamTestMixin, UnixStreamBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3468 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3469 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3470 @requireAttrs(socket.socket, "sendmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3471 @requireAttrs(socket, "AF_UNIX") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3472 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3473 class SendmsgUnixStreamTest(SendmsgStreamTests, SendrecvmsgUnixStreamTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3474 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3475 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3476 @requireAttrs(socket.socket, "recvmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3477 @requireAttrs(socket, "AF_UNIX") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3478 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3479 class RecvmsgUnixStreamTest(RecvmsgTests, RecvmsgGenericStreamTests, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3480 SendrecvmsgUnixStreamTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3481 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3482 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3483 @requireAttrs(socket.socket, "recvmsg_into") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3484 @requireAttrs(socket, "AF_UNIX") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3485 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3486 class RecvmsgIntoUnixStreamTest(RecvmsgIntoTests, RecvmsgGenericStreamTests, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3487 SendrecvmsgUnixStreamTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3488 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3489 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3490 @requireAttrs(socket.socket, "sendmsg", "recvmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3491 @requireAttrs(socket, "AF_UNIX", "SOL_SOCKET", "SCM_RIGHTS") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3492 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3493 class RecvmsgSCMRightsStreamTest(SCMRightsTest, SendrecvmsgUnixStreamTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3494 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3495 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3496 @requireAttrs(socket.socket, "sendmsg", "recvmsg_into") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3497 @requireAttrs(socket, "AF_UNIX", "SOL_SOCKET", "SCM_RIGHTS") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3498 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3499 class RecvmsgIntoSCMRightsStreamTest(RecvmsgIntoMixin, SCMRightsTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3500 SendrecvmsgUnixStreamTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3501 pass |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3502 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3503 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3504 # Test interrupting the interruptible send/receive methods with a |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3505 # signal when a timeout is set. These tests avoid having multiple |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3506 # threads alive during the test so that the OS cannot deliver the |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3507 # signal to the wrong one. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3508 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3509 class InterruptedTimeoutBase(unittest.TestCase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3510 # Base class for interrupted send/receive tests. Installs an |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3511 # empty handler for SIGALRM and removes it on teardown, along with |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3512 # any scheduled alarms. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3513 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3514 def setUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3515 super().setUp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3516 orig_alrm_handler = signal.signal(signal.SIGALRM, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3517 lambda signum, frame: None) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3518 self.addCleanup(signal.signal, signal.SIGALRM, orig_alrm_handler) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3519 self.addCleanup(self.setAlarm, 0) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3520 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3521 # Timeout for socket operations |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3522 timeout = 4.0 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3523 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3524 # Provide setAlarm() method to schedule delivery of SIGALRM after |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3525 # given number of seconds, or cancel it if zero, and an |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3526 # appropriate time value to use. Use setitimer() if available. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3527 if hasattr(signal, "setitimer"): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3528 alarm_time = 0.05 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3529 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3530 def setAlarm(self, seconds): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3531 signal.setitimer(signal.ITIMER_REAL, seconds) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3532 else: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3533 # Old systems may deliver the alarm up to one second early |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3534 alarm_time = 2 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3535 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3536 def setAlarm(self, seconds): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3537 signal.alarm(seconds) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3538 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3539 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3540 # Require siginterrupt() in order to ensure that system calls are |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3541 # interrupted by default. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3542 @requireAttrs(signal, "siginterrupt") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3543 @unittest.skipUnless(hasattr(signal, "alarm") or hasattr(signal, "setitimer"), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3544 "Don't have signal.alarm or signal.setitimer") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3545 class InterruptedRecvTimeoutTest(InterruptedTimeoutBase, UDPTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3546 # Test interrupting the recv*() methods with signals when a |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3547 # timeout is set. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3548 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3549 def setUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3550 super().setUp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3551 self.serv.settimeout(self.timeout) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3552 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3553 def checkInterruptedRecv(self, func, *args, **kwargs): |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
3554 # Check that func(*args, **kwargs) raises OSError with an |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3555 # errno of EINTR when interrupted by a signal. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3556 self.setAlarm(self.alarm_time) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
3557 with self.assertRaises(OSError) as cm: |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3558 func(*args, **kwargs) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3559 self.assertNotIsInstance(cm.exception, socket.timeout) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3560 self.assertEqual(cm.exception.errno, errno.EINTR) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3561 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3562 def testInterruptedRecvTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3563 self.checkInterruptedRecv(self.serv.recv, 1024) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3564 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3565 def testInterruptedRecvIntoTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3566 self.checkInterruptedRecv(self.serv.recv_into, bytearray(1024)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3567 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3568 def testInterruptedRecvfromTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3569 self.checkInterruptedRecv(self.serv.recvfrom, 1024) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3570 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3571 def testInterruptedRecvfromIntoTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3572 self.checkInterruptedRecv(self.serv.recvfrom_into, bytearray(1024)) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3573 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3574 @requireAttrs(socket.socket, "recvmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3575 def testInterruptedRecvmsgTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3576 self.checkInterruptedRecv(self.serv.recvmsg, 1024) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3577 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3578 @requireAttrs(socket.socket, "recvmsg_into") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3579 def testInterruptedRecvmsgIntoTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3580 self.checkInterruptedRecv(self.serv.recvmsg_into, [bytearray(1024)]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3581 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3582 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3583 # Require siginterrupt() in order to ensure that system calls are |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3584 # interrupted by default. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3585 @requireAttrs(signal, "siginterrupt") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3586 @unittest.skipUnless(hasattr(signal, "alarm") or hasattr(signal, "setitimer"), |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3587 "Don't have signal.alarm or signal.setitimer") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3588 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3589 class InterruptedSendTimeoutTest(InterruptedTimeoutBase, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3590 ThreadSafeCleanupTestCase, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3591 SocketListeningTestMixin, TCPTestBase): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3592 # Test interrupting the interruptible send*() methods with signals |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3593 # when a timeout is set. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3594 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3595 def setUp(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3596 super().setUp() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3597 self.serv_conn = self.newSocket() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3598 self.addCleanup(self.serv_conn.close) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3599 # Use a thread to complete the connection, but wait for it to |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3600 # terminate before running the test, so that there is only one |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3601 # thread to accept the signal. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3602 cli_thread = threading.Thread(target=self.doConnect) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3603 cli_thread.start() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3604 self.cli_conn, addr = self.serv.accept() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3605 self.addCleanup(self.cli_conn.close) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3606 cli_thread.join() |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3607 self.serv_conn.settimeout(self.timeout) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3608 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3609 def doConnect(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3610 self.serv_conn.connect(self.serv_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3611 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3612 def checkInterruptedSend(self, func, *args, **kwargs): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3613 # Check that func(*args, **kwargs), run in a loop, raises |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
3614 # OSError with an errno of EINTR when interrupted by a |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3615 # signal. |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
3616 with self.assertRaises(OSError) as cm: |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3617 while True: |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3618 self.setAlarm(self.alarm_time) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3619 func(*args, **kwargs) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3620 self.assertNotIsInstance(cm.exception, socket.timeout) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3621 self.assertEqual(cm.exception.errno, errno.EINTR) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3622 |
|
72400
a4e4facad164
Close issue 12958 by flagging expected failures in test_socket on Mac OS X
Nick Coghlan <ncoghlan@gmail.com>
parents:
72034
diff
changeset
|
3623 # Issue #12958: The following tests have problems on Mac OS X |
|
a4e4facad164
Close issue 12958 by flagging expected failures in test_socket on Mac OS X
Nick Coghlan <ncoghlan@gmail.com>
parents:
72034
diff
changeset
|
3624 @support.anticipate_failure(sys.platform == "darwin") |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3625 def testInterruptedSendTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3626 self.checkInterruptedSend(self.serv_conn.send, b"a"*512) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3627 |
|
72400
a4e4facad164
Close issue 12958 by flagging expected failures in test_socket on Mac OS X
Nick Coghlan <ncoghlan@gmail.com>
parents:
72034
diff
changeset
|
3628 @support.anticipate_failure(sys.platform == "darwin") |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3629 def testInterruptedSendtoTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3630 # Passing an actual address here as Python's wrapper for |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3631 # sendto() doesn't allow passing a zero-length one; POSIX |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3632 # requires that the address is ignored since the socket is |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3633 # connection-mode, however. |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3634 self.checkInterruptedSend(self.serv_conn.sendto, b"a"*512, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3635 self.serv_addr) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3636 |
|
72400
a4e4facad164
Close issue 12958 by flagging expected failures in test_socket on Mac OS X
Nick Coghlan <ncoghlan@gmail.com>
parents:
72034
diff
changeset
|
3637 @support.anticipate_failure(sys.platform == "darwin") |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3638 @requireAttrs(socket.socket, "sendmsg") |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3639 def testInterruptedSendmsgTimeout(self): |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3640 self.checkInterruptedSend(self.serv_conn.sendmsg, [b"a"*512]) |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3641 |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
3642 |
|
61073
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
3643 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3644 class TCPCloserTest(ThreadedTCPSocketTest): |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3645 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3646 def testClose(self): |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3647 conn, addr = self.serv.accept() |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3648 conn.close() |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3649 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3650 sd = self.cli |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3651 read, write, err = select.select([sd], [], [], 1.0) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3652 self.assertEqual(read, [sd]) |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
3653 self.assertEqual(sd.recv(1), b'') |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3654 |
|
42434
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3655 # Calling close() many times should be safe. |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3656 conn.close() |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3657 conn.close() |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3658 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3659 def _testClose(self): |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
3660 self.cli.connect((HOST, self.port)) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3661 time.sleep(1.0) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
3662 |
|
61073
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
3663 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3664 class BasicSocketPairTest(SocketPairTest): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3665 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3666 def __init__(self, methodName='runTest'): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3667 SocketPairTest.__init__(self, methodName=methodName) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3668 |
|
64754
b81e8e3fa5bb
Make testDefaults in test.test_socket.BasicSocketPairTest more reliable.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64747
diff
changeset
|
3669 def _check_defaults(self, sock): |
|
b81e8e3fa5bb
Make testDefaults in test.test_socket.BasicSocketPairTest more reliable.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64747
diff
changeset
|
3670 self.assertIsInstance(sock, socket.socket) |
|
b81e8e3fa5bb
Make testDefaults in test.test_socket.BasicSocketPairTest more reliable.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64747
diff
changeset
|
3671 if hasattr(socket, 'AF_UNIX'): |
|
b81e8e3fa5bb
Make testDefaults in test.test_socket.BasicSocketPairTest more reliable.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64747
diff
changeset
|
3672 self.assertEqual(sock.family, socket.AF_UNIX) |
|
b81e8e3fa5bb
Make testDefaults in test.test_socket.BasicSocketPairTest more reliable.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64747
diff
changeset
|
3673 else: |
|
b81e8e3fa5bb
Make testDefaults in test.test_socket.BasicSocketPairTest more reliable.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64747
diff
changeset
|
3674 self.assertEqual(sock.family, socket.AF_INET) |
|
b81e8e3fa5bb
Make testDefaults in test.test_socket.BasicSocketPairTest more reliable.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64747
diff
changeset
|
3675 self.assertEqual(sock.type, socket.SOCK_STREAM) |
|
b81e8e3fa5bb
Make testDefaults in test.test_socket.BasicSocketPairTest more reliable.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64747
diff
changeset
|
3676 self.assertEqual(sock.proto, 0) |
|
b81e8e3fa5bb
Make testDefaults in test.test_socket.BasicSocketPairTest more reliable.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64747
diff
changeset
|
3677 |
|
64747
534853ba8cd3
Issue #1552: socket.socketpair() now returns regular socket.socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
64593
diff
changeset
|
3678 def _testDefaults(self): |
|
64754
b81e8e3fa5bb
Make testDefaults in test.test_socket.BasicSocketPairTest more reliable.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64747
diff
changeset
|
3679 self._check_defaults(self.cli) |
|
64747
534853ba8cd3
Issue #1552: socket.socketpair() now returns regular socket.socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
64593
diff
changeset
|
3680 |
|
534853ba8cd3
Issue #1552: socket.socketpair() now returns regular socket.socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
64593
diff
changeset
|
3681 def testDefaults(self): |
|
64754
b81e8e3fa5bb
Make testDefaults in test.test_socket.BasicSocketPairTest more reliable.
Antoine Pitrou <solipsis@pitrou.net>
parents:
64747
diff
changeset
|
3682 self._check_defaults(self.serv) |
|
64747
534853ba8cd3
Issue #1552: socket.socketpair() now returns regular socket.socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
64593
diff
changeset
|
3683 |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3684 def testRecv(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3685 msg = self.serv.recv(1024) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3686 self.assertEqual(msg, MSG) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3687 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3688 def _testRecv(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3689 self.cli.send(MSG) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3690 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3691 def testSend(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3692 self.serv.send(MSG) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3693 |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3694 def _testSend(self): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3695 msg = self.cli.recv(1024) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3696 self.assertEqual(msg, MSG) |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
3697 |
|
61073
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
3698 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3699 class NonBlockingTCPTests(ThreadedTCPSocketTest): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3700 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3701 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3702 ThreadedTCPSocketTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3703 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3704 def testSetBlocking(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3705 # Testing whether set blocking works |
|
81587
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
3706 self.serv.setblocking(True) |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
3707 self.assertIsNone(self.serv.gettimeout()) |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
3708 self.serv.setblocking(False) |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
3709 self.assertEqual(self.serv.gettimeout(), 0.0) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3710 start = time.time() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3711 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3712 self.serv.accept() |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
3713 except OSError: |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3714 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3715 end = time.time() |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
3716 self.assertTrue((end - start) < 1.0, "Error setting non-blocking mode.") |
|
81587
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
3717 # Issue 15989 |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
3718 if _testcapi.UINT_MAX < _testcapi.ULONG_MAX: |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
3719 self.serv.setblocking(_testcapi.UINT_MAX + 1) |
|
974ace29ee2d
Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents:
79784
diff
changeset
|
3720 self.assertIsNone(self.serv.gettimeout()) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3721 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3722 def _testSetBlocking(self): |
|
17208
c8817a9bbbdd
Make socket.getservbyname test optional on socket module having that
Barry Warsaw <barry@python.org>
parents:
16519
diff
changeset
|
3723 pass |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
3724 |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3725 if hasattr(socket, "SOCK_NONBLOCK"): |
|
70612
277bbe6cae53
Issue #12196: Make test.support's requires_linux_version a decorator.
Charles-François Natali <neologix@free.fr>
parents:
70324
diff
changeset
|
3726 @support.requires_linux_version(2, 6, 28) |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3727 def testInitNonBlocking(self): |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3728 # reinit server socket |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3729 self.serv.close() |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3730 self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM | |
|
65606
a30e75820b8d
Also guard other SOCK_NONBLOCK test
Antoine Pitrou <solipsis@pitrou.net>
parents:
65604
diff
changeset
|
3731 socket.SOCK_NONBLOCK) |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3732 self.port = support.bind_port(self.serv) |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3733 self.serv.listen(1) |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3734 # actual testing |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3735 start = time.time() |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3736 try: |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3737 self.serv.accept() |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
3738 except OSError: |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3739 pass |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3740 end = time.time() |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3741 self.assertTrue((end - start) < 1.0, "Error creating with non-blocking mode.") |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3742 |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3743 def _testInitNonBlocking(self): |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3744 pass |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
3745 |
|
67382
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3746 def testInheritFlags(self): |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3747 # Issue #7995: when calling accept() on a listening socket with a |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3748 # timeout, the resulting socket should not be non-blocking. |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3749 self.serv.settimeout(10) |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3750 try: |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3751 conn, addr = self.serv.accept() |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3752 message = conn.recv(len(MSG)) |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3753 finally: |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3754 conn.close() |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3755 self.serv.settimeout(None) |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3756 |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3757 def _testInheritFlags(self): |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3758 time.sleep(0.1) |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3759 self.cli.connect((HOST, self.port)) |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3760 time.sleep(0.5) |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3761 self.cli.send(MSG) |
|
ed0259230611
Issue #7995: When calling accept() on a socket with a timeout, the returned
Antoine Pitrou <solipsis@pitrou.net>
parents:
67344
diff
changeset
|
3762 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3763 def testAccept(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3764 # Testing non-blocking accept |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3765 self.serv.setblocking(0) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3766 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3767 conn, addr = self.serv.accept() |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
3768 except OSError: |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3769 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3770 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3771 self.fail("Error trying to do non-blocking accept.") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3772 read, write, err = select.select([self.serv], [], []) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3773 if self.serv in read: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3774 conn, addr = self.serv.accept() |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
3775 conn.close() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3776 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3777 self.fail("Error trying to do accept after select.") |
|
20853
77bb2ae067c2
Correct getnameinfo refcounting and tuple parsing. Fixes #476648.
Martin v. Löwis <martin@v.loewis.de>
parents:
20733
diff
changeset
|
3778 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3779 def _testAccept(self): |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
3780 time.sleep(0.1) |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
3781 self.cli.connect((HOST, self.port)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3782 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3783 def testConnect(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3784 # Testing non-blocking connect |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3785 conn, addr = self.serv.accept() |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
3786 conn.close() |
|
4880
9a7e9f10aed6
Test of the socket module. The following functions and methods are
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
3787 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3788 def _testConnect(self): |
|
23818
8a0a14e3725e
Fix non-blocking connect() for Windows. Refactored the code
Guido van Rossum <guido@python.org>
parents:
23815
diff
changeset
|
3789 self.cli.settimeout(10) |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
3790 self.cli.connect((HOST, self.port)) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3791 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3792 def testRecv(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3793 # Testing non-blocking recv |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3794 conn, addr = self.serv.accept() |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3795 conn.setblocking(0) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3796 try: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3797 msg = conn.recv(len(MSG)) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
3798 except OSError: |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3799 pass |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3800 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3801 self.fail("Error trying to do non-blocking recv.") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3802 read, write, err = select.select([conn], [], []) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3803 if conn in read: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3804 msg = conn.recv(len(MSG)) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
3805 conn.close() |
|
23794
1f1a6f7dd600
Lose the message on assertEqual calls -- they actually hide
Guido van Rossum <guido@python.org>
parents:
23790
diff
changeset
|
3806 self.assertEqual(msg, MSG) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3807 else: |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3808 self.fail("Error during select call to non-blocking socket.") |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3809 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3810 def _testRecv(self): |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
3811 self.cli.connect((HOST, self.port)) |
|
24318
12815d05080c
Add test for previous core dump when sending on closed socket with
Guido van Rossum <guido@python.org>
parents:
24293
diff
changeset
|
3812 time.sleep(0.1) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3813 self.cli.send(MSG) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3814 |
|
61073
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
3815 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3816 class FileObjectClassTestCase(SocketConnectedTest): |
|
42434
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3817 """Unit tests for the object returned by socket.makefile() |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3818 |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3819 self.read_file is the io object returned by makefile() on |
|
42434
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3820 the client connection. You can read from this file to |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3821 get output from the server. |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3822 |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3823 self.write_file is the io object returned by makefile() on the |
|
42434
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3824 server connection. You can write to this file to send output |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3825 to the client. |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3826 """ |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
3827 |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
3828 bufsize = -1 # Use default buffer size |
|
68142
be6c38d1817b
Normalize the encoding names for Latin-1 and UTF-8 to
Marc-André Lemburg <mal@egenix.com>
parents:
67382
diff
changeset
|
3829 encoding = 'utf-8' |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3830 errors = 'strict' |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3831 newline = None |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3832 |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3833 read_mode = 'rb' |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3834 read_msg = MSG |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3835 write_mode = 'wb' |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3836 write_msg = MSG |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
3837 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3838 def __init__(self, methodName='runTest'): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3839 SocketConnectedTest.__init__(self, methodName=methodName) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3840 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3841 def setUp(self): |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
3842 self.evt1, self.evt2, self.serv_finished, self.cli_finished = [ |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
3843 threading.Event() for i in range(4)] |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3844 SocketConnectedTest.setUp(self) |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3845 self.read_file = self.cli_conn.makefile( |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3846 self.read_mode, self.bufsize, |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3847 encoding = self.encoding, |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3848 errors = self.errors, |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3849 newline = self.newline) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3850 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3851 def tearDown(self): |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
3852 self.serv_finished.set() |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3853 self.read_file.close() |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3854 self.assertTrue(self.read_file.closed) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3855 self.read_file = None |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3856 SocketConnectedTest.tearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3857 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3858 def clientSetUp(self): |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3859 SocketConnectedTest.clientSetUp(self) |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3860 self.write_file = self.serv_conn.makefile( |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3861 self.write_mode, self.bufsize, |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3862 encoding = self.encoding, |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3863 errors = self.errors, |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3864 newline = self.newline) |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
3865 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3866 def clientTearDown(self): |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
3867 self.cli_finished.set() |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3868 self.write_file.close() |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3869 self.assertTrue(self.write_file.closed) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3870 self.write_file = None |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3871 SocketConnectedTest.clientTearDown(self) |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3872 |
|
68032
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3873 def testReadAfterTimeout(self): |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3874 # Issue #7322: A file object must disallow further reads |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3875 # after a timeout has occurred. |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3876 self.cli_conn.settimeout(1) |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3877 self.read_file.read(3) |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3878 # First read raises a timeout |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3879 self.assertRaises(socket.timeout, self.read_file.read, 1) |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3880 # Second read is disallowed |
|
81039
7d69d04522e3
Replace IOError with OSError (#16715)
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80942
diff
changeset
|
3881 with self.assertRaises(OSError) as ctx: |
|
68032
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3882 self.read_file.read(1) |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3883 self.assertIn("cannot read from timed out object", str(ctx.exception)) |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3884 |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3885 def _testReadAfterTimeout(self): |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3886 self.write_file.write(self.write_msg[0:3]) |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3887 self.write_file.flush() |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3888 self.serv_finished.wait() |
|
59f9ed12f17a
Merged revisions 88622 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
67382
diff
changeset
|
3889 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3890 def testSmallRead(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3891 # Performing small file read test |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3892 first_seg = self.read_file.read(len(self.read_msg)-3) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3893 second_seg = self.read_file.read(3) |
|
23800
bf1555a92711
Remove some overly complicated ways to concatenate and repeat strings
Guido van Rossum <guido@python.org>
parents:
23799
diff
changeset
|
3894 msg = first_seg + second_seg |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3895 self.assertEqual(msg, self.read_msg) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3896 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3897 def _testSmallRead(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3898 self.write_file.write(self.write_msg) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3899 self.write_file.flush() |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
3900 |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3901 def testFullRead(self): |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3902 # read until EOF |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3903 msg = self.read_file.read() |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3904 self.assertEqual(msg, self.read_msg) |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3905 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3906 def _testFullRead(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3907 self.write_file.write(self.write_msg) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3908 self.write_file.close() |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3909 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3910 def testUnbufferedRead(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3911 # Performing unbuffered file read test |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3912 buf = type(self.read_msg)() |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3913 while 1: |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3914 char = self.read_file.read(1) |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3915 if not char: |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3916 break |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3917 buf += char |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3918 self.assertEqual(buf, self.read_msg) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3919 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3920 def _testUnbufferedRead(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3921 self.write_file.write(self.write_msg) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3922 self.write_file.flush() |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
3923 |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3924 def testReadline(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
3925 # Performing file readline test |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3926 line = self.read_file.readline() |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3927 self.assertEqual(line, self.read_msg) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3928 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
3929 def _testReadline(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3930 self.write_file.write(self.write_msg) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3931 self.write_file.flush() |
|
23715
c2733e8f6612
SF patch 555085 (timeout socket implementation) by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
21315
diff
changeset
|
3932 |
|
42434
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3933 def testCloseAfterMakefile(self): |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3934 # The file returned by makefile should keep the socket open. |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3935 self.cli_conn.close() |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3936 # read until EOF |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3937 msg = self.read_file.read() |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3938 self.assertEqual(msg, self.read_msg) |
|
42434
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3939 |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3940 def _testCloseAfterMakefile(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3941 self.write_file.write(self.write_msg) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3942 self.write_file.flush() |
|
42434
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3943 |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3944 def testMakefileAfterMakefileClose(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3945 self.read_file.close() |
|
42434
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3946 msg = self.cli_conn.recv(len(MSG)) |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3947 if isinstance(self.read_msg, str): |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3948 msg = msg.decode() |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3949 self.assertEqual(msg, self.read_msg) |
|
42434
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3950 |
|
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3951 def _testMakefileAfterMakefileClose(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3952 self.write_file.write(self.write_msg) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3953 self.write_file.flush() |
|
42434
c35140559f87
Make sure socket.close() doesn't interfere with socket.makefile().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
42169
diff
changeset
|
3954 |
|
31833
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
3955 def testClosedAttr(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3956 self.assertTrue(not self.read_file.closed) |
|
31833
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
3957 |
|
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
3958 def _testClosedAttr(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3959 self.assertTrue(not self.write_file.closed) |
|
31833
a910b822b12c
SF bug 924242: socket._fileobject._getclosed() returns wrong value
Tim Peters <tim.peters@gmail.com>
parents:
31503
diff
changeset
|
3960 |
|
49782
5ffd67df8c9f
Follow-up of r67300: correct a failure in socket.makefile().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48623
diff
changeset
|
3961 def testAttributes(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3962 self.assertEqual(self.read_file.mode, self.read_mode) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3963 self.assertEqual(self.read_file.name, self.cli_conn.fileno()) |
|
49782
5ffd67df8c9f
Follow-up of r67300: correct a failure in socket.makefile().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48623
diff
changeset
|
3964 |
|
5ffd67df8c9f
Follow-up of r67300: correct a failure in socket.makefile().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48623
diff
changeset
|
3965 def _testAttributes(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3966 self.assertEqual(self.write_file.mode, self.write_mode) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3967 self.assertEqual(self.write_file.name, self.serv_conn.fileno()) |
|
49782
5ffd67df8c9f
Follow-up of r67300: correct a failure in socket.makefile().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48623
diff
changeset
|
3968 |
|
50741
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
3969 def testRealClose(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3970 self.read_file.close() |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
3971 self.assertRaises(ValueError, self.read_file.fileno) |
|
50741
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
3972 self.cli_conn.close() |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
3973 self.assertRaises(OSError, self.cli_conn.getsockname) |
|
50741
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
3974 |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
3975 def _testRealClose(self): |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
3976 pass |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
3977 |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
3978 |
|
58146
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3979 class FileObjectInterruptedTestCase(unittest.TestCase): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3980 """Test that the file object correctly handles EINTR internally.""" |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3981 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3982 class MockSocket(object): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3983 def __init__(self, recv_funcs=()): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3984 # A generator that returns callables that we'll call for each |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3985 # call to recv(). |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3986 self._recv_step = iter(recv_funcs) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3987 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3988 def recv_into(self, buffer): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3989 data = next(self._recv_step)() |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3990 assert len(buffer) >= len(data) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3991 buffer[:len(data)] = data |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3992 return len(data) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3993 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3994 def _decref_socketios(self): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3995 pass |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3996 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3997 def _textiowrap_for_test(self, buffering=-1): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3998 raw = socket.SocketIO(self, "r") |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
3999 if buffering < 0: |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4000 buffering = io.DEFAULT_BUFFER_SIZE |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4001 if buffering == 0: |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4002 return raw |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4003 buffer = io.BufferedReader(raw, buffering) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4004 text = io.TextIOWrapper(buffer, None, None) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4005 text.mode = "rb" |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4006 return text |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4007 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4008 @staticmethod |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4009 def _raise_eintr(): |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4010 raise OSError(errno.EINTR, "interrupted") |
|
58146
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4011 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4012 def _textiowrap_mock_socket(self, mock, buffering=-1): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4013 raw = socket.SocketIO(mock, "r") |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4014 if buffering < 0: |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4015 buffering = io.DEFAULT_BUFFER_SIZE |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4016 if buffering == 0: |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4017 return raw |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4018 buffer = io.BufferedReader(raw, buffering) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4019 text = io.TextIOWrapper(buffer, None, None) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4020 text.mode = "rb" |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4021 return text |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4022 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4023 def _test_readline(self, size=-1, buffering=-1): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4024 mock_sock = self.MockSocket(recv_funcs=[ |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4025 lambda : b"This is the first line\nAnd the sec", |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4026 self._raise_eintr, |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4027 lambda : b"ond line is here\n", |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4028 lambda : b"", |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4029 lambda : b"", # XXX(gps): io library does an extra EOF read |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4030 ]) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4031 fo = mock_sock._textiowrap_for_test(buffering=buffering) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66279
diff
changeset
|
4032 self.assertEqual(fo.readline(size), "This is the first line\n") |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66279
diff
changeset
|
4033 self.assertEqual(fo.readline(size), "And the second line is here\n") |
|
58146
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4034 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4035 def _test_read(self, size=-1, buffering=-1): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4036 mock_sock = self.MockSocket(recv_funcs=[ |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4037 lambda : b"This is the first line\nAnd the sec", |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4038 self._raise_eintr, |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4039 lambda : b"ond line is here\n", |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4040 lambda : b"", |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4041 lambda : b"", # XXX(gps): io library does an extra EOF read |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4042 ]) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4043 expecting = (b"This is the first line\n" |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4044 b"And the second line is here\n") |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4045 fo = mock_sock._textiowrap_for_test(buffering=buffering) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4046 if buffering == 0: |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4047 data = b'' |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4048 else: |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4049 data = '' |
|
68142
be6c38d1817b
Normalize the encoding names for Latin-1 and UTF-8 to
Marc-André Lemburg <mal@egenix.com>
parents:
67382
diff
changeset
|
4050 expecting = expecting.decode('utf-8') |
|
58146
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4051 while len(data) != len(expecting): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4052 part = fo.read(size) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4053 if not part: |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4054 break |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4055 data += part |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66279
diff
changeset
|
4056 self.assertEqual(data, expecting) |
|
58146
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4057 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4058 def test_default(self): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4059 self._test_readline() |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4060 self._test_readline(size=100) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4061 self._test_read() |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4062 self._test_read(size=100) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4063 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4064 def test_with_1k_buffer(self): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4065 self._test_readline(buffering=1024) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4066 self._test_readline(size=100, buffering=1024) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4067 self._test_read(buffering=1024) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4068 self._test_read(size=100, buffering=1024) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4069 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4070 def _test_readline_no_buffer(self, size=-1): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4071 mock_sock = self.MockSocket(recv_funcs=[ |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4072 lambda : b"a", |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4073 lambda : b"\n", |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4074 lambda : b"B", |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4075 self._raise_eintr, |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4076 lambda : b"b", |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4077 lambda : b"", |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4078 ]) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4079 fo = mock_sock._textiowrap_for_test(buffering=0) |
|
66310
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66279
diff
changeset
|
4080 self.assertEqual(fo.readline(size), b"a\n") |
|
9fe76c26ea9f
#9424: Replace deprecated assert* methods in the Python test suite.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
66279
diff
changeset
|
4081 self.assertEqual(fo.readline(size), b"Bb") |
|
58146
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4082 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4083 def test_no_buffer(self): |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4084 self._test_readline_no_buffer() |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4085 self._test_readline_no_buffer(size=4) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4086 self._test_read(buffering=0) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4087 self._test_read(size=100, buffering=0) |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4088 |
|
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
4089 |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4090 class UnbufferedFileObjectClassTestCase(FileObjectClassTestCase): |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4091 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4092 """Repeat the tests from FileObjectClassTestCase with bufsize==0. |
|
24674
3269bdd65988
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
24655
diff
changeset
|
4093 |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4094 In this case (and in this case only), it should be possible to |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4095 create a file object, read a line from it, create another file |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4096 object, read another line from it, without loss of data in the |
|
47318
e1fcc3881cb6
Create http package. #2883.
Georg Brandl <georg@python.org>
parents:
47266
diff
changeset
|
4097 first file object's buffer. Note that http.client relies on this |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4098 when reading multiple requests from the same socket.""" |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4099 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4100 bufsize = 0 # Use unbuffered mode |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4101 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4102 def testUnbufferedReadline(self): |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
4103 # Read a line, create a new file object, read another line with it |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4104 line = self.read_file.readline() # first line |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4105 self.assertEqual(line, b"A. " + self.write_msg) # first line |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4106 self.read_file = self.cli_conn.makefile('rb', 0) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4107 line = self.read_file.readline() # second line |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4108 self.assertEqual(line, b"B. " + self.write_msg) # second line |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4109 |
|
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4110 def _testUnbufferedReadline(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4111 self.write_file.write(b"A. " + self.write_msg) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4112 self.write_file.write(b"B. " + self.write_msg) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4113 self.write_file.flush() |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4114 |
|
50741
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4115 def testMakefileClose(self): |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4116 # The file returned by makefile should keep the socket open... |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4117 self.cli_conn.close() |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4118 msg = self.cli_conn.recv(1024) |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4119 self.assertEqual(msg, self.read_msg) |
|
50741
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4120 # ...until the file is itself closed |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4121 self.read_file.close() |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4122 self.assertRaises(OSError, self.cli_conn.recv, 1024) |
|
50741
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4123 |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4124 def _testMakefileClose(self): |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4125 self.write_file.write(self.write_msg) |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4126 self.write_file.flush() |
|
50741
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4127 |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4128 def testMakefileCloseSocketDestroy(self): |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4129 refcount_before = sys.getrefcount(self.cli_conn) |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4130 self.read_file.close() |
|
50741
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4131 refcount_after = sys.getrefcount(self.cli_conn) |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4132 self.assertEqual(refcount_before - 1, refcount_after) |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4133 |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4134 def _testMakefileCloseSocketDestroy(self): |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4135 pass |
|
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4136 |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4137 # Non-blocking ops |
|
65258
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4138 # NOTE: to set `read_file` as non-blocking, we must call |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4139 # `cli_conn.setblocking` and vice-versa (see setUp / clientSetUp). |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4140 |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4141 def testSmallReadNonBlocking(self): |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4142 self.cli_conn.setblocking(False) |
|
65258
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4143 self.assertEqual(self.read_file.readinto(bytearray(10)), None) |
|
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4144 self.assertEqual(self.read_file.read(len(self.read_msg) - 3), None) |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4145 self.evt1.set() |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4146 self.evt2.wait(1.0) |
|
65258
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4147 first_seg = self.read_file.read(len(self.read_msg) - 3) |
|
69122
68a319ef70fc
Issue #11749: try to fix transient test_socket failure
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
4148 if first_seg is None: |
|
68a319ef70fc
Issue #11749: try to fix transient test_socket failure
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
4149 # Data not arrived (can happen under Windows), wait a bit |
|
68a319ef70fc
Issue #11749: try to fix transient test_socket failure
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
4150 time.sleep(0.5) |
|
68a319ef70fc
Issue #11749: try to fix transient test_socket failure
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
4151 first_seg = self.read_file.read(len(self.read_msg) - 3) |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4152 buf = bytearray(10) |
|
65258
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4153 n = self.read_file.readinto(buf) |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4154 self.assertEqual(n, 3) |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4155 msg = first_seg + buf[:n] |
|
65258
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4156 self.assertEqual(msg, self.read_msg) |
|
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4157 self.assertEqual(self.read_file.readinto(bytearray(16)), None) |
|
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4158 self.assertEqual(self.read_file.read(1), None) |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4159 |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4160 def _testSmallReadNonBlocking(self): |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4161 self.evt1.wait(1.0) |
|
65258
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4162 self.write_file.write(self.write_msg) |
|
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4163 self.write_file.flush() |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4164 self.evt2.set() |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4165 # Avoid cloding the socket before the server test has finished, |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4166 # otherwise system recv() will return 0 instead of EWOULDBLOCK. |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4167 self.serv_finished.wait(5.0) |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4168 |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4169 def testWriteNonBlocking(self): |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4170 self.cli_finished.wait(5.0) |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4171 # The client thread can't skip directly - the SkipTest exception |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4172 # would appear as a failure. |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4173 if self.serv_skipped: |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4174 self.skipTest(self.serv_skipped) |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4175 |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4176 def _testWriteNonBlocking(self): |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4177 self.serv_skipped = None |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4178 self.serv_conn.setblocking(False) |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4179 # Try to saturate the socket buffer pipe with repeated large writes. |
|
85450
498957c97c2b
Issue #18643: Fix some test_socket failures due to large default socket buffer
Charles-François Natali <cf.natali@gmail.com>
parents:
85360
diff
changeset
|
4180 BIG = b"x" * support.SOCK_MAX_SIZE |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4181 LIMIT = 10 |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4182 # The first write() succeeds since a chunk of data can be buffered |
|
65258
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4183 n = self.write_file.write(BIG) |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4184 self.assertGreater(n, 0) |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4185 for i in range(LIMIT): |
|
65258
1875bfed5689
Issue #10041: The signature of optional arguments in socket.makefile()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64959
diff
changeset
|
4186 n = self.write_file.write(BIG) |
|
64817
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4187 if n is None: |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4188 # Succeeded |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4189 break |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4190 self.assertGreater(n, 0) |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4191 else: |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4192 # Let us know that this test didn't manage to establish |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4193 # the expected conditions. This is not a failure in itself but, |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4194 # if it happens repeatedly, the test should be fixed. |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4195 self.serv_skipped = "failed to saturate the socket buffer" |
|
f3dcb314c3e3
Issue #9854: SocketIO objects now observe the RawIOBase interface in
Antoine Pitrou <solipsis@pitrou.net>
parents:
64754
diff
changeset
|
4196 |
|
50741
5f4c2de95091
Fixes issue #3826 and #4791:
Gregory P. Smith <greg@mad-scientist.com>
parents:
49800
diff
changeset
|
4197 |
|
24655
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
4198 class LineBufferedFileObjectClassTestCase(FileObjectClassTestCase): |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
4199 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
4200 bufsize = 1 # Default-buffered for reading; line-buffered for writing |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
4201 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
4202 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
4203 class SmallBufferedFileObjectClassTestCase(FileObjectClassTestCase): |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
4204 |
|
18ca4e783f98
Replace docstrings on test functions witrh comments -- then unittest
Guido van Rossum <guido@python.org>
parents:
24648
diff
changeset
|
4205 bufsize = 2 # Exercise the buffering code |
|
24634
778093533a46
"Unbuffered" mode of class _fileobject wasn't actually unbuffered,
Guido van Rossum <guido@python.org>
parents:
24485
diff
changeset
|
4206 |
|
40737
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40644
diff
changeset
|
4207 |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4208 class UnicodeReadFileObjectClassTestCase(FileObjectClassTestCase): |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4209 """Tests for socket.makefile() in text mode (rather than binary)""" |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4210 |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4211 read_mode = 'r' |
|
68142
be6c38d1817b
Normalize the encoding names for Latin-1 and UTF-8 to
Marc-André Lemburg <mal@egenix.com>
parents:
67382
diff
changeset
|
4212 read_msg = MSG.decode('utf-8') |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4213 write_mode = 'wb' |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4214 write_msg = MSG |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4215 newline = '' |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4216 |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4217 |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4218 class UnicodeWriteFileObjectClassTestCase(FileObjectClassTestCase): |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4219 """Tests for socket.makefile() in text mode (rather than binary)""" |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4220 |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4221 read_mode = 'rb' |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4222 read_msg = MSG |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4223 write_mode = 'w' |
|
68142
be6c38d1817b
Normalize the encoding names for Latin-1 and UTF-8 to
Marc-André Lemburg <mal@egenix.com>
parents:
67382
diff
changeset
|
4224 write_msg = MSG.decode('utf-8') |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4225 newline = '' |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4226 |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4227 |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4228 class UnicodeReadWriteFileObjectClassTestCase(FileObjectClassTestCase): |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4229 """Tests for socket.makefile() in text mode (rather than binary)""" |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4230 |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4231 read_mode = 'r' |
|
68142
be6c38d1817b
Normalize the encoding names for Latin-1 and UTF-8 to
Marc-André Lemburg <mal@egenix.com>
parents:
67382
diff
changeset
|
4232 read_msg = MSG.decode('utf-8') |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4233 write_mode = 'w' |
|
68142
be6c38d1817b
Normalize the encoding names for Latin-1 and UTF-8 to
Marc-André Lemburg <mal@egenix.com>
parents:
67382
diff
changeset
|
4234 write_msg = MSG.decode('utf-8') |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4235 newline = '' |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4236 |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
4237 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4238 class NetworkConnectionTest(object): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4239 """Prove network connection.""" |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
4240 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4241 def clientSetUp(self): |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
4242 # We're inherited below by BasicTCPTest2, which also inherits |
|
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
4243 # BasicTCPTest, which defines self.port referenced below. |
|
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
4244 self.cli = socket.create_connection((HOST, self.port)) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4245 self.serv_conn = self.cli |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4246 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4247 class BasicTCPTest2(NetworkConnectionTest, BasicTCPTest): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4248 """Tests that NetworkConnection does not break existing TCP functionality. |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4249 """ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4250 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4251 class NetworkConnectionNoServer(unittest.TestCase): |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
4252 |
|
64536
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4253 class MockSocket(socket.socket): |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4254 def connect(self, *args): |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4255 raise socket.timeout('timed out') |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4256 |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4257 @contextlib.contextmanager |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4258 def mocked_socket_module(self): |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4259 """Return a socket which times out on connect""" |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4260 old_socket = socket.socket |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4261 socket.socket = self.MockSocket |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4262 try: |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4263 yield |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4264 finally: |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4265 socket.socket = old_socket |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4266 |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4267 def test_connect(self): |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46899
diff
changeset
|
4268 port = support.find_unused_port() |
|
64536
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4269 cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
4270 self.addCleanup(cli.close) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4271 with self.assertRaises(OSError) as cm: |
|
64536
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4272 cli.connect((HOST, port)) |
|
64534
b2f7cf9c6776
Issue #9792: In case of connection failure, socket.create_connection()
Antoine Pitrou <solipsis@pitrou.net>
parents:
64442
diff
changeset
|
4273 self.assertEqual(cm.exception.errno, errno.ECONNREFUSED) |
|
64536
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4274 |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4275 def test_create_connection(self): |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4276 # Issue #9792: errors raised by create_connection() should have |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4277 # a proper errno attribute. |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4278 port = support.find_unused_port() |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4279 with self.assertRaises(OSError) as cm: |
|
64536
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4280 socket.create_connection((HOST, port)) |
|
79784
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4281 |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4282 # Issue #16257: create_connection() calls getaddrinfo() against |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4283 # 'localhost'. This may result in an IPV6 addr being returned |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4284 # as well as an IPV4 one: |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4285 # >>> socket.getaddrinfo('localhost', port, 0, SOCK_STREAM) |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4286 # >>> [(2, 2, 0, '', ('127.0.0.1', 41230)), |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4287 # (26, 2, 0, '', ('::1', 41230, 0, 0))] |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4288 # |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4289 # create_connection() enumerates through all the addresses returned |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4290 # and if it doesn't successfully bind to any of them, it propagates |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4291 # the last exception it encountered. |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4292 # |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4293 # On Solaris, ENETUNREACH is returned in this circumstance instead |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4294 # of ECONNREFUSED. So, if that errno exists, add it to our list of |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4295 # expected errnos. |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4296 expected_errnos = [ errno.ECONNREFUSED, ] |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4297 if hasattr(errno, 'ENETUNREACH'): |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4298 expected_errnos.append(errno.ENETUNREACH) |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4299 |
|
b5fa9d8603b6
Issue #16257: make test_create_connection() handle ENETUNREACH.
Trent Nelson <trent@trent.me>
parents:
79026
diff
changeset
|
4300 self.assertIn(cm.exception.errno, expected_errnos) |
|
64536
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4301 |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4302 def test_create_connection_timeout(self): |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4303 # Issue #9792: create_connection() should not recast timeout errors |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4304 # as generic socket errors. |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4305 with self.mocked_socket_module(): |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4306 with self.assertRaises(socket.timeout): |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4307 socket.create_connection((HOST, 1234)) |
|
2400f55ea312
Merged revisions 84597-84599 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64060
diff
changeset
|
4308 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4309 |
|
61073
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
4310 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4311 class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4312 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4313 def __init__(self, methodName='runTest'): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4314 SocketTCPTest.__init__(self, methodName=methodName) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4315 ThreadableTest.__init__(self) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4316 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4317 def clientSetUp(self): |
|
58114
b0386fe650c7
Merged revisions 77263-77264 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
56367
diff
changeset
|
4318 self.source_port = support.find_unused_port() |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4319 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4320 def clientTearDown(self): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4321 self.cli.close() |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4322 self.cli = None |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4323 ThreadableTest.clientTearDown(self) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4324 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4325 def _justAccept(self): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4326 conn, addr = self.serv.accept() |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
4327 conn.close() |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4328 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4329 testFamily = _justAccept |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4330 def _testFamily(self): |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
4331 self.cli = socket.create_connection((HOST, self.port), timeout=30) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
4332 self.addCleanup(self.cli.close) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4333 self.assertEqual(self.cli.family, 2) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4334 |
|
58136
ecc8a45894c9
Merged revisions 77286 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58114
diff
changeset
|
4335 testSourceAddress = _justAccept |
|
ecc8a45894c9
Merged revisions 77286 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58114
diff
changeset
|
4336 def _testSourceAddress(self): |
|
58114
b0386fe650c7
Merged revisions 77263-77264 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
56367
diff
changeset
|
4337 self.cli = socket.create_connection((HOST, self.port), timeout=30, |
|
b0386fe650c7
Merged revisions 77263-77264 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
56367
diff
changeset
|
4338 source_address=('', self.source_port)) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
4339 self.addCleanup(self.cli.close) |
|
58114
b0386fe650c7
Merged revisions 77263-77264 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
56367
diff
changeset
|
4340 self.assertEqual(self.cli.getsockname()[1], self.source_port) |
|
58136
ecc8a45894c9
Merged revisions 77286 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58114
diff
changeset
|
4341 # The port number being used is sufficient to show that the bind() |
|
ecc8a45894c9
Merged revisions 77286 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58114
diff
changeset
|
4342 # call happened. |
|
58114
b0386fe650c7
Merged revisions 77263-77264 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
56367
diff
changeset
|
4343 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4344 testTimeoutDefault = _justAccept |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4345 def _testTimeoutDefault(self): |
|
47559
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4346 # passing no explicit timeout uses socket's global default |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
4347 self.assertTrue(socket.getdefaulttimeout() is None) |
|
47559
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4348 socket.setdefaulttimeout(42) |
|
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4349 try: |
|
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4350 self.cli = socket.create_connection((HOST, self.port)) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
4351 self.addCleanup(self.cli.close) |
|
47559
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4352 finally: |
|
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4353 socket.setdefaulttimeout(None) |
|
66340
2beb25369289
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
65926
diff
changeset
|
4354 self.assertEqual(self.cli.gettimeout(), 42) |
|
47559
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4355 |
|
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4356 testTimeoutNone = _justAccept |
|
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4357 def _testTimeoutNone(self): |
|
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4358 # None timeout means the same as sock.settimeout(None) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
4359 self.assertTrue(socket.getdefaulttimeout() is None) |
|
47559
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4360 socket.setdefaulttimeout(30) |
|
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4361 try: |
|
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4362 self.cli = socket.create_connection((HOST, self.port), timeout=None) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
4363 self.addCleanup(self.cli.close) |
|
47559
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4364 finally: |
|
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4365 socket.setdefaulttimeout(None) |
|
2925b568aacc
Merged revisions 63562,63570,63728,63734,63784,63788,63802,63817,63827,63839,63887,63975,63998 via svnmerge from
Georg Brandl <georg@python.org>
parents:
47318
diff
changeset
|
4366 self.assertEqual(self.cli.gettimeout(), None) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4367 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4368 testTimeoutValueNamed = _justAccept |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4369 def _testTimeoutValueNamed(self): |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
4370 self.cli = socket.create_connection((HOST, self.port), timeout=30) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4371 self.assertEqual(self.cli.gettimeout(), 30) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4372 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4373 testTimeoutValueNonamed = _justAccept |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4374 def _testTimeoutValueNonamed(self): |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
4375 self.cli = socket.create_connection((HOST, self.port), 30) |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
4376 self.addCleanup(self.cli.close) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4377 self.assertEqual(self.cli.gettimeout(), 30) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4378 |
|
61073
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
4379 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4380 class NetworkConnectionBehaviourTest(SocketTCPTest, ThreadableTest): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4381 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4382 def __init__(self, methodName='runTest'): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4383 SocketTCPTest.__init__(self, methodName=methodName) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4384 ThreadableTest.__init__(self) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4385 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4386 def clientSetUp(self): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4387 pass |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4388 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4389 def clientTearDown(self): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4390 self.cli.close() |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4391 self.cli = None |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4392 ThreadableTest.clientTearDown(self) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4393 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4394 def testInsideTimeout(self): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4395 conn, addr = self.serv.accept() |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
4396 self.addCleanup(conn.close) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4397 time.sleep(3) |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
4398 conn.send(b"done!") |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4399 testOutsideTimeout = testInsideTimeout |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4400 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4401 def _testInsideTimeout(self): |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
4402 self.cli = sock = socket.create_connection((HOST, self.port)) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4403 data = sock.recv(5) |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
4404 self.assertEqual(data, b"done!") |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4405 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4406 def _testOutsideTimeout(self): |
|
46370
2e917b0c8f6e
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46262
diff
changeset
|
4407 self.cli = sock = socket.create_connection((HOST, self.port), timeout=1) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
4408 self.assertRaises(socket.timeout, lambda: sock.recv(5)) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4409 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
4410 |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4411 class TCPTimeoutTest(SocketTCPTest): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4412 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4413 def testTCPTimeout(self): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4414 def raise_timeout(*args, **kwargs): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4415 self.serv.settimeout(1.0) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4416 self.serv.accept() |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
4417 self.assertRaises(socket.timeout, raise_timeout, |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4418 "Error generating a timeout exception (TCP)") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4419 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4420 def testTimeoutZero(self): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4421 ok = False |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4422 try: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4423 self.serv.settimeout(0.0) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4424 foo = self.serv.accept() |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4425 except socket.timeout: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4426 self.fail("caught timeout instead of error (TCP)") |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4427 except OSError: |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4428 ok = True |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4429 except: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4430 self.fail("caught unexpected exception (TCP)") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4431 if not ok: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4432 self.fail("accept() returned success when we did not expect it") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4433 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4434 def testInterruptedTimeout(self): |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4435 # XXX I don't know how to do this test on MSWindows or any other |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4436 # plaform that doesn't support signal.alarm() or os.kill(), though |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4437 # the bug should have existed on all platforms. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4438 if not hasattr(signal, "alarm"): |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4439 return # can only test on *nix |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4440 self.serv.settimeout(5.0) # must be longer than alarm |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4441 class Alarm(Exception): |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4442 pass |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4443 def alarm_handler(signal, frame): |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4444 raise Alarm |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4445 old_alarm = signal.signal(signal.SIGALRM, alarm_handler) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4446 try: |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4447 signal.alarm(2) # POSIX allows alarm to be up to 1 second early |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4448 try: |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4449 foo = self.serv.accept() |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4450 except socket.timeout: |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4451 self.fail("caught timeout instead of Alarm") |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4452 except Alarm: |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4453 pass |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4454 except: |
|
46161
848160d10780
Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44782
diff
changeset
|
4455 self.fail("caught other exception instead of Alarm:" |
|
848160d10780
Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44782
diff
changeset
|
4456 " %s(%s):\n%s" % |
|
848160d10780
Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44782
diff
changeset
|
4457 (sys.exc_info()[:2] + (traceback.format_exc(),))) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4458 else: |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4459 self.fail("nothing caught") |
|
46161
848160d10780
Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44782
diff
changeset
|
4460 finally: |
|
848160d10780
Merged revisions 61981,61984-61987,61992-61993,61997-62000 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44782
diff
changeset
|
4461 signal.alarm(0) # shut off alarm |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4462 except Alarm: |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4463 self.fail("got Alarm in wrong place") |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4464 finally: |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4465 # no alarm can be pending. Safe to restore old handler. |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4466 signal.signal(signal.SIGALRM, old_alarm) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
4467 |
|
73612
b410bcd300a1
#11112: Fix typo in a base class in test_socket.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
72586
diff
changeset
|
4468 class UDPTimeoutTest(SocketUDPTest): |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4469 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4470 def testUDPTimeout(self): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4471 def raise_timeout(*args, **kwargs): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4472 self.serv.settimeout(1.0) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4473 self.serv.recv(1024) |
|
55593
0bb232078b8c
Merged revisions 73715 via svnmerge from
Georg Brandl <georg@python.org>
parents:
51579
diff
changeset
|
4474 self.assertRaises(socket.timeout, raise_timeout, |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4475 "Error generating a timeout exception (UDP)") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4476 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4477 def testTimeoutZero(self): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4478 ok = False |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4479 try: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4480 self.serv.settimeout(0.0) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4481 foo = self.serv.recv(1024) |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4482 except socket.timeout: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4483 self.fail("caught timeout instead of error (UDP)") |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4484 except OSError: |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4485 ok = True |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4486 except: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4487 self.fail("caught unexpected exception (UDP)") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4488 if not ok: |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4489 self.fail("recv() returned success when we did not expect it") |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4490 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4491 class TestExceptions(unittest.TestCase): |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4492 |
|
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4493 def testExceptionTree(self): |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4494 self.assertTrue(issubclass(OSError, Exception)) |
|
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4495 self.assertTrue(issubclass(socket.herror, OSError)) |
|
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4496 self.assertTrue(issubclass(socket.gaierror, OSError)) |
|
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4497 self.assertTrue(issubclass(socket.timeout, OSError)) |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4498 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
4499 class TestLinuxAbstractNamespace(unittest.TestCase): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
4500 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
4501 UNIX_PATH_MAX = 108 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
4502 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
4503 def testLinuxAbstractNamespace(self): |
| 42596 | 4504 address = b"\x00python-test-hello\x00\xff" |
|
67299
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4505 with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s1: |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4506 s1.bind(address) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4507 s1.listen(1) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4508 with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s2: |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4509 s2.connect(s1.getsockname()) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4510 with s1.accept()[0] as s3: |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4511 self.assertEqual(s1.getsockname(), address) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4512 self.assertEqual(s2.getpeername(), address) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
4513 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
4514 def testMaxName(self): |
| 42596 | 4515 address = b"\x00" + b"h" * (self.UNIX_PATH_MAX - 1) |
|
67299
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4516 with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4517 s.bind(address) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4518 self.assertEqual(s.getsockname(), address) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
4519 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
4520 def testNameOverflow(self): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
4521 address = "\x00" + "h" * self.UNIX_PATH_MAX |
|
67299
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4522 with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4523 self.assertRaises(OSError, s.bind, address) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
4524 |
|
73998
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4525 def testStrName(self): |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4526 # Check that an abstract name can be passed as a string. |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4527 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4528 try: |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4529 s.bind("\x00python\x00test\x00") |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4530 self.assertEqual(s.getsockname(), b"\x00python\x00test\x00") |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4531 finally: |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4532 s.close() |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4533 |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4534 class TestUnixDomain(unittest.TestCase): |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4535 |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4536 def setUp(self): |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4537 self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4538 |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4539 def tearDown(self): |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4540 self.sock.close() |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4541 |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4542 def encoded(self, path): |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4543 # Return the given path encoded in the file system encoding, |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4544 # or skip the test if this is not possible. |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4545 try: |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4546 return os.fsencode(path) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4547 except UnicodeEncodeError: |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4548 self.skipTest( |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4549 "Pathname {0!a} cannot be represented in file " |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4550 "system encoding {1!r}".format( |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4551 path, sys.getfilesystemencoding())) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4552 |
|
73999
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4553 def bind(self, sock, path): |
|
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4554 # Bind the socket |
|
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4555 try: |
|
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4556 sock.bind(path) |
|
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4557 except OSError as e: |
|
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4558 if str(e) == "AF_UNIX path too long": |
|
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4559 self.skipTest( |
|
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4560 "Pathname {0!a} is too long to serve as a AF_UNIX path" |
|
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4561 .format(path)) |
|
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4562 else: |
|
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4563 raise |
|
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4564 |
|
73998
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4565 def testStrAddr(self): |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4566 # Test binding to and retrieving a normal string pathname. |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4567 path = os.path.abspath(support.TESTFN) |
|
73999
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4568 self.bind(self.sock, path) |
|
73998
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4569 self.addCleanup(support.unlink, path) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4570 self.assertEqual(self.sock.getsockname(), path) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4571 |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4572 def testBytesAddr(self): |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4573 # Test binding to a bytes pathname. |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4574 path = os.path.abspath(support.TESTFN) |
|
73999
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4575 self.bind(self.sock, self.encoded(path)) |
|
73998
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4576 self.addCleanup(support.unlink, path) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4577 self.assertEqual(self.sock.getsockname(), path) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4578 |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4579 def testSurrogateescapeBind(self): |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4580 # Test binding to a valid non-ASCII pathname, with the |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4581 # non-ASCII bytes supplied using surrogateescape encoding. |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4582 path = os.path.abspath(support.TESTFN_UNICODE) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4583 b = self.encoded(path) |
|
73999
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4584 self.bind(self.sock, b.decode("ascii", "surrogateescape")) |
|
73998
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4585 self.addCleanup(support.unlink, path) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4586 self.assertEqual(self.sock.getsockname(), path) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4587 |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4588 def testUnencodableAddr(self): |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4589 # Test binding to a pathname that cannot be encoded in the |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4590 # file system encoding. |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4591 if support.TESTFN_UNENCODABLE is None: |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4592 self.skipTest("No unencodable filename available") |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4593 path = os.path.abspath(support.TESTFN_UNENCODABLE) |
|
73999
fb887a9ce2c9
Skip test if the path is too long for a AF_UNIX socket
Antoine Pitrou <solipsis@pitrou.net>
parents:
73998
diff
changeset
|
4594 self.bind(self.sock, path) |
|
73998
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4595 self.addCleanup(support.unlink, path) |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
4596 self.assertEqual(self.sock.getsockname(), path) |
|
29662
1308d7ec9953
SF patch #760257: add socket.timeout exception
Raymond Hettinger <python@rcn.com>
parents:
29087
diff
changeset
|
4597 |
|
61073
493bb4585e38
Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59677
diff
changeset
|
4598 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4599 class BufferIOTest(SocketConnectedTest): |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4600 """ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4601 Test the buffer versions of socket.recv() and socket.send(). |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4602 """ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4603 def __init__(self, methodName='runTest'): |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4604 SocketConnectedTest.__init__(self, methodName=methodName) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4605 |
|
59677
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4606 def testRecvIntoArray(self): |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4607 buf = bytearray(1024) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4608 nbytes = self.cli_conn.recv_into(buf) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4609 self.assertEqual(nbytes, len(MSG)) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4610 msg = buf[:len(MSG)] |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4611 self.assertEqual(msg, MSG) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4612 |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4613 def _testRecvIntoArray(self): |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4614 buf = bytes(MSG) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4615 self.serv_conn.send(buf) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4616 |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4617 def testRecvIntoBytearray(self): |
|
48623
bf50085fbcd3
#2538: bytes objects can only provide read-only buffers
Antoine Pitrou <solipsis@pitrou.net>
parents:
47615
diff
changeset
|
4618 buf = bytearray(1024) |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
4619 nbytes = self.cli_conn.recv_into(buf) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4620 self.assertEqual(nbytes, len(MSG)) |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
4621 msg = buf[:len(MSG)] |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4622 self.assertEqual(msg, MSG) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4623 |
|
59677
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4624 _testRecvIntoBytearray = _testRecvIntoArray |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4625 |
|
59677
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4626 def testRecvIntoMemoryview(self): |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4627 buf = bytearray(1024) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4628 nbytes = self.cli_conn.recv_into(memoryview(buf)) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4629 self.assertEqual(nbytes, len(MSG)) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4630 msg = buf[:len(MSG)] |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4631 self.assertEqual(msg, MSG) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4632 |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4633 _testRecvIntoMemoryview = _testRecvIntoArray |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4634 |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4635 def testRecvFromIntoArray(self): |
|
48623
bf50085fbcd3
#2538: bytes objects can only provide read-only buffers
Antoine Pitrou <solipsis@pitrou.net>
parents:
47615
diff
changeset
|
4636 buf = bytearray(1024) |
|
38673
a19c20c5e5c7
Merge the rest of the trunk.
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
4637 nbytes, addr = self.cli_conn.recvfrom_into(buf) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4638 self.assertEqual(nbytes, len(MSG)) |
|
41809
8e062e572ea4
Sockets facelift. APIs that could return binary data (e.g. aton() and
Guido van Rossum <guido@python.org>
parents:
41770
diff
changeset
|
4639 msg = buf[:len(MSG)] |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4640 self.assertEqual(msg, MSG) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4641 |
|
59677
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4642 def _testRecvFromIntoArray(self): |
|
41770
651fa2c9c2ab
Make test_socket pass. There was an unchecked error when a Unicode
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
4643 buf = bytes(MSG) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4644 self.serv_conn.send(buf) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
4645 |
|
59677
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4646 def testRecvFromIntoBytearray(self): |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4647 buf = bytearray(1024) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4648 nbytes, addr = self.cli_conn.recvfrom_into(buf) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4649 self.assertEqual(nbytes, len(MSG)) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4650 msg = buf[:len(MSG)] |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4651 self.assertEqual(msg, MSG) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4652 |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4653 _testRecvFromIntoBytearray = _testRecvFromIntoArray |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4654 |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4655 def testRecvFromIntoMemoryview(self): |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4656 buf = bytearray(1024) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4657 nbytes, addr = self.cli_conn.recvfrom_into(memoryview(buf)) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4658 self.assertEqual(nbytes, len(MSG)) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4659 msg = buf[:len(MSG)] |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4660 self.assertEqual(msg, MSG) |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4661 |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4662 _testRecvFromIntoMemoryview = _testRecvFromIntoArray |
|
d62ca1eaccb9
NOTE: just porting tests here.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59522
diff
changeset
|
4663 |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4664 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4665 TIPC_STYPE = 2000 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4666 TIPC_LOWER = 200 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4667 TIPC_UPPER = 210 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4668 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4669 def isTipcAvailable(): |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4670 """Check if the TIPC module is loaded |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4671 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4672 The TIPC module is not loaded automatically on Ubuntu and probably |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4673 other Linux distros. |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4674 """ |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4675 if not hasattr(socket, "AF_TIPC"): |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4676 return False |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4677 if not os.path.isfile("/proc/modules"): |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4678 return False |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4679 with open("/proc/modules") as f: |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4680 for line in f: |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4681 if line.startswith("tipc "): |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4682 return True |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46899
diff
changeset
|
4683 if support.verbose: |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4684 print("TIPC module is not loaded, please 'sudo modprobe tipc'") |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4685 return False |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4686 |
|
72586
77397669c62f
Fix ResourceWarnings in the TIPC socket tests.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72448
diff
changeset
|
4687 class TIPCTest(unittest.TestCase): |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4688 def testRDM(self): |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4689 srv = socket.socket(socket.AF_TIPC, socket.SOCK_RDM) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4690 cli = socket.socket(socket.AF_TIPC, socket.SOCK_RDM) |
|
72586
77397669c62f
Fix ResourceWarnings in the TIPC socket tests.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72448
diff
changeset
|
4691 self.addCleanup(srv.close) |
|
77397669c62f
Fix ResourceWarnings in the TIPC socket tests.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72448
diff
changeset
|
4692 self.addCleanup(cli.close) |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4693 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4694 srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4695 srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4696 TIPC_LOWER, TIPC_UPPER) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4697 srv.bind(srvaddr) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4698 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4699 sendaddr = (socket.TIPC_ADDR_NAME, TIPC_STYPE, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4700 TIPC_LOWER + int((TIPC_UPPER - TIPC_LOWER) / 2), 0) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4701 cli.sendto(MSG, sendaddr) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4702 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4703 msg, recvaddr = srv.recvfrom(1024) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4704 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4705 self.assertEqual(cli.getsockname(), recvaddr) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4706 self.assertEqual(msg, MSG) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4707 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4708 |
|
72586
77397669c62f
Fix ResourceWarnings in the TIPC socket tests.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72448
diff
changeset
|
4709 class TIPCThreadableTest(unittest.TestCase, ThreadableTest): |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4710 def __init__(self, methodName = 'runTest'): |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4711 unittest.TestCase.__init__(self, methodName = methodName) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4712 ThreadableTest.__init__(self) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4713 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4714 def setUp(self): |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4715 self.srv = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM) |
|
72586
77397669c62f
Fix ResourceWarnings in the TIPC socket tests.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72448
diff
changeset
|
4716 self.addCleanup(self.srv.close) |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4717 self.srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4718 srvaddr = (socket.TIPC_ADDR_NAMESEQ, TIPC_STYPE, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4719 TIPC_LOWER, TIPC_UPPER) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4720 self.srv.bind(srvaddr) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4721 self.srv.listen(5) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4722 self.serverExplicitReady() |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4723 self.conn, self.connaddr = self.srv.accept() |
|
72586
77397669c62f
Fix ResourceWarnings in the TIPC socket tests.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72448
diff
changeset
|
4724 self.addCleanup(self.conn.close) |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4725 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4726 def clientSetUp(self): |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4727 # The is a hittable race between serverExplicitReady() and the |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4728 # accept() call; sleep a little while to avoid it, otherwise |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4729 # we could get an exception |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4730 time.sleep(0.1) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4731 self.cli = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM) |
|
72586
77397669c62f
Fix ResourceWarnings in the TIPC socket tests.
Antoine Pitrou <solipsis@pitrou.net>
parents:
72448
diff
changeset
|
4732 self.addCleanup(self.cli.close) |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4733 addr = (socket.TIPC_ADDR_NAME, TIPC_STYPE, |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4734 TIPC_LOWER + int((TIPC_UPPER - TIPC_LOWER) / 2), 0) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4735 self.cli.connect(addr) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4736 self.cliaddr = self.cli.getsockname() |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4737 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4738 def testStream(self): |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4739 msg = self.conn.recv(1024) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4740 self.assertEqual(msg, MSG) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4741 self.assertEqual(self.cliaddr, self.connaddr) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4742 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4743 def _testStream(self): |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4744 self.cli.send(MSG) |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4745 self.cli.close() |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4746 |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
4747 |
|
64574
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4748 @unittest.skipUnless(thread, 'Threading required for this test.') |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4749 class ContextManagersTest(ThreadedTCPSocketTest): |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4750 |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4751 def _testSocketClass(self): |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4752 # base test |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4753 with socket.socket() as sock: |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4754 self.assertFalse(sock._closed) |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4755 self.assertTrue(sock._closed) |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4756 # close inside with block |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4757 with socket.socket() as sock: |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4758 sock.close() |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4759 self.assertTrue(sock._closed) |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4760 # exception inside with block |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4761 with socket.socket() as sock: |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4762 self.assertRaises(OSError, sock.sendall, b'foo') |
|
64574
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4763 self.assertTrue(sock._closed) |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4764 |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4765 def testCreateConnectionBase(self): |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4766 conn, addr = self.serv.accept() |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
4767 self.addCleanup(conn.close) |
|
64574
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4768 data = conn.recv(1024) |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4769 conn.sendall(data) |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4770 |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4771 def _testCreateConnectionBase(self): |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4772 address = self.serv.getsockname() |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4773 with socket.create_connection(address) as sock: |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4774 self.assertFalse(sock._closed) |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4775 sock.sendall(b'foo') |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4776 self.assertEqual(sock.recv(1024), b'foo') |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4777 self.assertTrue(sock._closed) |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4778 |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4779 def testCreateConnectionClose(self): |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4780 conn, addr = self.serv.accept() |
|
65882
889fd8ecbff4
Clean up ResourceWarnings due to unclosed sockets.
Brian Curtin <brian.curtin@gmail.com>
parents:
65707
diff
changeset
|
4781 self.addCleanup(conn.close) |
|
64574
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4782 data = conn.recv(1024) |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4783 conn.sendall(data) |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4784 |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4785 def _testCreateConnectionClose(self): |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4786 address = self.serv.getsockname() |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4787 with socket.create_connection(address) as sock: |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4788 sock.close() |
|
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4789 self.assertTrue(sock._closed) |
|
80933
50d19c2fac82
Issue #16717: get rid of socket.error, replace with OSError
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
80889
diff
changeset
|
4790 self.assertRaises(OSError, sock.sendall, b'foo') |
|
64574
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4791 |
|
65604
8d7f18332db7
Fix SOCK_CLOEXEC and SOCK_NONBLOCK tests on recent glibcs with old Linux kernels.
Antoine Pitrou <solipsis@pitrou.net>
parents:
65416
diff
changeset
|
4792 |
|
85420
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4793 class InheritanceTest(unittest.TestCase): |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4794 @unittest.skipUnless(hasattr(socket, "SOCK_CLOEXEC"), |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4795 "SOCK_CLOEXEC not defined") |
|
70612
277bbe6cae53
Issue #12196: Make test.support's requires_linux_version a decorator.
Charles-François Natali <neologix@free.fr>
parents:
70324
diff
changeset
|
4796 @support.requires_linux_version(2, 6, 28) |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4797 def test_SOCK_CLOEXEC(self): |
|
67299
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4798 with socket.socket(socket.AF_INET, |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4799 socket.SOCK_STREAM | socket.SOCK_CLOEXEC) as s: |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4800 self.assertTrue(s.type & socket.SOCK_CLOEXEC) |
|
85432
2cb26c67a55a
Fix test_socket.test_SOCK_CLOEXEC(), the test was wrong
Victor Stinner <vstinner@wyplay.com>
parents:
85420
diff
changeset
|
4801 self.assertFalse(s.get_inheritable()) |
|
85420
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4802 |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4803 def test_default_inheritable(self): |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4804 sock = socket.socket() |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4805 with sock: |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4806 self.assertEqual(sock.get_inheritable(), False) |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4807 |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4808 def test_dup(self): |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4809 sock = socket.socket() |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4810 with sock: |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4811 newsock = sock.dup() |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4812 sock.close() |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4813 with newsock: |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4814 self.assertEqual(newsock.get_inheritable(), False) |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4815 |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4816 def test_set_inheritable(self): |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4817 sock = socket.socket() |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4818 with sock: |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4819 sock.set_inheritable(True) |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4820 self.assertEqual(sock.get_inheritable(), True) |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4821 |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4822 sock.set_inheritable(False) |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4823 self.assertEqual(sock.get_inheritable(), False) |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4824 |
|
85624
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4825 @unittest.skipIf(fcntl is None, "need fcntl") |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4826 def test_get_inheritable_cloexec(self): |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4827 sock = socket.socket() |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4828 with sock: |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4829 fd = sock.fileno() |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4830 self.assertEqual(sock.get_inheritable(), False) |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4831 |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4832 # clear FD_CLOEXEC flag |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4833 flags = fcntl.fcntl(fd, fcntl.F_GETFD) |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4834 flags &= ~fcntl.FD_CLOEXEC |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4835 fcntl.fcntl(fd, fcntl.F_SETFD, flags) |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4836 |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4837 self.assertEqual(sock.get_inheritable(), True) |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4838 |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4839 @unittest.skipIf(fcntl is None, "need fcntl") |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4840 def test_set_inheritable_cloexec(self): |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4841 sock = socket.socket() |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4842 with sock: |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4843 fd = sock.fileno() |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4844 self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC, |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4845 fcntl.FD_CLOEXEC) |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4846 |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4847 sock.set_inheritable(True) |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4848 self.assertEqual(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC, |
|
aea58e1cae75
Issue #18904: test_os and test_socket use unittest.skipIf() to check if fcntl
Victor Stinner <victor.stinner@gmail.com>
parents:
85619
diff
changeset
|
4849 0) |
|
85619
b7f6f6f59e91
Issue #18904: test_socket: add inheritance tests using fcntl and FD_CLOEXEC
Victor Stinner <victor.stinner@gmail.com>
parents:
85481
diff
changeset
|
4850 |
|
b7f6f6f59e91
Issue #18904: test_socket: add inheritance tests using fcntl and FD_CLOEXEC
Victor Stinner <victor.stinner@gmail.com>
parents:
85481
diff
changeset
|
4851 |
|
85420
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4852 @unittest.skipUnless(hasattr(socket, "socketpair"), |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4853 "need socket.socketpair()") |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4854 def test_socketpair(self): |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4855 s1, s2 = socket.socketpair() |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4856 self.addCleanup(s1.close) |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4857 self.addCleanup(s2.close) |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4858 self.assertEqual(s1.get_inheritable(), False) |
|
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
4859 self.assertEqual(s2.get_inheritable(), False) |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4860 |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4861 |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4862 @unittest.skipUnless(hasattr(socket, "SOCK_NONBLOCK"), |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4863 "SOCK_NONBLOCK not defined") |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4864 class NonblockConstantTest(unittest.TestCase): |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4865 def checkNonblock(self, s, nonblock=True, timeout=0.0): |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4866 if nonblock: |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4867 self.assertTrue(s.type & socket.SOCK_NONBLOCK) |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4868 self.assertEqual(s.gettimeout(), timeout) |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4869 else: |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4870 self.assertFalse(s.type & socket.SOCK_NONBLOCK) |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4871 self.assertEqual(s.gettimeout(), None) |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4872 |
|
70612
277bbe6cae53
Issue #12196: Make test.support's requires_linux_version a decorator.
Charles-François Natali <neologix@free.fr>
parents:
70324
diff
changeset
|
4873 @support.requires_linux_version(2, 6, 28) |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4874 def test_SOCK_NONBLOCK(self): |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4875 # a lot of it seems silly and redundant, but I wanted to test that |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4876 # changing back and forth worked ok |
|
67299
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4877 with socket.socket(socket.AF_INET, |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4878 socket.SOCK_STREAM | socket.SOCK_NONBLOCK) as s: |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4879 self.checkNonblock(s) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4880 s.setblocking(1) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4881 self.checkNonblock(s, False) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4882 s.setblocking(0) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4883 self.checkNonblock(s) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4884 s.settimeout(None) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4885 self.checkNonblock(s, False) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4886 s.settimeout(2.0) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4887 self.checkNonblock(s, timeout=2.0) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4888 s.setblocking(1) |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4889 self.checkNonblock(s, False) |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4890 # defaulttimeout |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4891 t = socket.getdefaulttimeout() |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4892 socket.setdefaulttimeout(0.0) |
|
67299
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4893 with socket.socket() as s: |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4894 self.checkNonblock(s) |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4895 socket.setdefaulttimeout(None) |
|
67299
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4896 with socket.socket() as s: |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4897 self.checkNonblock(s, False) |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4898 socket.setdefaulttimeout(2.0) |
|
67299
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4899 with socket.socket() as s: |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4900 self.checkNonblock(s, timeout=2.0) |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4901 socket.setdefaulttimeout(None) |
|
67299
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4902 with socket.socket() as s: |
|
6cb7ed7b6697
test_socket: use context managers to close directly the socket
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66799
diff
changeset
|
4903 self.checkNonblock(s, False) |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4904 socket.setdefaulttimeout(t) |
|
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
4905 |
|
64574
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
4906 |
|
76150
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4907 @unittest.skipUnless(os.name == "nt", "Windows specific") |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4908 @unittest.skipUnless(multiprocessing, "need multiprocessing") |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4909 class TestSocketSharing(SocketTCPTest): |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4910 # This must be classmethod and not staticmethod or multiprocessing |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4911 # won't be able to bootstrap it. |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4912 @classmethod |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4913 def remoteProcessServer(cls, q): |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4914 # Recreate socket from shared data |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4915 sdata = q.get() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4916 message = q.get() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4917 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4918 s = socket.fromshare(sdata) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4919 s2, c = s.accept() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4920 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4921 # Send the message |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4922 s2.sendall(message) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4923 s2.close() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4924 s.close() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4925 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4926 def testShare(self): |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4927 # Transfer the listening server socket to another process |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4928 # and service it from there. |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4929 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4930 # Create process: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4931 q = multiprocessing.Queue() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4932 p = multiprocessing.Process(target=self.remoteProcessServer, args=(q,)) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4933 p.start() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4934 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4935 # Get the shared socket data |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4936 data = self.serv.share(p.pid) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4937 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4938 # Pass the shared socket to the other process |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4939 addr = self.serv.getsockname() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4940 self.serv.close() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4941 q.put(data) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4942 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4943 # The data that the server will send us |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4944 message = b"slapmahfro" |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4945 q.put(message) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4946 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4947 # Connect |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4948 s = socket.create_connection(addr) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4949 # listen for the data |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4950 m = [] |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4951 while True: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4952 data = s.recv(100) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4953 if not data: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4954 break |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4955 m.append(data) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4956 s.close() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4957 received = b"".join(m) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4958 self.assertEqual(received, message) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4959 p.join() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4960 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4961 def testShareLength(self): |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4962 data = self.serv.share(os.getpid()) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4963 self.assertRaises(ValueError, socket.fromshare, data[:-1]) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4964 self.assertRaises(ValueError, socket.fromshare, data+b"foo") |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4965 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4966 def compareSockets(self, org, other): |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4967 # socket sharing is expected to work only for blocking socket |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4968 # since the internal python timout value isn't transfered. |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4969 self.assertEqual(org.gettimeout(), None) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4970 self.assertEqual(org.gettimeout(), other.gettimeout()) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4971 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4972 self.assertEqual(org.family, other.family) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4973 self.assertEqual(org.type, other.type) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4974 # If the user specified "0" for proto, then |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4975 # internally windows will have picked the correct value. |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4976 # Python introspection on the socket however will still return |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4977 # 0. For the shared socket, the python value is recreated |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4978 # from the actual value, so it may not compare correctly. |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4979 if org.proto != 0: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4980 self.assertEqual(org.proto, other.proto) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4981 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4982 def testShareLocal(self): |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4983 data = self.serv.share(os.getpid()) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4984 s = socket.fromshare(data) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4985 try: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4986 self.compareSockets(self.serv, s) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4987 finally: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4988 s.close() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4989 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4990 def testTypes(self): |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4991 families = [socket.AF_INET, socket.AF_INET6] |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4992 types = [socket.SOCK_STREAM, socket.SOCK_DGRAM] |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4993 for f in families: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4994 for t in types: |
|
76157
9b858096044e
Issue #14310: Catch testing errors when trying to create unsupported socket
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76150
diff
changeset
|
4995 try: |
|
9b858096044e
Issue #14310: Catch testing errors when trying to create unsupported socket
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76150
diff
changeset
|
4996 source = socket.socket(f, t) |
|
9b858096044e
Issue #14310: Catch testing errors when trying to create unsupported socket
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76150
diff
changeset
|
4997 except OSError: |
|
9b858096044e
Issue #14310: Catch testing errors when trying to create unsupported socket
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76150
diff
changeset
|
4998 continue # This combination is not supported |
|
76150
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
4999 try: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
5000 data = source.share(os.getpid()) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
5001 shared = socket.fromshare(data) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
5002 try: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
5003 self.compareSockets(source, shared) |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
5004 finally: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
5005 shared.close() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
5006 finally: |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
5007 source.close() |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
5008 |
|
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
5009 |
|
24451
22570e76cca1
Enable test_socket again, if only to prevent mistakes like Jeremy
Guido van Rossum <guido@python.org>
parents:
24450
diff
changeset
|
5010 def test_main(): |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
5011 tests = [GeneralModuleTests, BasicTCPTest, TCPCloserTest, TCPTimeoutTest, |
|
61259
1f7506f23771
Remove traces of MacOS9 support.
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
61073
diff
changeset
|
5012 TestExceptions, BufferIOTest, BasicTCPTest2, BasicUDPTest, UDPTimeoutTest ] |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
5013 |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
5014 tests.extend([ |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
5015 NonBlockingTCPTests, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
5016 FileObjectClassTestCase, |
|
58146
efbac7d3a368
Merged revisions 74426 via svnmerge from
Gregory P. Smith <greg@mad-scientist.com>
parents:
58136
diff
changeset
|
5017 FileObjectInterruptedTestCase, |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
5018 UnbufferedFileObjectClassTestCase, |
|
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
5019 LineBufferedFileObjectClassTestCase, |
|
40737
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40644
diff
changeset
|
5020 SmallBufferedFileObjectClassTestCase, |
|
65259
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
5021 UnicodeReadFileObjectClassTestCase, |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
5022 UnicodeWriteFileObjectClassTestCase, |
|
3619c1214007
Merged revisions 85420 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64961
diff
changeset
|
5023 UnicodeReadWriteFileObjectClassTestCase, |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
5024 NetworkConnectionNoServer, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
5025 NetworkConnectionAttributesTest, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
5026 NetworkConnectionBehaviourTest, |
|
64574
caf0b4b0569e
Fix issue 9794: adds context manager protocol to socket.socket so that socket.create_connection() can be used with the 'with' statement.
Giampaolo Rodolà <g.rodola@gmail.com>
parents:
64534
diff
changeset
|
5027 ContextManagersTest, |
|
85420
ef889c3d5dc6
Issue #18571: Implementation of the PEP 446: file descriptors and file handles
Victor Stinner <victor.stinner@gmail.com>
parents:
85361
diff
changeset
|
5028 InheritanceTest, |
|
65314
12442ac3f7dd
Issue #7523: Add SOCK_CLOEXEC and SOCK_NONBLOCK to the socket module,
Antoine Pitrou <solipsis@pitrou.net>
parents:
65258
diff
changeset
|
5029 NonblockConstantTest |
|
28917
1741af48fd9f
Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents:
28833
diff
changeset
|
5030 ]) |
|
33063
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
5031 if hasattr(socket, "socketpair"): |
|
90da70986407
Patch #1003700: Add socketpair function to socket module.
Dave Cole <djc@object-craft.com.au>
parents:
32630
diff
changeset
|
5032 tests.append(BasicSocketPairTest) |
|
73998
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
5033 if hasattr(socket, "AF_UNIX"): |
|
1f23bb74f4bc
Issue #8373: The filesystem path of AF_UNIX sockets now uses the filesystem
Antoine Pitrou <solipsis@pitrou.net>
parents:
73613
diff
changeset
|
5034 tests.append(TestUnixDomain) |
|
72011
b5ccdf7c032a
Issue #12326: refactor usage of sys.platform
Victor Stinner <victor.stinner@haypocalc.com>
parents:
71897
diff
changeset
|
5035 if sys.platform == 'linux': |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
35453
diff
changeset
|
5036 tests.append(TestLinuxAbstractNamespace) |
|
44568
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
5037 if isTipcAvailable(): |
|
305d7d2ce047
Copied doc for reload() from trunk's function.rst to imp.rst
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
5038 tests.append(TIPCTest) |
|
44587
fb5a6330f71b
Merged revisions 59822-59841 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44568
diff
changeset
|
5039 tests.append(TIPCThreadableTest) |
|
72758
e767318baccd
Issue #10141: socket: add SocketCAN (PF_CAN) support. Initial patch by Matthias
Charles-François Natali <neologix@free.fr>
parents:
72619
diff
changeset
|
5040 tests.extend([BasicCANTest, CANTest]) |
|
73478
2293ca739223
Issue #7777: socket: Add Reliable Datagram Sockets (PF_RDS) support.
Charles-François Natali <neologix@free.fr>
parents:
73085
diff
changeset
|
5041 tests.extend([BasicRDSTest, RDSTest]) |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5042 tests.extend([ |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5043 CmsgMacroTests, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5044 SendmsgUDPTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5045 RecvmsgUDPTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5046 RecvmsgIntoUDPTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5047 SendmsgUDP6Test, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5048 RecvmsgUDP6Test, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5049 RecvmsgRFC3542AncillaryUDP6Test, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5050 RecvmsgIntoRFC3542AncillaryUDP6Test, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5051 RecvmsgIntoUDP6Test, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5052 SendmsgTCPTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5053 RecvmsgTCPTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5054 RecvmsgIntoTCPTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5055 SendmsgSCTPStreamTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5056 RecvmsgSCTPStreamTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5057 RecvmsgIntoSCTPStreamTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5058 SendmsgUnixStreamTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5059 RecvmsgUnixStreamTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5060 RecvmsgIntoUnixStreamTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5061 RecvmsgSCMRightsStreamTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5062 RecvmsgIntoSCMRightsStreamTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5063 # These are slow when setitimer() is not available |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5064 InterruptedRecvTimeoutTest, |
|
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5065 InterruptedSendTimeoutTest, |
|
76150
51b4bddd0e92
Issue #14310: inter-process socket duplication for windows
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
76034
diff
changeset
|
5066 TestSocketSharing, |
|
72029
c64216addd7f
Add support for the send/recvmsg API to the socket module. Patch by David Watson and Heiko Wundram. (Closes #6560)
Nick Coghlan <ncoghlan@gmail.com>
parents:
72011
diff
changeset
|
5067 ]) |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38673
diff
changeset
|
5068 |
|
47201
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46899
diff
changeset
|
5069 thread_info = support.threading_setup() |
|
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46899
diff
changeset
|
5070 support.run_unittest(*tests) |
|
9c930a32cebb
#2621 rename test.test_support to test.support
Benjamin Peterson <benjamin@python.org>
parents:
46899
diff
changeset
|
5071 support.threading_cleanup(*thread_info) |
|
23790
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
5072 |
|
486f4045d13d
New test suite for the socket module by Michael Gilfix.
Guido van Rossum <guido@python.org>
parents:
23715
diff
changeset
|
5073 if __name__ == "__main__": |
|
24451
22570e76cca1
Enable test_socket again, if only to prevent mistakes like Jeremy
Guido van Rossum <guido@python.org>
parents:
24450
diff
changeset
|
5074 test_main() |
