/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bzr/serializer.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Inventory/revision serialization."""
 
18
 
 
19
from .. import registry
 
20
 
 
21
 
 
22
class Serializer(object):
 
23
    """Inventory and revision serialization/deserialization."""
 
24
 
 
25
    squashes_xml_invalid_characters = False
 
26
 
 
27
    def write_inventory(self, inv, f):
 
28
        """Write inventory to a file.
 
29
 
 
30
        Note: this is a *whole inventory* operation, and should only be used
 
31
        sparingly, as it does not scale well with large trees.
 
32
        """
 
33
        raise NotImplementedError(self.write_inventory)
 
34
 
 
35
    def write_inventory_to_chunks(self, inv):
 
36
        """Produce a simple bytestring chunk representation of an inventory.
 
37
 
 
38
        Note: this is a *whole inventory* operation, and should only be used
 
39
        sparingly, as it does not scale well with large trees.
 
40
 
 
41
        The requirement for the contents of the string is that it can be passed
 
42
        to read_inventory_from_lines and the result is an identical inventory
 
43
        in memory.
 
44
        """
 
45
        raise NotImplementedError(self.write_inventory_to_chunks)
 
46
 
 
47
    def write_inventory_to_lines(self, inv):
 
48
        """Produce a simple lines representation of an inventory.
 
49
 
 
50
        Note: this is a *whole inventory* operation, and should only be used
 
51
        sparingly, as it does not scale well with large trees.
 
52
 
 
53
        The requirement for the contents of the string is that it can be passed
 
54
        to read_inventory_from_lines and the result is an identical inventory
 
55
        in memory.
 
56
        """
 
57
        raise NotImplementedError(self.write_inventory_to_lines)
 
58
 
 
59
    def read_inventory_from_lines(self, lines, revision_id=None,
 
60
                                  entry_cache=None, return_from_cache=False):
 
61
        """Read bytestring chunks into an inventory object.
 
62
 
 
63
        :param lines: The serialized inventory to read.
 
64
        :param revision_id: If not-None, the expected revision id of the
 
65
            inventory. Some serialisers use this to set the results' root
 
66
            revision. This should be supplied for deserialising all
 
67
            from-repository inventories so that xml5 inventories that were
 
68
            serialised without a revision identifier can be given the right
 
69
            revision id (but not for working tree inventories where users can
 
70
            edit the data without triggering checksum errors or anything).
 
71
        :param entry_cache: An optional cache of InventoryEntry objects. If
 
72
            supplied we will look up entries via (file_id, revision_id) which
 
73
            should map to a valid InventoryEntry (File/Directory/etc) object.
 
74
        :param return_from_cache: Return entries directly from the cache,
 
75
            rather than copying them first. This is only safe if the caller
 
76
            promises not to mutate the returned inventory entries, but it can
 
77
            make some operations significantly faster.
 
78
        """
 
79
        raise NotImplementedError(self.read_inventory_from_lines)
 
80
 
 
81
    def read_inventory(self, f, revision_id=None):
 
82
        """See read_inventory_from_lines."""
 
83
        raise NotImplementedError(self.read_inventory)
 
84
 
 
85
    def write_revision_to_string(self, rev):
 
86
        raise NotImplementedError(self.write_revision_to_string)
 
87
 
 
88
    def write_revision_to_lines(self, rev):
 
89
        raise NotImplementedError(self.write_revision_to_lines)
 
90
 
 
91
    def read_revision(self, f):
 
92
        raise NotImplementedError(self.read_revision)
 
93
 
 
94
    def read_revision_from_string(self, xml_string):
 
95
        raise NotImplementedError(self.read_revision_from_string)
 
96
 
 
97
 
 
98
class SerializerRegistry(registry.Registry):
 
99
    """Registry for serializer objects"""
 
100
 
 
101
 
 
102
format_registry = SerializerRegistry()
 
103
format_registry.register_lazy('5', 'breezy.bzr.xml5', 'serializer_v5')
 
104
format_registry.register_lazy('6', 'breezy.bzr.xml6', 'serializer_v6')
 
105
format_registry.register_lazy('7', 'breezy.bzr.xml7', 'serializer_v7')
 
106
format_registry.register_lazy('8', 'breezy.bzr.xml8', 'serializer_v8')
 
107
format_registry.register_lazy('9', 'breezy.bzr.chk_serializer',
 
108
                              'chk_serializer_255_bigpage')
 
109
format_registry.register_lazy('10', 'breezy.bzr.chk_serializer',
 
110
                              'chk_bencode_serializer')