Stop using multifile and use email instead.

parent b5b32ac6
...@@ -178,9 +178,8 @@ class TestRequestRange(unittest.TestCase): ...@@ -178,9 +178,8 @@ class TestRequestRange(unittest.TestCase):
def expectMultipleRanges(self, range, sets, draft=0): def expectMultipleRanges(self, range, sets, draft=0):
import cStringIO import cStringIO
from mimetools import Message
from multifile import MultiFile
import re import re
import email
rangeParse = re.compile('bytes\s*(\d+)-(\d+)/(\d+)') rangeParse = re.compile('bytes\s*(\d+)-(\d+)/(\d+)')
req = self.app.REQUEST req = self.app.REQUEST
rsp = req.RESPONSE rsp = req.RESPONSE
...@@ -211,20 +210,16 @@ class TestRequestRange(unittest.TestCase): ...@@ -211,20 +210,16 @@ class TestRequestRange(unittest.TestCase):
# Decode the multipart message # Decode the multipart message
bodyfile = cStringIO.StringIO('Content-Type: %s\n\n%s' % ( bodyfile = cStringIO.StringIO('Content-Type: %s\n\n%s' % (
rsp.getHeader('content-type'), body)) rsp.getHeader('content-type'), body))
bodymessage = Message(bodyfile) partmessages = [part
partfiles = MultiFile(bodyfile) for part in email.message_from_file(bodyfile).walk()]
partfiles.push(bodymessage.getparam('boundary'))
partmessages = []
add = partmessages.append
while partfiles.next():
add(Message(cStringIO.StringIO(partfiles.read())))
# Check the different parts # Check the different parts
returnedRanges = [] returnedRanges = []
add = returnedRanges.append add = returnedRanges.append
for part in partmessages: for part in partmessages:
range = part['content-range'] if part.get_content_maintype() == 'multipart':
continue
range = part.get('content-range')
start, end, size = rangeParse.search(range).groups() start, end, size = rangeParse.search(range).groups()
start, end, size = int(start), int(end), int(size) start, end, size = int(start), int(end), int(size)
end = end + 1 end = end + 1
...@@ -233,13 +228,7 @@ class TestRequestRange(unittest.TestCase): ...@@ -233,13 +228,7 @@ class TestRequestRange(unittest.TestCase):
'Part Content-Range header reported incorrect length. ' 'Part Content-Range header reported incorrect length. '
'Expected %d, got %d.' % (len(self.data), size)) 'Expected %d, got %d.' % (len(self.data), size))
part.rewindbody() body = part.get_payload()
body = part.fp.read()
# Whotcha! Bug in MultiFile; the CRLF that is part of the boundary
# is returned as part of the body. Note that this bug is resolved
# in Python 2.2.
if body[-2:] == '\r\n':
body = body[:-2]
self.failIf(len(body) != end - start, self.failIf(len(body) != end - start,
'Part (%d, %d) is of wrong length, expected %d, got %d.' % ( 'Part (%d, %d) is of wrong length, expected %d, got %d.' % (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment