summaryrefslogtreecommitdiffstats
path: root/Lib/rfc822.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-07-21 14:24:04 (GMT)
committerGuido van Rossum <guido@python.org>1998-07-21 14:24:04 (GMT)
commit052969a6022a06414b11ab6fe294d5af01d20a59 (patch)
tree625b4a78ff6e8861507b2e9cbfa74834b36a2ad6 /Lib/rfc822.py
parent897b9f0b0d6ffdb56ee3587666fe67d530d2ac39 (diff)
downloadcpython-052969a6022a06414b11ab6fe294d5af01d20a59.zip
cpython-052969a6022a06414b11ab6fe294d5af01d20a59.tar.gz
cpython-052969a6022a06414b11ab6fe294d5af01d20a59.tar.bz2
Don't use calculations on values gotten from tell(). Also use a
slightly different way to test for the existence of unread.
Diffstat (limited to 'Lib/rfc822.py')
-rw-r--r--Lib/rfc822.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/rfc822.py b/Lib/rfc822.py
index fc244c5..2e97ef4 100644
--- a/Lib/rfc822.py
+++ b/Lib/rfc822.py
@@ -125,7 +125,14 @@ class Message:
self.status = ''
headerseen = ""
firstline = 1
+ startofline = unread = tell = None
+ if hasattr(self.fp, 'unread'):
+ unread = self.fp.unread
+ elif self.seekable:
+ tell = self.fp.tell
while 1:
+ if tell:
+ startofline = tell()
line = self.fp.readline()
if not line:
self.status = 'EOF in headers'
@@ -160,10 +167,10 @@ class Message:
else:
self.status = 'Non-header line where header expected'
# Try to undo the read.
- if hasattr(self.fp, 'unread'):
- self.fp.unread(line)
- elif self.seekable:
- self.fp.seek(-len(line), 1)
+ if unread:
+ unread(line)
+ elif tell:
+ self.fp.seek(startofline)
else:
self.status = self.status + '; bad seek'
break