summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2008-06-12 04:06:45 +0000
committerBarry Warsaw <barry@python.org>2008-06-12 04:06:45 +0000
commit67ff650a9245a7a225e0e7b5b1761bea1f99f57e (patch)
tree868598a4a26c5d5581a5196c55eb2da9eed1a71b /Lib/test
parentecced7d025f5f8e80fa34c56bc3e99bb1cbde661 (diff)
downloadcpython-67ff650a9245a7a225e0e7b5b1761bea1f99f57e.tar.gz
Patch for issue 2848, mostly by Humberto Diogenes, with a couple of
small fixes by Barry. This removes mimetools from the stdlib.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_http_cookiejar.py5
-rw-r--r--Lib/test/test_httpservers.py4
-rw-r--r--Lib/test/test_ssl.py2
-rw-r--r--Lib/test/test_urllib.py8
-rw-r--r--Lib/test/test_urllib2.py6
-rw-r--r--Lib/test/test_urllib2_localnet.py8
-rw-r--r--Lib/test/test_urllib2net.py1
-rw-r--r--Lib/test/test_urllibnet.py12
-rw-r--r--Lib/test/test_xmlrpc.py14
9 files changed, 30 insertions, 30 deletions
diff --git a/Lib/test/test_http_cookiejar.py b/Lib/test/test_http_cookiejar.py
index 09fb0c65bb..c130190933 100644
--- a/Lib/test/test_http_cookiejar.py
+++ b/Lib/test/test_http_cookiejar.py
@@ -193,9 +193,8 @@ class FakeResponse:
"""
headers: list of RFC822-style 'Key: value' strings
"""
- import mimetools, io
- f = io.StringIO("\n".join(headers))
- self._headers = mimetools.Message(f)
+ import email
+ self._headers = email.message_from_string("\n".join(headers))
self._url = url
def info(self): return self._headers
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index 02be57a3b2..94c6a3d121 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -19,12 +19,14 @@ import threading
import unittest
from test import support
-
class NoLogRequestHandler:
def log_message(self, *args):
# don't write log messages to stderr
pass
+ def read(self, n=None):
+ return ''
+
class TestServerThread(threading.Thread):
def __init__(self, test_object, request_handler):
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 33419fe541..619161eb85 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -944,7 +944,7 @@ else:
url = 'https://%s:%d/%s' % (
HOST, server.port, os.path.split(CERTFILE)[1])
f = urllib.urlopen(url)
- dlen = f.info().getheader("content-length")
+ dlen = f.info().get("content-length")
if dlen and (int(dlen) > 0):
d2 = f.read(int(dlen))
if support.verbose:
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index 26b51cb77c..2b41cad0ce 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -2,11 +2,11 @@
import urllib
import http.client
+import email.message
import io
import unittest
from test import support
import os
-import mimetools
import tempfile
def hexescape(char):
@@ -78,7 +78,7 @@ class urlopen_FileTests(unittest.TestCase):
self.returned_obj.close()
def test_info(self):
- self.assert_(isinstance(self.returned_obj.info(), mimetools.Message))
+ self.assert_(isinstance(self.returned_obj.info(), email.message.Message))
def test_geturl(self):
self.assertEqual(self.returned_obj.geturl(), self.pathname)
@@ -206,8 +206,8 @@ class urlretrieve_FileTests(unittest.TestCase):
# a headers value is returned.
result = urllib.urlretrieve("file:%s" % support.TESTFN)
self.assertEqual(result[0], support.TESTFN)
- self.assert_(isinstance(result[1], mimetools.Message),
- "did not get a mimetools.Message instance as second "
+ self.assert_(isinstance(result[1], email.message.Message),
+ "did not get a email.message.Message instance as second "
"returned value")
def test_copy(self):
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index c2d594b400..6bcb17ee64 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -349,18 +349,18 @@ class MockHTTPHandler(urllib2.BaseHandler):
self._count = 0
self.requests = []
def http_open(self, req):
- import mimetools, http.client, copy
+ import email, http.client, copy
from io import StringIO
self.requests.append(copy.deepcopy(req))
if self._count == 0:
self._count = self._count + 1
name = http.client.responses[self.code]
- msg = mimetools.Message(StringIO(self.headers))
+ msg = email.message_from_string(self.headers)
return self.parent.error(
"http", req, MockFile(), self.code, name, msg)
else:
self.req = req
- msg = mimetools.Message(StringIO("\r\n\r\n"))
+ msg = email.message_from_string("\r\n\r\n")
return MockResponse(200, "OK", msg, "", req.get_full_url())
class MockPasswordManager:
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py
index 6c877d925b..d3016c3b71 100644
--- a/Lib/test/test_urllib2_localnet.py
+++ b/Lib/test/test_urllib2_localnet.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import mimetools
+import email
import threading
import urlparse
import urllib2
@@ -443,10 +443,10 @@ class TestUrlopen(unittest.TestCase):
try:
open_url = urllib2.urlopen("http://localhost:%s" % handler.port)
info_obj = open_url.info()
- self.assert_(isinstance(info_obj, mimetools.Message),
+ self.assert_(isinstance(info_obj, email.message.Message),
"object returned by 'info' is not an instance of "
- "mimetools.Message")
- self.assertEqual(info_obj.getsubtype(), "plain")
+ "email.message.Message")
+ self.assertEqual(info_obj.get_content_subtype(), "plain")
finally:
self.server.stop()
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py
index 1c4af18d97..938ab9ffca 100644
--- a/Lib/test/test_urllib2net.py
+++ b/Lib/test/test_urllib2net.py
@@ -8,7 +8,6 @@ import socket
import urllib2
import sys
import os
-import mimetools
def _retry_thrice(func, exc, *args, **kwargs):
diff --git a/Lib/test/test_urllibnet.py b/Lib/test/test_urllibnet.py
index 6c2632c55a..d4831d8708 100644
--- a/Lib/test/test_urllibnet.py
+++ b/Lib/test/test_urllibnet.py
@@ -7,7 +7,7 @@ import socket
import urllib
import sys
import os
-import mimetools
+import email.message
def _open_with_retry(func, host, *args, **kwargs):
@@ -87,10 +87,10 @@ class urlopenNetworkTests(unittest.TestCase):
info_obj = open_url.info()
finally:
open_url.close()
- self.assert_(isinstance(info_obj, mimetools.Message),
+ self.assert_(isinstance(info_obj, email.message.Message),
"object returned by 'info' is not an instance of "
- "mimetools.Message")
- self.assertEqual(info_obj.getsubtype(), "html")
+ "email.message.Message")
+ self.assertEqual(info_obj.get_content_subtype(), "html")
def test_geturl(self):
# Make sure same URL as opened is returned by geturl.
@@ -180,8 +180,8 @@ class urlretrieveNetworkTests(unittest.TestCase):
# Make sure header returned as 2nd value from urlretrieve is good.
file_location, header = self.urlretrieve("http://www.python.org/")
os.unlink(file_location)
- self.assert_(isinstance(header, mimetools.Message),
- "header is not an instance of mimetools.Message")
+ self.assert_(isinstance(header, email.message.Message),
+ "header is not an instance of email.message.Message")
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index b9103fa73c..9d38470033 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -6,7 +6,6 @@ import unittest
import xmlrpc.client as xmlrpclib
import xmlrpc.server
import threading
-import mimetools
import http.client
import socket
import os
@@ -452,12 +451,12 @@ class SimpleServerTestCase(unittest.TestCase):
# This is a contrived way to make a failure occur on the server side
# in order to test the _send_traceback_header flag on the server
-class FailingMessageClass(mimetools.Message):
- def __getitem__(self, key):
+class FailingMessageClass(http.client.HTTPMessage):
+ def get(self, key, failobj=None):
key = key.lower()
if key == 'content-length':
return 'I am broken'
- return mimetools.Message.__getitem__(self, key)
+ return super().get(key, failobj)
class FailingServerTestCase(unittest.TestCase):
@@ -477,7 +476,8 @@ class FailingServerTestCase(unittest.TestCase):
# reset flag
xmlrpc.server.SimpleXMLRPCServer._send_traceback_header = False
# reset message class
- xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = mimetools.Message
+ default_class = http.client.HTTPMessage
+ xmlrpc.server.SimpleXMLRPCRequestHandler.MessageClass = default_class
def test_basic(self):
# check that flag is false by default
@@ -529,8 +529,8 @@ class FailingServerTestCase(unittest.TestCase):
if not is_unavailable_exception(e) and hasattr(e, "headers"):
# We should get error info in the response
expected_err = "invalid literal for int() with base 10: 'I am broken'"
- self.assertEqual(e.headers.get("x-exception"), expected_err)
- self.assertTrue(e.headers.get("x-traceback") is not None)
+ self.assertEqual(e.headers.get("X-exception"), expected_err)
+ self.assertTrue(e.headers.get("X-traceback") is not None)
else:
self.fail('ProtocolError not raised')