1
# $Id: misc.py 6142 2009-09-25 18:51:01Z milde $
1
# $Id: misc.py 6185 2009-10-25 20:43:42Z milde $
2
2
# Authors: David Goodger <goodger@python.org>; Dethe Elza
3
3
# Copyright: This module has been placed in the public domain.
78
78
endline = self.options.get('end-line', None)
80
80
if startline or (endline is not None):
81
include_lines = include_file.readlines()
82
include_text = ''.join(include_lines[startline:endline])
81
lines = include_file.readlines()
82
rawtext = ''.join(lines[startline:endline])
84
include_text = include_file.read()
84
rawtext = include_file.read()
85
85
except UnicodeError, error:
87
87
'Problem with "%s" directive:\n%s: %s'
90
90
# and no restrictions on matching inside lines vs. line boundaries
91
91
after_text = self.options.get('start-after', None)
93
# skip content in include_text before *and incl.* a matching text
94
after_index = include_text.find(after_text)
93
# skip content in rawtext before *and incl.* a matching text
94
after_index = rawtext.find(after_text)
95
95
if after_index < 0:
96
96
raise self.severe('Problem with "start-after" option of "%s" '
97
97
'directive:\nText not found.' % self.name)
98
include_text = include_text[after_index + len(after_text):]
98
rawtext = rawtext[after_index + len(after_text):]
99
99
before_text = self.options.get('end-before', None)
101
# skip content in include_text after *and incl.* a matching text
102
before_index = include_text.find(before_text)
101
# skip content in rawtext after *and incl.* a matching text
102
before_index = rawtext.find(before_text)
103
103
if before_index < 0:
104
104
raise self.severe('Problem with "end-before" option of "%s" '
105
105
'directive:\nText not found.' % self.name)
106
include_text = include_text[:before_index]
106
rawtext = rawtext[:before_index]
107
107
if 'literal' in self.options:
108
108
# Convert tabs to spaces, if `tab_width` is positive.
109
109
if tab_width >= 0:
110
text = include_text.expandtabs(tab_width)
110
text = rawtext.expandtabs(tab_width)
113
literal_block = nodes.literal_block(include_text, text,
113
literal_block = nodes.literal_block(rawtext, text, source=path)
115
114
literal_block.line = 1
116
115
return [literal_block]
118
117
include_lines = statemachine.string2lines(
119
include_text, tab_width, convert_whitespace=1)
118
rawtext, tab_width, convert_whitespace=1)
120
119
self.state_machine.insert_input(include_lines, path)