[Python-checkins] python/dist/src/Lib/test test_urllib.py, 1.14,
1.15
perky at users.sourceforge.net
perky at users.sourceforge.net
Sat Jun 5 09:30:58 EDT 2004
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23584/Lib/test
Modified Files:
test_urllib.py
Log Message:
Fix a bug that robotparser starves memory when the server responses
in HTTP/0.9 due to dissonance of httplib.LineAndFileWrapper and
urllib.addbase.
Index: test_urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_urllib.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** test_urllib.py 12 May 2003 20:19:37 -0000 1.14
--- test_urllib.py 5 Jun 2004 13:30:56 -0000 1.15
***************
*** 2,9 ****
--- 2,11 ----
import urllib
+ import httplib
import unittest
from test import test_support
import os
import mimetools
+ import StringIO
def hexescape(char):
***************
*** 89,92 ****
--- 91,125 ----
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"""
***************
*** 411,414 ****
--- 444,448 ----
test_support.run_unittest(
urlopen_FileTests,
+ urlopen_HttpTests,
urlretrieve_FileTests,
QuotingTests,
More information about the Python-checkins
mailing list