mirror of
https://github.com/python/cpython.git
synced 2024-11-29 12:54:02 +08:00
f78e02b798
svn+ssh://pythondev@svn.python.org/python/trunk ........ r63562 | martin.v.loewis | 2008-05-23 17:06:50 +0200 (Fri, 23 May 2008) | 2 lines Patch #1722225: Support QNX 6. ........ r63570 | trent.nelson | 2008-05-23 22:33:14 +0200 (Fri, 23 May 2008) | 1 line Introduce a user macro named $(externalsDir), which should point to the root directory of where all the external sources should live. Developers can change this value if their external sources live elsewhere. The default of '..\..' matches the current status quo. ........ r63728 | gregory.p.smith | 2008-05-26 23:16:34 +0200 (Mon, 26 May 2008) | 4 lines Fix issue2589: there was a potential integer overflow leading to memory corruption on esoteric platforms and incorrect behavior on normal platforms. ........ r63734 | gregory.p.smith | 2008-05-27 00:07:28 +0200 (Tue, 27 May 2008) | 3 lines Fix issue2588: Do not execute str[size-1] = '\0' when a 0 size is passed in. (The assert won't prevent this in non-debug builds). ........ r63784 | raymond.hettinger | 2008-05-29 10:38:23 +0200 (Thu, 29 May 2008) | 1 line Fix two typos. ........ r63788 | facundo.batista | 2008-05-29 18:39:26 +0200 (Thu, 29 May 2008) | 6 lines Fixed the semantic of timeout for socket.create_connection and all the upper level libraries that use it, including urllib2. Added and fixed some tests, and changed docs correspondingly. Thanks to John J Lee for the patch and the pusing, :) ........ r63802 | mark.dickinson | 2008-05-30 04:46:53 +0200 (Fri, 30 May 2008) | 2 lines Fix typo in testSum ........ r63817 | raymond.hettinger | 2008-05-30 20:20:50 +0200 (Fri, 30 May 2008) | 8 lines * Mark intermedidate computes values (hi, lo, yr) as volatile. * Expand comments. * Swap variable names in the sum_exact code so that x and y are consistently chosen as the larger and smaller magnitude values respectively. ........ r63827 | raymond.hettinger | 2008-05-31 05:24:31 +0200 (Sat, 31 May 2008) | 1 line Implement heapq in terms of less-than (to match list.sort()). ........ r63839 | gerhard.haering | 2008-05-31 23:33:27 +0200 (Sat, 31 May 2008) | 2 lines Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance. ........ r63887 | gregory.p.smith | 2008-06-02 06:05:52 +0200 (Mon, 02 Jun 2008) | 4 lines Fix issue 2782: be less strict about the format string type in strftime. Accept unicode and anything else ParseTuple "s#" can deal with. This matches the time.strftime behavior. ........ r63975 | neal.norwitz | 2008-06-06 06:47:01 +0200 (Fri, 06 Jun 2008) | 3 lines Aldo Cortesi confirmed this is still needed for OpenBSD 4.2 and 4.3. (I didn't regen configure, since I don't have a working autoconf.) ........ r63998 | raymond.hettinger | 2008-06-06 23:47:51 +0200 (Fri, 06 Jun 2008) | 1 line Issue 3501: Make heapq support both __le__ and __lt__. ........
118 lines
3.1 KiB
Python
118 lines
3.1 KiB
Python
import socket
|
|
import threading
|
|
import ftplib
|
|
import time
|
|
|
|
from unittest import TestCase
|
|
from test import support
|
|
|
|
HOST = support.HOST
|
|
|
|
# This function sets the evt 3 times:
|
|
# 1) when the connection is ready to be accepted.
|
|
# 2) when it is safe for the caller to close the connection
|
|
# 3) when we have closed the socket
|
|
def server(evt, serv):
|
|
serv.listen(5)
|
|
|
|
# (1) Signal the caller that we are ready to accept the connection.
|
|
evt.set()
|
|
try:
|
|
conn, addr = serv.accept()
|
|
except socket.timeout:
|
|
pass
|
|
else:
|
|
conn.send(b"1 Hola mundo\n")
|
|
# (2) Signal the caller that it is safe to close the socket.
|
|
evt.set()
|
|
conn.close()
|
|
finally:
|
|
serv.close()
|
|
# (3) Signal the caller that we are done.
|
|
evt.set()
|
|
|
|
class GeneralTests(TestCase):
|
|
|
|
def setUp(self):
|
|
self.evt = threading.Event()
|
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
self.sock.settimeout(3)
|
|
self.port = support.bind_port(self.sock)
|
|
threading.Thread(target=server, args=(self.evt,self.sock)).start()
|
|
# Wait for the server to be ready.
|
|
self.evt.wait()
|
|
self.evt.clear()
|
|
ftplib.FTP.port = self.port
|
|
|
|
def tearDown(self):
|
|
self.evt.wait()
|
|
|
|
def testBasic(self):
|
|
# do nothing
|
|
ftplib.FTP()
|
|
|
|
# connects
|
|
ftp = ftplib.FTP(HOST)
|
|
self.evt.wait()
|
|
ftp.close()
|
|
|
|
def testTimeoutDefault(self):
|
|
# default -- use global socket timeout
|
|
self.assert_(socket.getdefaulttimeout() is None)
|
|
socket.setdefaulttimeout(30)
|
|
try:
|
|
ftp = ftplib.FTP("localhost")
|
|
finally:
|
|
socket.setdefaulttimeout(None)
|
|
self.assertEqual(ftp.sock.gettimeout(), 30)
|
|
self.evt.wait()
|
|
ftp.close()
|
|
|
|
def testTimeoutNone(self):
|
|
# no timeout -- do not use global socket timeout
|
|
self.assert_(socket.getdefaulttimeout() is None)
|
|
socket.setdefaulttimeout(30)
|
|
try:
|
|
ftp = ftplib.FTP("localhost", timeout=None)
|
|
finally:
|
|
socket.setdefaulttimeout(None)
|
|
self.assertTrue(ftp.sock.gettimeout() is None)
|
|
self.evt.wait()
|
|
ftp.close()
|
|
|
|
def testTimeoutValue(self):
|
|
# a value
|
|
ftp = ftplib.FTP(HOST, timeout=30)
|
|
self.assertEqual(ftp.sock.gettimeout(), 30)
|
|
self.evt.wait()
|
|
ftp.close()
|
|
|
|
def testTimeoutConnect(self):
|
|
ftp = ftplib.FTP()
|
|
ftp.connect(HOST, timeout=30)
|
|
self.assertEqual(ftp.sock.gettimeout(), 30)
|
|
self.evt.wait()
|
|
ftp.close()
|
|
|
|
def testTimeoutDifferentOrder(self):
|
|
ftp = ftplib.FTP(timeout=30)
|
|
ftp.connect(HOST)
|
|
self.assertEqual(ftp.sock.gettimeout(), 30)
|
|
self.evt.wait()
|
|
ftp.close()
|
|
|
|
def testTimeoutDirectAccess(self):
|
|
ftp = ftplib.FTP()
|
|
ftp.timeout = 30
|
|
ftp.connect(HOST)
|
|
self.assertEqual(ftp.sock.gettimeout(), 30)
|
|
self.evt.wait()
|
|
ftp.close()
|
|
|
|
|
|
def test_main(verbose=None):
|
|
support.run_unittest(GeneralTests)
|
|
|
|
if __name__ == '__main__':
|
|
test_main()
|