~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml_serializer.py

  • Committer: Sabin Iacob
  • Date: 2009-03-23 14:59:43 UTC
  • mto: (4189.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4193.
  • Revision ID: iacobs@m0n5t3r.info-20090323145943-3s3p1px5q1rkh2e5
update FSF mailing address

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""XML externalization support."""
18
18
 
34
34
    except ImportError:
35
35
        from cElementTree import (ElementTree, SubElement, Element,
36
36
                                  XMLTreeBuilder, fromstring, tostring)
37
 
        import elementtree
 
37
        import elementtree.ElementTree
38
38
    ParseError = SyntaxError
39
39
except ImportError:
40
40
    mutter('WARNING: using slower ElementTree; consider installing cElementTree'
59
59
    def write_inventory_to_string(self, inv):
60
60
        raise NotImplementedError(self.write_inventory_to_string)
61
61
 
62
 
    def read_inventory_from_string(self, xml_string, revision_id=None):
 
62
    def read_inventory_from_string(self, xml_string, revision_id=None,
 
63
                                   entry_cache=None):
63
64
        """Read xml_string into an inventory object.
64
65
 
65
66
        :param xml_string: The xml to read.
66
67
        :param revision_id: If not-None, the expected revision id of the
67
68
            inventory. Some serialisers use this to set the results' root
68
 
            revision.
 
69
            revision. This should be supplied for deserialising all
 
70
            from-repository inventories so that xml5 inventories that were
 
71
            serialised without a revision identifier can be given the right
 
72
            revision id (but not for working tree inventories where users can
 
73
            edit the data without triggering checksum errors or anything).
 
74
        :param entry_cache: An optional cache of InventoryEntry objects. If
 
75
            supplied we will look up entries via (file_id, revision_id) which
 
76
            should map to a valid InventoryEntry (File/Directory/etc) object.
69
77
        """
70
78
        try:
71
 
            return self._unpack_inventory(fromstring(xml_string), revision_id)
 
79
            return self._unpack_inventory(fromstring(xml_string), revision_id,
 
80
                                          entry_cache=entry_cache)
72
81
        except ParseError, e:
73
82
            raise errors.UnexpectedInventoryFormat(e)
74
83
 
113
122
    }
114
123
def _escape_replace(match, map=escape_map):
115
124
    return map[match.group()]
116
 
 
 
125
 
117
126
def _escape_attrib(text, encoding=None, replace=None):
118
127
    # escape attribute value
119
128
    try:
144
153
    }
145
154
def _escape_cdata_replace(match, map=escape_cdata_map):
146
155
    return map[match.group()]
147
 
 
 
156
 
148
157
def _escape_cdata(text, encoding=None, replace=None):
149
158
    # escape character data
150
159
    try:
175
184
format_registry.register_lazy('5', 'bzrlib.xml5', 'serializer_v5')
176
185
format_registry.register_lazy('6', 'bzrlib.xml6', 'serializer_v6')
177
186
format_registry.register_lazy('7', 'bzrlib.xml7', 'serializer_v7')
 
187
format_registry.register_lazy('8', 'bzrlib.xml8', 'serializer_v8')