~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/serializer.py

  • Committer: Patch Queue Manager
  • Date: 2015-10-05 13:45:00 UTC
  • mfrom: (6603.3.1 bts794146)
  • Revision ID: pqm@pqm.ubuntu.com-20151005134500-v244rho557tv0ukd
(vila) Resolve Bug #1480015: Test failure: hexify removed from paramiko
 (Andrew Starr-Bochicchio) (Andrew Starr-Bochicchio)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
17
"""Inventory/revision serialization."""
19
18
 
 
19
from __future__ import absolute_import
20
20
 
21
21
from bzrlib import registry
22
22
 
24
24
class Serializer(object):
25
25
    """Inventory and revision serialization/deserialization."""
26
26
 
 
27
    squashes_xml_invalid_characters = False
 
28
 
27
29
    def write_inventory(self, inv, f):
28
 
        """Write inventory to a file"""
 
30
        """Write inventory to a file.
 
31
 
 
32
        Note: this is a *whole inventory* operation, and should only be used
 
33
        sparingly, as it does not scale well with large trees.
 
34
        """
29
35
        raise NotImplementedError(self.write_inventory)
30
36
 
31
37
    def write_inventory_to_string(self, inv):
 
38
        """Produce a simple string representation of an inventory.
 
39
 
 
40
        Note: this is a *whole inventory* operation, and should only be used
 
41
        sparingly, as it does not scale well with large trees.
 
42
 
 
43
        The requirement for the contents of the string is that it can be passed
 
44
        to read_inventory_from_string and the result is an identical inventory
 
45
        in memory.
 
46
 
 
47
        (All serializers as of 2009-07-29 produce XML, but this is not mandated
 
48
        by the interface.)
 
49
        """
32
50
        raise NotImplementedError(self.write_inventory_to_string)
33
51
 
34
52
    def read_inventory_from_string(self, string, revision_id=None,
35
 
                                   entry_cache=None):
 
53
                                   entry_cache=None, return_from_cache=False):
36
54
        """Read string into an inventory object.
37
55
 
38
56
        :param string: The serialized inventory to read.
46
64
        :param entry_cache: An optional cache of InventoryEntry objects. If
47
65
            supplied we will look up entries via (file_id, revision_id) which
48
66
            should map to a valid InventoryEntry (File/Directory/etc) object.
 
67
        :param return_from_cache: Return entries directly from the cache,
 
68
            rather than copying them first. This is only safe if the caller
 
69
            promises not to mutate the returned inventory entries, but it can
 
70
            make some operations significantly faster.
49
71
        """
50
72
        raise NotImplementedError(self.read_inventory_from_string)
51
73
 
52
74
    def read_inventory(self, f, revision_id=None):
 
75
        """See read_inventory_from_string."""
53
76
        raise NotImplementedError(self.read_inventory)
54
77
 
55
78
    def write_revision(self, rev, f):
70
93
 
71
94
 
72
95
format_registry = SerializerRegistry()
73
 
format_registry.register_lazy('4', 'bzrlib.xml4', 'serializer_v4')
74
96
format_registry.register_lazy('5', 'bzrlib.xml5', 'serializer_v5')
75
97
format_registry.register_lazy('6', 'bzrlib.xml6', 'serializer_v6')
76
98
format_registry.register_lazy('7', 'bzrlib.xml7', 'serializer_v7')
77
99
format_registry.register_lazy('8', 'bzrlib.xml8', 'serializer_v8')
 
100
format_registry.register_lazy('9', 'bzrlib.chk_serializer',
 
101
    'chk_serializer_255_bigpage')
 
102
format_registry.register_lazy('10', 'bzrlib.chk_serializer',
 
103
    'chk_bencode_serializer')