summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_urllib.py49
-rw-r--r--Lib/test/test_urllib2.py1
2 files changed, 28 insertions, 22 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index 0a82cb7..c18e738 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -3,12 +3,12 @@
import collections
import urllib
import httplib
+import io
import unittest
import os
import sys
import mimetools
import tempfile
-import StringIO
from test import test_support
from base64 import b64encode
@@ -22,37 +22,42 @@ def hexescape(char):
return "%" + hex_repr
-class FakeHTTPMixin(object):
- def fakehttp(self, fakedata):
- class FakeSocket(StringIO.StringIO):
+def fakehttp(fakedata):
+ class FakeSocket(io.BytesIO):
+
+ def sendall(self, data):
+ FakeHTTPConnection.buf = data
- def sendall(self, data):
- FakeHTTPConnection.buf = data
+ def makefile(self, *args, **kwds):
+ return self
- def makefile(self, *args, **kwds):
- return self
+ def read(self, amt=None):
+ if self.closed:
+ return b""
+ return io.BytesIO.read(self, amt)
- def read(self, amt=None):
- if self.closed:
- return ""
- return StringIO.StringIO.read(self, amt)
+ def readline(self, length=None):
+ if self.closed:
+ return b""
+ return io.BytesIO.readline(self, length)
- def readline(self, length=None):
- if self.closed:
- return ""
- return StringIO.StringIO.readline(self, length)
+ class FakeHTTPConnection(httplib.HTTPConnection):
- class FakeHTTPConnection(httplib.HTTPConnection):
+ # buffer to store data for verification in urlopen tests.
+ buf = ""
+ fakesock = FakeSocket(fakedata)
- # buffer to store data for verification in urlopen tests.
- buf = ""
+ def connect(self):
+ self.sock = self.fakesock
- def connect(self):
- self.sock = FakeSocket(fakedata)
+ return FakeHTTPConnection
+
+class FakeHTTPMixin(object):
+ def fakehttp(self, fakedata):
assert httplib.HTTP._connection_class == httplib.HTTPConnection
- httplib.HTTP._connection_class = FakeHTTPConnection
+ httplib.HTTP._connection_class = fakehttp(fakedata)
def unfakehttp(self):
httplib.HTTP._connection_class = httplib.HTTPConnection
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index a6889cc..30c3d2b 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -1,5 +1,6 @@
import unittest
from test import test_support
+from test import test_urllib
import os
import socket