merge with 3.3
authorGeorg Brandl <georg@python.org>
Mon, 10 Feb 2014 21:11:21 +0000 (22:11 +0100)
committerGeorg Brandl <georg@python.org>
Mon, 10 Feb 2014 21:11:21 +0000 (22:11 +0100)
.hgtags
Doc/tools/sphinxext/susp-ignored.csv
Lib/idlelib/NEWS.txt
Lib/smtplib.py
Lib/test/mock_socket.py
Lib/test/test_smtplib.py

diff --git a/.hgtags b/.hgtags
index 979e8ad7e15b459942c1959b4cb7ce96f0f5c978..2d5c42ba87cfb8177f10bb07a95cb61c4fbf6d5b 100644 (file)
--- a/.hgtags
+++ b/.hgtags
@@ -118,6 +118,8 @@ d047928ae3f6314a13b6137051315453d0ae89b6 v3.3.2
 fd53c500f8b80f54f3ecedec9da2e8c7e52a6888 v3.3.3rc1
 d32442c0e60dfbd71234e807d3d1dedd227495a9 v3.3.3rc2
 c3896275c0f61b2510a6c7e6c458a750359a91b8 v3.3.3
+fa92f5f940c6c0d839d7f0611e4b717606504a3c v3.3.4rc1
+7ff62415e4263c432c8acf6e424224209211eadb v3.3.4
 46535f65e7f3bcdcf176f36d34bc1fed719ffd2b v3.4.0a1
 9265a2168e2cb2a84785d8717792acc661e6b692 v3.4.0a2
 dd9cdf90a5073510877e9dd5112f8e6cf20d5e89 v3.4.0a3
index 1769023941ecdf1facad453ab6793c71383d1da3..f9d6bbfa57211f05a42557850adcddef7911aa9d 100644 (file)
@@ -282,3 +282,4 @@ whatsnew/changelog,,:PythonCmd,"With Tk < 8.5 _tkinter.c:PythonCmd() raised Unic
 whatsnew/changelog,,::,": Fix FTP tests for IPv6, bind to ""::1"" instead of ""localhost""."
 whatsnew/changelog,,::,": Use ""127.0.0.1"" or ""::1"" instead of ""localhost"" as much as"
 whatsnew/changelog,,:password,user:password
+whatsnew/changelog,,:gz,w:gz
index 478c18337ee5217c1378dfeaaae58f4b00de744c..953a38dcda23b8a0f0f9f829a4ea3cc8fa4f9cd5 100644 (file)
@@ -875,4 +875,3 @@ What's New in IDLEfork 0.9 Alpha 1?
 --------------------------------------------------------------------
 Refer to HISTORY.txt for additional information on earlier releases.
 --------------------------------------------------------------------
-
index 796b86612247e7f43f32ba89af14a66e7b760874..66b5879defdca1f3dec0839db6211d8d6541d313 100755 (executable)
@@ -62,6 +62,7 @@ SMTP_PORT = 25
 SMTP_SSL_PORT = 465
 CRLF = "\r\n"
 bCRLF = b"\r\n"
+_MAXLINE = 8192 # more than 8 times larger than RFC 821, 4.5.3
 
 OLDSTYLE_AUTH = re.compile(r"auth=(.*)", re.I)
 
@@ -365,7 +366,7 @@ class SMTP:
             self.file = self.sock.makefile('rb')
         while 1:
             try:
-                line = self.file.readline()
+                line = self.file.readline(_MAXLINE + 1)
             except OSError as e:
                 self.close()
                 raise SMTPServerDisconnected("Connection unexpectedly closed: "
@@ -375,6 +376,8 @@ class SMTP:
                 raise SMTPServerDisconnected("Connection unexpectedly closed")
             if self.debuglevel > 0:
                 print('reply:', repr(line), file=stderr)
+            if len(line) > _MAXLINE:
+                raise SMTPResponseException(500, "Line too long.")
             resp.append(line[4:].strip(b' \t\r\n'))
             code = line[:3]
             # Check that the error code is syntactically correct.
index 8ef0ec8c8dae61a03fc91c49daa385347bd84a9f..e36724f54bce0d52ec2af99d554d7ffc751855c2 100644 (file)
@@ -21,8 +21,13 @@ class MockFile:
     """
     def __init__(self, lines):
         self.lines = lines
-    def readline(self):
-        return self.lines.pop(0) + b'\r\n'
+    def readline(self, limit=-1):
+        result = self.lines.pop(0) + b'\r\n'
+        if limit >= 0:
+            # Re-insert the line, removing the \r\n we added.
+            self.lines.insert(0, result[limit:-2])
+            result = result[:limit]
+        return result
     def close(self):
         pass
 
index 39bf7ae3b49aabe6342c19f06ec59e857faea523..3f7b9b4175cc1deb6d3742aa5025b7ab3ac69b79 100644 (file)
@@ -563,6 +563,33 @@ class BadHELOServerTests(unittest.TestCase):
                             HOST, self.port, 'localhost', 3)
 
 
+@unittest.skipUnless(threading, 'Threading required for this test.')
+class TooLongLineTests(unittest.TestCase):
+    respdata = b'250 OK' + (b'.' * smtplib._MAXLINE * 2) + b'\n'
+
+    def setUp(self):
+        self.old_stdout = sys.stdout
+        self.output = io.StringIO()
+        sys.stdout = self.output
+
+        self.evt = threading.Event()
+        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        self.sock.settimeout(15)
+        self.port = support.bind_port(self.sock)
+        servargs = (self.evt, self.respdata, self.sock)
+        threading.Thread(target=server, args=servargs).start()
+        self.evt.wait()
+        self.evt.clear()
+
+    def tearDown(self):
+        self.evt.wait()
+        sys.stdout = self.old_stdout
+
+    def testLineTooLong(self):
+        self.assertRaises(smtplib.SMTPResponseException, smtplib.SMTP,
+                          HOST, self.port, 'localhost', 3)
+
+
 sim_users = {'Mr.A@somewhere.com':'John A',
              'Ms.B@xn--fo-fka.com':'Sally B',
              'Mrs.C@somewhereesle.com':'Ruth C',
@@ -888,7 +915,8 @@ class SMTPSimTests(unittest.TestCase):
 def test_main(verbose=None):
     support.run_unittest(GeneralTests, DebuggingServerTests,
                               NonConnectingTests,
-                              BadHELOServerTests, SMTPSimTests)
+                              BadHELOServerTests, SMTPSimTests,
+                              TooLongLineTests)
 
 if __name__ == '__main__':
     test_main()