summaryrefslogtreecommitdiff
path: root/docutils/statemachine.py
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2010-04-26 10:04:17 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2010-04-26 10:04:17 +0000
commitda71c39fa3517fbf76e4d7d654f25317a726e720 (patch)
tree7fc300e8b4af2c9b4287309a4fb0fd509c2b1912 /docutils/statemachine.py
parent739ac4db4abf4165fa3d796412048377843b3021 (diff)
downloaddocutils-da71c39fa3517fbf76e4d7d654f25317a726e720.tar.gz
Fix [ 2788716 ] reporting problems in included files.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@6314 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/statemachine.py')
-rw-r--r--docutils/statemachine.py44
1 files changed, 33 insertions, 11 deletions
diff --git a/docutils/statemachine.py b/docutils/statemachine.py
index 964a18fca..b660fc5f0 100644
--- a/docutils/statemachine.py
+++ b/docutils/statemachine.py
@@ -362,26 +362,38 @@ class StateMachine:
Looks up the source and line number in the `self.input_lines`
StringList instance to count for included source files.
- If the optional argument `lineno` is given, convert it from a
- "cumulative line number" (result of `abs_line_number()`) to the
- corresponding (source, line) pair.
+ If the optional argument `lineno` is given, convert it from an
+ absolute line number to the corresponding (source, line) pair.
"""
if lineno is None:
- line_offset = self.line_offset
+ offset = self.line_offset
else:
- line_offset = lineno - self.input_offset - 1
- (src, offset) = self.input_lines.info(line_offset)
+ offset = lineno - self.input_offset - 1
try:
- srcline = offset + 1
- except TypeError: # offset is None if `line_offset` is off the list
- srcline = None
+ src, srcoffset = self.input_lines.info(offset)
+ srcline = srcoffset + 1
+ except (TypeError):
+ # line is None if index is "Just past the end"
+ src, line = self.get_source_and_line(offset + self.input_offset)
+ return src, line + 1
+ except (IndexError): # `offset` is off the list
+ src, srcline = None, None
+ # raise AssertionError('cannot find line %d in %s lines' %
+ # (offset, len(self.input_lines)))
+ # # list(self.input_lines.lines())))
+ # assert offset == srcoffset, str(self.input_lines)
+ # print "get_source_and_line(%s):" % lineno,
+ # print offset + 1, '->', src, srcline
+ # print self.input_lines
return (src, srcline)
def insert_input(self, input_lines, source):
self.input_lines.insert(self.line_offset + 1, '',
- source='internal padding after ' + source)
+ source='internal padding after '+source,
+ offset=len(input_lines))
self.input_lines.insert(self.line_offset + 1, '',
- source='internal padding before '+ source)
+ source='internal padding before '+source,
+ offset=-1)
self.input_lines.insert(self.line_offset + 2,
StringList(input_lines, source))
@@ -1306,6 +1318,16 @@ class ViewList:
"""Break link between this list and parent list."""
self.parent = None
+ def xitems(self):
+ """Return iterator yielding (source, offset, value) tuples."""
+ for (value, (source, offset)) in zip(self.data, self.items):
+ yield (source, offset, value)
+
+ def pprint(self):
+ """Print the list in `grep` format (`source:offset:value` lines)"""
+ for line in self.xitems():
+ print "%s:%d:%s" % line
+
class StringList(ViewList):