]> granicus.if.org Git - python/commitdiff
Don't use calculations on values gotten from tell(). Also use a
authorGuido van Rossum <guido@python.org>
Tue, 21 Jul 1998 14:24:04 +0000 (14:24 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 21 Jul 1998 14:24:04 +0000 (14:24 +0000)
slightly different way to test for the existence of unread.

Lib/rfc822.py

index fc244c5b88c7ce12620a6fada7ee5bada240449f..2e97ef4daf274546f8800f6795ebca7fcd70407d 100644 (file)
@@ -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