~ubuntu-branches/ubuntu/vivid/python-docutils/vivid

« back to all changes in this revision

Viewing changes to docutils/transforms/frontmatter.py

  • Committer: Package Import Robot
  • Author(s): Michael Schutte, Michael Schutte, Dmitry Shachnev
  • Date: 2013-09-09 22:58:50 UTC
  • mfrom: (11.1.9 experimental)
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: package-import@ubuntu.com-20130909225850-61mgyuamzo0zb6pj
[ Michael Schutte ]
* Upload to unstable.
* Document in the patch header that #714313 is also taken care of by
  odt-writer-ascii-filenames.diff.

[ Dmitry Shachnev ]
* Updated rst2odt_prepstyles-elementtree.diff to make it not cause
  SyntaxErrors with Python 3.
* Fix autopkgtest failures:
  - Copy HISTORY.txt to the testing directory.
  - Disable test_html4css1_misc as it does not work with our location
    of html4css1.css.
* docutils.xml: fix codes of Chinese languages (thanks Jakub Wilk),
  and add Hungarian language.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# $Id: frontmatter.py 5618 2008-07-28 08:37:32Z strank $
 
1
# $Id: frontmatter.py 7595 2013-01-21 17:33:56Z milde $
2
2
# Author: David Goodger, Ueli Schlaepfer <goodger@python.org>
3
3
# Copyright: This module has been placed in the public domain.
4
4
 
49
49
 
50
50
        `node` is normally a document.
51
51
        """
 
52
        # Type check
 
53
        if not isinstance(node, nodes.Element):
 
54
            raise TypeError, 'node must be of Element-derived type.'
 
55
 
52
56
        # `node` must not have a title yet.
53
57
        assert not (len(node) and isinstance(node[0], nodes.title))
54
58
        section, index = self.candidate_index(node)
55
59
        if index is None:
56
60
            return None
 
61
 
57
62
        # Transfer the section's attributes to the node:
58
 
        node.attributes.update(section.attributes)
 
63
        # NOTE: Change second parameter to False to NOT replace
 
64
        #       attributes that already exist in node with those in
 
65
        #       section
 
66
        # NOTE: Remove third parameter to NOT copy the 'source'
 
67
        #       attribute from section
 
68
        node.update_all_atts_concatenating(section, True, True)
 
69
 
59
70
        # setup_child is called automatically for all nodes.
60
71
        node[:] = (section[:1]        # section title
61
72
                   + node[:index]     # everything that was in the
81
92
                <subtitle>
82
93
                ...
83
94
        """
 
95
        # Type check
 
96
        if not isinstance(node, nodes.Element):
 
97
            raise TypeError, 'node must be of Element-derived type.'
 
98
 
84
99
        subsection, index = self.candidate_index(node)
85
100
        if index is None:
86
101
            return None
87
102
        subtitle = nodes.subtitle()
88
 
        # Transfer the subsection's attributes to the new subtitle:
89
 
        # This causes trouble with list attributes!  To do: Write a
90
 
        # test case which catches direct access to the `attributes`
91
 
        # dictionary and/or write a test case which shows problems in
92
 
        # this particular case.
93
 
        subtitle.attributes.update(subsection.attributes)
94
 
        # We're losing the subtitle's attributes here!  To do: Write a
95
 
        # test case which shows this behavior.
 
103
 
 
104
        # Transfer the subsection's attributes to the new subtitle
 
105
        # NOTE: Change second parameter to False to NOT replace
 
106
        #       attributes that already exist in node with those in
 
107
        #       section
 
108
        # NOTE: Remove third parameter to NOT copy the 'source'
 
109
        #       attribute from section
 
110
        subtitle.update_all_atts_concatenating(subsection, True, True)
 
111
 
96
112
        # Transfer the contents of the subsection's title to the
97
113
        # subtitle:
98
114
        subtitle[:] = subsection[0][:]