diff options
author | Hye-Shik Chang <hyeshik@gmail.com> | 2004-06-05 13:30:56 (GMT) |
---|---|---|
committer | Hye-Shik Chang <hyeshik@gmail.com> | 2004-06-05 13:30:56 (GMT) |
commit | 39aef79821d9ad8d428b14b59190bd0ca0c550d9 (patch) | |
tree | 5421d50fc7b9fb7e4e30d44d61d37a2954ed891f /Lib/test/test_urllib.py | |
parent | 5962f457b48997dbfb8bcb0769b57cd3fab96148 (diff) | |
download | cpython-39aef79821d9ad8d428b14b59190bd0ca0c550d9.zip cpython-39aef79821d9ad8d428b14b59190bd0ca0c550d9.tar.gz cpython-39aef79821d9ad8d428b14b59190bd0ca0c550d9.tar.bz2 |
Fix a bug that robotparser starves memory when the server responses
in HTTP/0.9 due to dissonance of httplib.LineAndFileWrapper and
urllib.addbase.
Diffstat (limited to 'Lib/test/test_urllib.py')
-rw-r--r-- | Lib/test/test_urllib.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 9cb4dd2..a7ada27 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -1,10 +1,12 @@ """Regresssion tests for urllib""" import urllib +import httplib import unittest from test import test_support import os import mimetools +import StringIO def hexescape(char): """Escape char as RFC 2396 specifies""" @@ -88,6 +90,37 @@ class urlopen_FileTests(unittest.TestCase): for line in self.returned_obj.__iter__(): self.assertEqual(line, self.text) +class urlopen_HttpTests(unittest.TestCase): + """Test urlopen() opening a fake http connection.""" + + def fakehttp(self, fakedata): + class FakeSocket(StringIO.StringIO): + def sendall(self, str): pass + def makefile(self, mode, name): return self + def read(self, amt=None): + if self.closed: return '' + return StringIO.StringIO.read(self, amt) + def readline(self, length=None): + if self.closed: return '' + return StringIO.StringIO.readline(self, length) + class FakeHTTPConnection(httplib.HTTPConnection): + def connect(self): + self.sock = FakeSocket(fakedata) + assert httplib.HTTP._connection_class == httplib.HTTPConnection + httplib.HTTP._connection_class = FakeHTTPConnection + + def unfakehttp(self): + httplib.HTTP._connection_class = httplib.HTTPConnection + + def test_read(self): + self.fakehttp('Hello!') + try: + fp = urllib.urlopen("http://python.org/") + self.assertEqual(fp.readline(), 'Hello!') + self.assertEqual(fp.readline(), '') + finally: + self.unfakehttp() + class urlretrieve_FileTests(unittest.TestCase): """Test urllib.urlretrieve() on local files""" @@ -410,6 +443,7 @@ class Pathname_Tests(unittest.TestCase): def test_main(): test_support.run_unittest( urlopen_FileTests, + urlopen_HttpTests, urlretrieve_FileTests, QuotingTests, UnquotingTests, |