summaryrefslogtreecommitdiff
path: root/sphinx/directives/code.py
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
commit02a3b5bfdfe14ffb348d2abcc33c2da9df51c1ce (patch)
treed7272cbd5431a7582fb2229c4747a6b3dfa6ec68 /sphinx/directives/code.py
parenteaa43cafce0408ef30bdea1b205f1b2aa4d45c84 (diff)
downloadsphinx-git-02a3b5bfdfe14ffb348d2abcc33c2da9df51c1ce.tar.gz
Closes #675: Fix IndexErrors when including nonexisting lines with :rst:dir:`literalinclude`.
Diffstat (limited to 'sphinx/directives/code.py')
-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 bfde48e58..6073a7de2 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')