##// END OF EJS Templates
compat: use email in favor of mimetools
Alejandro Santos -
r9034:8429062d default
parent child Browse files
Show More
@@ -208,7 +208,7 b' class FileRangeHandler(urllib2.FileHandl'
208 """
208 """
209 def open_local_file(self, req):
209 def open_local_file(self, req):
210 import mimetypes
210 import mimetypes
211 import mimetools
211 import email
212 host = req.get_host()
212 host = req.get_host()
213 file = req.get_selector()
213 file = req.get_selector()
214 localfile = urllib.url2pathname(file)
214 localfile = urllib.url2pathname(file)
@@ -232,9 +232,9 b' class FileRangeHandler(urllib2.FileHandl'
232 raise RangeError('Requested Range Not Satisfiable')
232 raise RangeError('Requested Range Not Satisfiable')
233 size = (lb - fb)
233 size = (lb - fb)
234 fo = RangeableFileObject(fo, (fb, lb))
234 fo = RangeableFileObject(fo, (fb, lb))
235 headers = mimetools.Message(StringIO(
235 headers = email.message_from_string(
236 'Content-Type: %s\nContent-Length: %d\nLast-Modified: %s\n' %
236 'Content-Type: %s\nContent-Length: %d\nLast-Modified: %s\n' %
237 (mtype or 'text/plain', size, modified)))
237 (mtype or 'text/plain', size, modified))
238 return urllib.addinfourl(fo, headers, 'file:'+file)
238 return urllib.addinfourl(fo, headers, 'file:'+file)
239
239
240
240
@@ -251,7 +251,7 b' import ftplib'
251 import socket
251 import socket
252 import sys
252 import sys
253 import mimetypes
253 import mimetypes
254 import mimetools
254 import email
255
255
256 class FTPRangeHandler(urllib2.FTPHandler):
256 class FTPRangeHandler(urllib2.FTPHandler):
257 def ftp_open(self, req):
257 def ftp_open(self, req):
@@ -325,8 +325,7 b' class FTPRangeHandler(urllib2.FTPHandler'
325 headers += "Content-Type: %s\n" % mtype
325 headers += "Content-Type: %s\n" % mtype
326 if retrlen is not None and retrlen >= 0:
326 if retrlen is not None and retrlen >= 0:
327 headers += "Content-Length: %d\n" % retrlen
327 headers += "Content-Length: %d\n" % retrlen
328 sf = StringIO(headers)
328 headers = email.message_from_string(headers)
329 headers = mimetools.Message(sf)
330 return addinfourl(fp, headers, req.get_full_url())
329 return addinfourl(fp, headers, req.get_full_url())
331 except ftplib.all_errors, msg:
330 except ftplib.all_errors, msg:
332 raise IOError('ftp error', msg), sys.exc_info()[2]
331 raise IOError('ftp error', msg), sys.exc_info()[2]
General Comments 0
You need to be logged in to leave comments. Login now