diff options
author | Raymond Hettinger <python@rcn.com> | 2004-05-04 08:21:52 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-05-04 08:21:52 (GMT) |
commit | 0b569bb3992467850926dab9f4e8048a70a6d904 (patch) | |
tree | c7c6796e485262010ade8aefdee13bca9db013f6 | |
parent | 2d5914b17e79803251693531ef45815b42da3933 (diff) | |
download | cpython-0b569bb3992467850926dab9f4e8048a70a6d904.zip cpython-0b569bb3992467850926dab9f4e8048a70a6d904.tar.gz cpython-0b569bb3992467850926dab9f4e8048a70a6d904.tar.bz2 |
Stacks based on lists work better and read more clearly when they
grow and shrink on the right.
-rw-r--r-- | Lib/multifile.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Lib/multifile.py b/Lib/multifile.py index 23d9d31..e82a3fd 100644 --- a/Lib/multifile.py +++ b/Lib/multifile.py @@ -38,13 +38,13 @@ class MultiFile: def __init__(self, fp, seekable=1): self.fp = fp - self.stack = [] # Grows down + self.stack = [] self.level = 0 self.last = 0 if seekable: self.seekable = 1 self.start = self.fp.tell() - self.posstack = [] # Grows down + self.posstack = [] def tell(self): if self.level > 0: @@ -88,8 +88,7 @@ class MultiFile: marker = line.rstrip() # No? OK, try to match a boundary. # Return the line (unstripped) if we don't. - for i in range(len(self.stack)): - sep = self.stack[i] + for i, sep in enumerate(reversed(self.stack)): if marker == self.section_divider(sep): self.last = 0 break @@ -130,9 +129,9 @@ class MultiFile: def push(self, sep): if self.level > 0: raise Error, 'bad MultiFile.push() call' - self.stack.insert(0, sep) + self.stack.append(sep) if self.seekable: - self.posstack.insert(0, self.start) + self.posstack.append(self.start) self.start = self.fp.tell() def pop(self): @@ -143,9 +142,9 @@ class MultiFile: else: abslastpos = self.lastpos + self.start self.level = max(0, self.level - 1) - del self.stack[0] + self.stack.pop() if self.seekable: - self.start = self.posstack.pop(0) + self.start = self.posstack.pop() if self.level > 0: self.lastpos = abslastpos - self.start |