aboutsummaryrefslogtreecommitdiff
path: root/examples/python2.7/patches/revert-issue14635.diff
blob: 47a2bdd75dc87a8030265e7553312b7afe4624e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
diff -urN a/Lib/telnetlib.py b/Lib/telnetlib.py
--- a/Lib/telnetlib.py	2012-12-25 13:41:08.467405725 +0100
+++ b/Lib/telnetlib.py	2012-12-25 14:00:31.339404759 +0100
@@ -34,7 +34,6 @@
 
 
 # Imported modules
-import errno
 import sys
 import socket
 import select
@@ -206,7 +205,6 @@
         self.sb = 0 # flag for SB and SE sequence.
         self.sbdataq = ''
         self.option_callback = None
-        self._has_poll = hasattr(select, 'poll')
         if host is not None:
             self.open(host, port, timeout)
 
@@ -289,61 +287,6 @@
         is closed and no cooked data is available.
 
         """
-        if self._has_poll:
-            return self._read_until_with_poll(match, timeout)
-        else:
-            return self._read_until_with_select(match, timeout)
-
-    def _read_until_with_poll(self, match, timeout):
-        """Read until a given string is encountered or until timeout.
-
-        This method uses select.poll() to implement the timeout.
-        """
-        n = len(match)
-        call_timeout = timeout
-        if timeout is not None:
-            from time import time
-            time_start = time()
-        self.process_rawq()
-        i = self.cookedq.find(match)
-        if i < 0:
-            poller = select.poll()
-            poll_in_or_priority_flags = select.POLLIN | select.POLLPRI
-            poller.register(self, poll_in_or_priority_flags)
-            while i < 0 and not self.eof:
-                try:
-                    ready = poller.poll(call_timeout)
-                except select.error as e:
-                    if e.errno == errno.EINTR:
-                        if timeout is not None:
-                            elapsed = time() - time_start
-                            call_timeout = timeout-elapsed
-                        continue
-                    raise
-                for fd, mode in ready:
-                    if mode & poll_in_or_priority_flags:
-                        i = max(0, len(self.cookedq)-n)
-                        self.fill_rawq()
-                        self.process_rawq()
-                        i = self.cookedq.find(match, i)
-                if timeout is not None:
-                    elapsed = time() - time_start
-                    if elapsed >= timeout:
-                        break
-                    call_timeout = timeout-elapsed
-            poller.unregister(self)
-        if i >= 0:
-            i = i + n
-            buf = self.cookedq[:i]
-            self.cookedq = self.cookedq[i:]
-            return buf
-        return self.read_very_lazy()
-
-    def _read_until_with_select(self, match, timeout=None):
-        """Read until a given string is encountered or until timeout.
-
-        The timeout is implemented using select.select().
-        """
         n = len(match)
         self.process_rawq()
         i = self.cookedq.find(match)
@@ -646,79 +589,6 @@
         results are undeterministic, and may depend on the I/O timing.
 
         """
-        if self._has_poll:
-            return self._expect_with_poll(list, timeout)
-        else:
-            return self._expect_with_select(list, timeout)
-
-    def _expect_with_poll(self, expect_list, timeout=None):
-        """Read until one from a list of a regular expressions matches.
-
-        This method uses select.poll() to implement the timeout.
-        """
-        re = None
-        expect_list = expect_list[:]
-        indices = range(len(expect_list))
-        for i in indices:
-            if not hasattr(expect_list[i], "search"):
-                if not re: import re
-                expect_list[i] = re.compile(expect_list[i])
-        call_timeout = timeout
-        if timeout is not None:
-            from time import time
-            time_start = time()
-        self.process_rawq()
-        m = None
-        for i in indices:
-            m = expect_list[i].search(self.cookedq)
-            if m:
-                e = m.end()
-                text = self.cookedq[:e]
-                self.cookedq = self.cookedq[e:]
-                break
-        if not m:
-            poller = select.poll()
-            poll_in_or_priority_flags = select.POLLIN | select.POLLPRI
-            poller.register(self, poll_in_or_priority_flags)
-            while not m and not self.eof:
-                try:
-                    ready = poller.poll(call_timeout)
-                except select.error as e:
-                    if e.errno == errno.EINTR:
-                        if timeout is not None:
-                            elapsed = time() - time_start
-                            call_timeout = timeout-elapsed
-                        continue
-                    raise
-                for fd, mode in ready:
-                    if mode & poll_in_or_priority_flags:
-                        self.fill_rawq()
-                        self.process_rawq()
-                        for i in indices:
-                            m = expect_list[i].search(self.cookedq)
-                            if m:
-                                e = m.end()
-                                text = self.cookedq[:e]
-                                self.cookedq = self.cookedq[e:]
-                                break
-                if timeout is not None:
-                    elapsed = time() - time_start
-                    if elapsed >= timeout:
-                        break
-                    call_timeout = timeout-elapsed
-            poller.unregister(self)
-        if m:
-            return (i, m, text)
-        text = self.read_very_lazy()
-        if not text and self.eof:
-            raise EOFError
-        return (-1, None, text)
-
-    def _expect_with_select(self, list, timeout=None):
-        """Read until one from a list of a regular expressions matches.
-
-        The timeout is implemented using select.select().
-        """
         re = None
         list = list[:]
         indices = range(len(list))
diff -urN a/Lib/test/test_telnetlib.py b/Lib/test/test_telnetlib.py
--- a/Lib/test/test_telnetlib.py	2012-12-25 13:41:08.499405725 +0100
+++ b/Lib/test/test_telnetlib.py	2012-12-25 14:00:31.339404759 +0100
@@ -136,28 +136,6 @@
         self.assertEqual(data, want[0])
         self.assertEqual(telnet.read_all(), 'not seen')
 
-    def test_read_until_with_poll(self):
-        """Use select.poll() to implement telnet.read_until()."""
-        want = ['x' * 10, 'match', 'y' * 10, EOF_sigil]
-        self.dataq.put(want)
-        telnet = telnetlib.Telnet(HOST, self.port)
-        if not telnet._has_poll:
-            raise unittest.SkipTest('select.poll() is required')
-        telnet._has_poll = True
-        self.dataq.join()
-        data = telnet.read_until('match')
-        self.assertEqual(data, ''.join(want[:-2]))
-
-    def test_read_until_with_select(self):
-        """Use select.select() to implement telnet.read_until()."""
-        want = ['x' * 10, 'match', 'y' * 10, EOF_sigil]
-        self.dataq.put(want)
-        telnet = telnetlib.Telnet(HOST, self.port)
-        telnet._has_poll = False
-        self.dataq.join()
-        data = telnet.read_until('match')
-        self.assertEqual(data, ''.join(want[:-2]))
-
     def test_read_all_A(self):
         """
         read_all()
@@ -380,75 +358,8 @@
         self.assertEqual('', telnet.read_sb_data())
         nego.sb_getter = None # break the nego => telnet cycle
 
-
-class ExpectTests(TestCase):
-    def setUp(self):
-        self.evt = threading.Event()
-        self.dataq = Queue.Queue()
-        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        self.sock.settimeout(10)
-        self.port = test_support.bind_port(self.sock)
-        self.thread = threading.Thread(target=server, args=(self.evt,self.sock,
-                                                            self.dataq))
-        self.thread.start()
-        self.evt.wait()
-
-    def tearDown(self):
-        self.thread.join()
-
-    # use a similar approach to testing timeouts as test_timeout.py
-    # these will never pass 100% but make the fuzz big enough that it is rare
-    block_long = 0.6
-    block_short = 0.3
-    def test_expect_A(self):
-        """
-        expect(expected, [timeout])
-          Read until the expected string has been seen, or a timeout is
-          hit (default is no timeout); may block.
-        """
-        want = ['x' * 10, 'match', 'y' * 10, EOF_sigil]
-        self.dataq.put(want)
-        telnet = telnetlib.Telnet(HOST, self.port)
-        self.dataq.join()
-        (_,_,data) = telnet.expect(['match'])
-        self.assertEqual(data, ''.join(want[:-2]))
-
-    def test_expect_B(self):
-        # test the timeout - it does NOT raise socket.timeout
-        want = ['hello', self.block_long, 'not seen', EOF_sigil]
-        self.dataq.put(want)
-        telnet = telnetlib.Telnet(HOST, self.port)
-        self.dataq.join()
-        (_,_,data) = telnet.expect(['not seen'], self.block_short)
-        self.assertEqual(data, want[0])
-        self.assertEqual(telnet.read_all(), 'not seen')
-
-    def test_expect_with_poll(self):
-        """Use select.poll() to implement telnet.expect()."""
-        want = ['x' * 10, 'match', 'y' * 10, EOF_sigil]
-        self.dataq.put(want)
-        telnet = telnetlib.Telnet(HOST, self.port)
-        if not telnet._has_poll:
-            raise unittest.SkipTest('select.poll() is required')
-        telnet._has_poll = True
-        self.dataq.join()
-        (_,_,data) = telnet.expect(['match'])
-        self.assertEqual(data, ''.join(want[:-2]))
-
-    def test_expect_with_select(self):
-        """Use select.select() to implement telnet.expect()."""
-        want = ['x' * 10, 'match', 'y' * 10, EOF_sigil]
-        self.dataq.put(want)
-        telnet = telnetlib.Telnet(HOST, self.port)
-        telnet._has_poll = False
-        self.dataq.join()
-        (_,_,data) = telnet.expect(['match'])
-        self.assertEqual(data, ''.join(want[:-2]))
-
-
 def test_main(verbose=None):
-    test_support.run_unittest(GeneralTests, ReadTests, OptionTests,
-                              ExpectTests)
+    test_support.run_unittest(GeneralTests, ReadTests, OptionTests)
 
 if __name__ == '__main__':
     test_main()
diff -urN a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS	2012-12-25 13:48:09.675405378 +0100
+++ b/Misc/ACKS	2012-12-25 14:00:31.339404759 +0100
@@ -372,7 +372,6 @@
 Albert Hofkamp
 Tomas Hoger
 Jonathan Hogg
-Akintayo Holder
 Gerrit Holl
 Shane Holloway
 Rune Holm
diff -urN a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS	2012-12-25 13:48:48.947405345 +0100
+++ b/Misc/NEWS	2012-12-25 14:00:31.347404759 +0100
@@ -123,9 +123,6 @@
 - Issue #6493: An issue in ctypes on Windows that caused structure bitfields
   of type ctypes.c_uint32 and width 32 to incorrectly be set has been fixed.
 
-- Issue #14635: telnetlib will use poll() rather than select() when possible
-  to avoid failing due to the select() file descriptor limit.
-
 - Issue #15247: FileIO now raises an error when given a file descriptor
   pointing to a directory.