summaryrefslogtreecommitdiff
path: root/sphinx/directives
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2011-05-15 12:31:33 +0200
committerGeorg Brandl <georg@python.org>2011-05-15 12:31:33 +0200
commit3ea4ee1aec7140401bda55786a7e27fdc699403f (patch)
treed7272cbd5431a7582fb2229c4747a6b3dfa6ec68 /sphinx/directives
parentb7802213a0e1272daa38d122274b2613f28e2a7f (diff)
downloadsphinx-3ea4ee1aec7140401bda55786a7e27fdc699403f.tar.gz
Closes #675: Fix IndexErrors when including nonexisting lines with :rst:dir:`literalinclude`.
Diffstat (limited to 'sphinx/directives')
-rw-r--r--sphinx/directives/code.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py
index bfde48e5..6073a7de 100644
--- a/sphinx/directives/code.py
+++ b/sphinx/directives/code.py
@@ -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')