Closes #675: Fix IndexErrors when including nonexisting lines with :rst:dir:literalinclude.

This commit is contained in:
Georg Brandl 2011-05-15 12:31:33 +02:00
parent eaa43cafce
commit 02a3b5bfdf
2 changed files with 10 additions and 1 deletions

View File

@ -1,6 +1,9 @@
Release 1.0.8 (in development)
==============================
* #675: Fix IndexErrors when including nonexisting lines with
:rst:dir:`literalinclude`.
* #676: Respect custom function/method parameter separator strings.
* #682: Fix JS incompatibility with jQuery >= 1.5.

View File

@ -152,7 +152,13 @@ class LiteralInclude(Directive):
linelist = parselinenos(linespec, len(lines))
except ValueError, err:
return [document.reporter.warning(str(err), line=self.lineno)]
lines = [lines[i] for i in linelist]
# just ignore nonexisting lines
nlines = len(lines)
lines = [lines[i] for i in linelist if i < nlines]
if not lines:
return [document.reporter.warning(
'Line spec %r: no lines pulled from include file %r' %
(linespec, filename), line=self.lineno)]
startafter = self.options.get('start-after')
endbefore = self.options.get('end-before')