/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 bzrlib/xml8.py

  • Committer: Frank Aspell
  • Date: 2009-02-22 16:54:02 UTC
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: frankaspell@googlemail.com-20090222165402-2myrucnu7er5w4ha
Fixing various typos

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import cStringIO
18
18
import re
24
24
    revision as _mod_revision,
25
25
    trace,
26
26
    )
27
 
from bzrlib.xml_serializer import (
28
 
    Element,
29
 
    SubElement,
30
 
    XMLSerializer,
31
 
    escape_invalid_chars,
32
 
    )
33
 
from bzrlib.inventory import InventoryEntry
 
27
from bzrlib.xml_serializer import SubElement, Element, Serializer
 
28
from bzrlib.inventory import ROOT_ID, Inventory, InventoryEntry
34
29
from bzrlib.revision import Revision
35
30
from bzrlib.errors import BzrError
36
31
 
97
92
    # to check if None, rather than try/KeyError
98
93
    text = _map.get(unicode_or_utf8_str)
99
94
    if text is None:
100
 
        if unicode_or_utf8_str.__class__ is unicode:
 
95
        if unicode_or_utf8_str.__class__ == unicode:
101
96
            # The alternative policy is to do a regular UTF8 encoding
102
97
            # and then escape only XML meta characters.
103
98
            # Performance is equivalent once you use cache_utf8. *However*
133
128
    # This is fairly optimized because we know what cElementTree does, this is
134
129
    # not meant as a generic function for all cases. Because it is possible for
135
130
    # an 8-bit string to not be ascii or valid utf8.
136
 
    if a_str.__class__ is unicode:
 
131
    if a_str.__class__ == unicode:
137
132
        return _encode_utf8(a_str)
138
133
    else:
139
 
        return intern(a_str)
 
134
        return _get_cached_ascii(a_str)
140
135
 
141
136
 
142
137
def _clear_cache():
144
139
    _to_escaped_map.clear()
145
140
 
146
141
 
147
 
class Serializer_v8(XMLSerializer):
 
142
class Serializer_v8(Serializer):
148
143
    """This serialiser adds rich roots.
149
144
 
150
145
    Its revision format number matches its inventory number.
168
163
        :raises: AssertionError if an error has occurred.
169
164
        """
170
165
        if inv.revision_id is None:
171
 
            raise AssertionError("inv.revision_id is None")
 
166
            raise AssertionError()
172
167
        if inv.root.revision is None:
173
 
            raise AssertionError("inv.root.revision is None")
 
168
            raise AssertionError()
174
169
 
175
170
    def _check_cache_size(self, inv_size, entry_cache):
176
171
        """Check that the entry_cache is large enough.
216
211
 
217
212
    def write_inventory(self, inv, f, working=False):
218
213
        """Write inventory to a file.
219
 
 
 
214
        
220
215
        :param inv: the inventory to write.
221
216
        :param f: the file to write. (May be None if the lines are the desired
222
217
            output).
346
341
            root.set('timezone', str(rev.timezone))
347
342
        root.text = '\n'
348
343
        msg = SubElement(root, 'message')
349
 
        msg.text = escape_invalid_chars(rev.message)[0]
 
344
        msg.text = rev.message
350
345
        msg.tail = '\n'
351
346
        if rev.parent_ids:
352
347
            pelts = SubElement(root, 'parents')
371
366
            prop_elt.tail = '\n'
372
367
        top_elt.tail = '\n'
373
368
 
374
 
    def _unpack_inventory(self, elt, revision_id=None, entry_cache=None,
375
 
                          return_from_cache=False):
 
369
    def _unpack_inventory(self, elt, revision_id=None, entry_cache=None):
376
370
        """Construct from XML Element"""
377
371
        if elt.tag != 'inventory':
378
372
            raise errors.UnexpectedInventoryFormat('Root tag is %r' % elt.tag)
385
379
            revision_id = cache_utf8.encode(revision_id)
386
380
        inv = inventory.Inventory(root_id=None, revision_id=revision_id)
387
381
        for e in elt:
388
 
            ie = self._unpack_entry(e, entry_cache=entry_cache,
389
 
                                    return_from_cache=return_from_cache)
 
382
            ie = self._unpack_entry(e, entry_cache=entry_cache)
390
383
            inv.add(ie)
391
384
        self._check_cache_size(len(inv), entry_cache)
392
385
        return inv
393
386
 
394
 
    def _unpack_entry(self, elt, entry_cache=None, return_from_cache=False):
 
387
    def _unpack_entry(self, elt, entry_cache=None):
395
388
        elt_get = elt.get
396
389
        file_id = elt_get('file_id')
397
390
        revision = elt_get('revision')
435
428
                pass
436
429
            else:
437
430
                # Only copying directory entries drops us 2.85s => 2.35s
438
 
                if return_from_cache:
439
 
                    if cached_ie.kind == 'directory':
440
 
                        return cached_ie.copy()
441
 
                    return cached_ie
 
431
                # if cached_ie.kind == 'directory':
 
432
                #     return cached_ie.copy()
 
433
                # return cached_ie
442
434
                return cached_ie.copy()
443
435
 
444
436
        kind = elt.tag