compat: use email in favor of mimetools
authorAlejandro Santos <alejolp@alejolp.com>
Sun, 05 Jul 2009 11:04:55 +0200
changeset 9034 8429062de8d3
parent 9033 98a5652bfed9
child 9035 8e34f363dd77
compat: use email in favor of mimetools
mercurial/byterange.py
--- a/mercurial/byterange.py	Sun Jul 05 11:04:31 2009 +0200
+++ b/mercurial/byterange.py	Sun Jul 05 11:04:55 2009 +0200
@@ -208,7 +208,7 @@
     """
     def open_local_file(self, req):
         import mimetypes
-        import mimetools
+        import email
         host = req.get_host()
         file = req.get_selector()
         localfile = urllib.url2pathname(file)
@@ -232,9 +232,9 @@
                 raise RangeError('Requested Range Not Satisfiable')
             size = (lb - fb)
             fo = RangeableFileObject(fo, (fb, lb))
-        headers = mimetools.Message(StringIO(
+        headers = email.message_from_string(
             'Content-Type: %s\nContent-Length: %d\nLast-Modified: %s\n' %
-            (mtype or 'text/plain', size, modified)))
+            (mtype or 'text/plain', size, modified))
         return urllib.addinfourl(fo, headers, 'file:'+file)
 
 
@@ -251,7 +251,7 @@
 import socket
 import sys
 import mimetypes
-import mimetools
+import email
 
 class FTPRangeHandler(urllib2.FTPHandler):
     def ftp_open(self, req):
@@ -325,8 +325,7 @@
                 headers += "Content-Type: %s\n" % mtype
             if retrlen is not None and retrlen >= 0:
                 headers += "Content-Length: %d\n" % retrlen
-            sf = StringIO(headers)
-            headers = mimetools.Message(sf)
+            headers = email.message_from_string(headers)
             return addinfourl(fp, headers, req.get_full_url())
         except ftplib.all_errors, msg:
             raise IOError('ftp error', msg), sys.exc_info()[2]