Commit 052969a6 authored by Guido van Rossum's avatar Guido van Rossum

Don't use calculations on values gotten from tell(). Also use a

slightly different way to test for the existence of unread.
parent 897b9f0b
...@@ -125,7 +125,14 @@ class Message: ...@@ -125,7 +125,14 @@ class Message:
self.status = '' self.status = ''
headerseen = "" headerseen = ""
firstline = 1 firstline = 1
startofline = unread = tell = None
if hasattr(self.fp, 'unread'):
unread = self.fp.unread
elif self.seekable:
tell = self.fp.tell
while 1: while 1:
if tell:
startofline = tell()
line = self.fp.readline() line = self.fp.readline()
if not line: if not line:
self.status = 'EOF in headers' self.status = 'EOF in headers'
...@@ -160,10 +167,10 @@ class Message: ...@@ -160,10 +167,10 @@ class Message:
else: else:
self.status = 'Non-header line where header expected' self.status = 'Non-header line where header expected'
# Try to undo the read. # Try to undo the read.
if hasattr(self.fp, 'unread'): if unread:
self.fp.unread(line) unread(line)
elif self.seekable: elif tell:
self.fp.seek(-len(line), 1) self.fp.seek(startofline)
else: else:
self.status = self.status + '; bad seek' self.status = self.status + '; bad seek'
break break
......
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