~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/weave_fmt/xml4.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
from bzrlib.xml_serializer import ElementTree, SubElement, Element, Serializer
18
 
from bzrlib.inventory import ROOT_ID, Inventory, InventoryEntry
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
from __future__ import absolute_import
 
18
 
 
19
from bzrlib.xml_serializer import (
 
20
    Element,
 
21
    SubElement,
 
22
    XMLSerializer,
 
23
    escape_invalid_chars,
 
24
    )
 
25
from bzrlib.inventory import ROOT_ID, Inventory
19
26
import bzrlib.inventory as inventory
20
27
from bzrlib.revision import Revision
21
28
from bzrlib.errors import BzrError
22
29
 
23
30
 
24
 
class _Serializer_v4(Serializer):
 
31
class _Serializer_v4(XMLSerializer):
25
32
    """Version 0.0.4 serializer
26
33
 
27
34
    You should use the serializer_v4 singleton.
28
 
    
 
35
 
29
36
    v4 serialisation is no longer supported, only deserialisation.
30
37
    """
31
 
    
 
38
 
32
39
    __slots__ = []
33
 
    
 
40
 
34
41
    def _pack_entry(self, ie):
35
42
        """Convert InventoryEntry to XML element"""
36
43
        e = Element('entry')
57
64
        return e
58
65
 
59
66
 
60
 
    def _unpack_inventory(self, elt, revision_id=None):
 
67
    def _unpack_inventory(self, elt, revision_id=None, entry_cache=None,
 
68
                          return_from_cache=False):
61
69
        """Construct from XML Element
62
70
 
63
71
        :param revision_id: Ignored parameter used by xml5.
65
73
        root_id = elt.get('file_id') or ROOT_ID
66
74
        inv = Inventory(root_id)
67
75
        for e in elt:
68
 
            ie = self._unpack_entry(e)
 
76
            ie = self._unpack_entry(e, entry_cache=entry_cache,
 
77
                                    return_from_cache=return_from_cache)
69
78
            if ie.parent_id == ROOT_ID:
70
79
                ie.parent_id = root_id
71
80
            inv.add(ie)
72
81
        return inv
73
82
 
74
83
 
75
 
    def _unpack_entry(self, elt):
 
84
    def _unpack_entry(self, elt, entry_cache=None, return_from_cache=False):
76
85
        ## original format inventories don't have a parent_id for
77
86
        ## nodes in the root directory, but it's cleaner to use one
78
87
        ## internally.
120
129
        root.text = '\n'
121
130
 
122
131
        msg = SubElement(root, 'message')
123
 
        msg.text = rev.message
 
132
        msg.text = escape_invalid_chars(rev.message)[0]
124
133
        msg.tail = '\n'
125
134
 
126
135
        if rev.parents:
134
143
                    p.set('revision_sha1', rev.parent_sha1s[i])
135
144
        return root
136
145
 
137
 
    
 
146
 
138
147
    def _unpack_revision(self, elt):
139
148
        """XML Element -> Revision object"""
140
 
        
 
149
 
141
150
        # <changeset> is deprecated...
142
151
        if elt.tag not in ('revision', 'changeset'):
143
152
            raise BzrError("unexpected tag in revision file: %r" % elt)