annotate Lib/multifile.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 2f14518f300b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
1 """A readline()-style interface to the parts of a multipart message.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
2
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
3 The MultiFile class makes each part of a multipart message "feel" like
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
4 an ordinary file, as long as you use fp.readline(). Allows recursive
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
5 use, for nested multipart messages. Probably best used together
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
6 with module mimetools.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
7
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
8 Suggested use:
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
9
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
10 real_fp = open(...)
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
11 fp = MultiFile(real_fp)
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
12
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
13 "read some lines from fp"
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
14 fp.push(separator)
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
15 while 1:
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
16 "read lines from fp until it returns an empty string" (A)
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
17 if not fp.next(): break
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
18 fp.pop()
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
19 "read remaining lines from fp until it returns an empty string"
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
20
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
21 The latter sequence may be used recursively at (A).
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
22 It is also allowed to use multiple push()...pop() sequences.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
23
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 11706
diff changeset
24 If seekable is given as 0, the class code will not do the bookkeeping
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
25 it normally attempts in order to make seeks relative to the beginning of the
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
26 current file part. This may be useful when using MultiFile with a non-
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
27 seekable stream object.
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
28 """
46935
2f14518f300b Deprecate the multifile module as per PEP 4.
Brett Cannon <bcannon@gmail.com>
parents: 31965
diff changeset
29 from warnings import warn
2f14518f300b Deprecate the multifile module as per PEP 4.
Brett Cannon <bcannon@gmail.com>
parents: 31965
diff changeset
30 warn("the multifile module has been deprecated since Python 2.5",
2f14518f300b Deprecate the multifile module as per PEP 4.
Brett Cannon <bcannon@gmail.com>
parents: 31965
diff changeset
31 DeprecationWarning, stacklevel=2)
2f14518f300b Deprecate the multifile module as per PEP 4.
Brett Cannon <bcannon@gmail.com>
parents: 31965
diff changeset
32 del warn
915
39ee7de74750 New module to support decoding multipart messages (also see mimetools).
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15868
diff changeset
34 __all__ = ["MultiFile","Error"]
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15868
diff changeset
35
14022
d44603f2b928 Convert some old-style string exceptions to class exceptions.
Fred Drake <fdrake@acm.org>
parents: 13620
diff changeset
36 class Error(Exception):
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
37 pass
915
39ee7de74750 New module to support decoding multipart messages (also see mimetools).
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
39ee7de74750 New module to support decoding multipart messages (also see mimetools).
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 class MultiFile:
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
40
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
41 seekable = 0
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
42
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
43 def __init__(self, fp, seekable=1):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
44 self.fp = fp
31965
ef34dec004cd Stacks based on lists work better and read more clearly when they
Raymond Hettinger <python@rcn.com>
parents: 25337
diff changeset
45 self.stack = []
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
46 self.level = 0
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
47 self.last = 0
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
48 if seekable:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
49 self.seekable = 1
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
50 self.start = self.fp.tell()
31965
ef34dec004cd Stacks based on lists work better and read more clearly when they
Raymond Hettinger <python@rcn.com>
parents: 25337
diff changeset
51 self.posstack = []
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
52
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
53 def tell(self):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
54 if self.level > 0:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
55 return self.lastpos
25337
b529ac2f9ab6 Back out multifile.py 1.19 and 1.20. Fixes #514676.
Martin v. Löwis <martin@v.loewis.de>
parents: 24058
diff changeset
56 return self.fp.tell() - self.start
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
57
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
58 def seek(self, pos, whence=0):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
59 here = self.tell()
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
60 if whence:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
61 if whence == 1:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
62 pos = pos + here
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
63 elif whence == 2:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
64 if self.level > 0:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
65 pos = pos + self.lastpos
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
66 else:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
67 raise Error, "can't use whence=2 yet"
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
68 if not 0 <= pos <= here or \
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
69 self.level > 0 and pos > self.lastpos:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
70 raise Error, 'bad MultiFile.seek() call'
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
71 self.fp.seek(pos + self.start)
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
72 self.level = 0
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
73 self.last = 0
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
74
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
75 def readline(self):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
76 if self.level > 0:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
77 return ''
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
78 line = self.fp.readline()
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
79 # Real EOF?
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
80 if not line:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
81 self.level = len(self.stack)
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
82 self.last = (self.level > 0)
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
83 if self.last:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
84 raise Error, 'sudden EOF in MultiFile.readline()'
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
85 return ''
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
86 assert self.level == 0
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
87 # Fast check to see if this is just data
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
88 if self.is_data(line):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
89 return line
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
90 else:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
91 # Ignore trailing whitespace on marker lines
16532
7fc64df13db0 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16460
diff changeset
92 marker = line.rstrip()
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
93 # No? OK, try to match a boundary.
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
94 # Return the line (unstripped) if we don't.
31965
ef34dec004cd Stacks based on lists work better and read more clearly when they
Raymond Hettinger <python@rcn.com>
parents: 25337
diff changeset
95 for i, sep in enumerate(reversed(self.stack)):
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
96 if marker == self.section_divider(sep):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
97 self.last = 0
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
98 break
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
99 elif marker == self.end_marker(sep):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
100 self.last = 1
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
101 break
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
102 else:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
103 return line
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
104 # We only get here if we see a section divider or EOM line
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
105 if self.seekable:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
106 self.lastpos = self.tell() - len(line)
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
107 self.level = i+1
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
108 if self.level > 1:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
109 raise Error,'Missing endmarker in MultiFile.readline()'
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
110 return ''
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
111
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
112 def readlines(self):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
113 list = []
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
114 while 1:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
115 line = self.readline()
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
116 if not line: break
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
117 list.append(line)
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
118 return list
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
119
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
120 def read(self): # Note: no size argument -- read until EOF only!
17031
b40ab3105521 Multifile.read(): Fix a broken conversion to string methods.
Fred Drake <fdrake@acm.org>
parents: 16532
diff changeset
121 return ''.join(self.readlines())
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
122
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
123 def next(self):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
124 while self.readline(): pass
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
125 if self.level > 1 or self.last:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
126 return 0
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
127 self.level = 0
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
128 self.last = 0
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
129 if self.seekable:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
130 self.start = self.fp.tell()
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
131 return 1
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
132
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
133 def push(self, sep):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
134 if self.level > 0:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
135 raise Error, 'bad MultiFile.push() call'
31965
ef34dec004cd Stacks based on lists work better and read more clearly when they
Raymond Hettinger <python@rcn.com>
parents: 25337
diff changeset
136 self.stack.append(sep)
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
137 if self.seekable:
31965
ef34dec004cd Stacks based on lists work better and read more clearly when they
Raymond Hettinger <python@rcn.com>
parents: 25337
diff changeset
138 self.posstack.append(self.start)
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
139 self.start = self.fp.tell()
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
140
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
141 def pop(self):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
142 if self.stack == []:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
143 raise Error, 'bad MultiFile.pop() call'
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
144 if self.level <= 1:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
145 self.last = 0
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
146 else:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
147 abslastpos = self.lastpos + self.start
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
148 self.level = max(0, self.level - 1)
31965
ef34dec004cd Stacks based on lists work better and read more clearly when they
Raymond Hettinger <python@rcn.com>
parents: 25337
diff changeset
149 self.stack.pop()
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
150 if self.seekable:
31965
ef34dec004cd Stacks based on lists work better and read more clearly when they
Raymond Hettinger <python@rcn.com>
parents: 25337
diff changeset
151 self.start = self.posstack.pop()
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
152 if self.level > 0:
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
153 self.lastpos = abslastpos - self.start
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
154
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
155 def is_data(self, line):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
156 return line[:2] != '--'
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
157
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
158 def section_divider(self, str):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
159 return "--" + str
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 8583
diff changeset
160
15868
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
161 def end_marker(self, str):
3060cbfa01be Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15655
diff changeset
162 return "--" + str + "--"