~ubuntu-branches/ubuntu/raring/python-docutils/raring-201211091312

« back to all changes in this revision

Viewing changes to docutils/parsers/rst/directives/misc.py

  • Committer: Bazaar Package Importer
  • Author(s): Jakub Wilk
  • Date: 2010-07-24 09:03:32 UTC
  • mfrom: (11.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100724090332-n30aqcft3axs8xd3
* Upload to unstable.
* Replace patch to fix --local option for tools/buildhtml.py
  (17_revert_buildhtml.diff) with the one that was applied upstream
  (buildhtml-local.diff).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
4
4
 
78
78
        endline = self.options.get('end-line', None)
79
79
        try:
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])
83
83
            else:
84
 
                include_text = include_file.read()
 
84
                rawtext = include_file.read()
85
85
        except UnicodeError, error:
86
86
            raise self.severe(
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)
92
92
        if after_text:
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)
100
100
        if before_text:
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)
111
111
            else:
112
 
                text = include_text
113
 
            literal_block = nodes.literal_block(include_text, text, 
114
 
                                                source=path)
 
112
                text = rawtext
 
113
            literal_block = nodes.literal_block(rawtext, text, source=path)
115
114
            literal_block.line = 1
116
115
            return [literal_block]
117
116
        else:
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)
121
120
            return []
122
121