~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/newinventory.py

  • Committer: mbp at sourcefrog
  • Date: 2005-04-07 06:16:02 UTC
  • Revision ID: mbp@sourcefrog.net-20050407061602-6b7da239ef883b0817b7fcd3
more XML performance tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
    f.write('\n')
63
63
 
64
64
 
 
65
 
 
66
def escape_attr(text):
 
67
    return text.replace("&", "&") \
 
68
           .replace("'", "'") \
 
69
           .replace('"', """) \
 
70
           .replace("<", "&lt;") \
 
71
           .replace(">", "&gt;")
 
72
 
 
73
 
65
74
# This writes out an inventory without building an XML tree first,
66
75
# just to see if it's faster.  Not currently used.
67
76
def write_slacker_inventory(inv, f):
68
77
    def descend(ie):
69
78
        kind = ie.kind
70
 
        f.write('<%s name="%s" id="%s" ' % (kind, ie.name, ie.file_id))
 
79
        f.write('<%s name="%s" id="%s" ' % (kind, escape_attr(ie.name),
 
80
                                            escape_attr(ie.file_id)))
71
81
 
72
82
        if kind == 'file':
73
83
            if ie.text_id:
90
100
            bailout('unknown InventoryEntry kind %r' % kind)
91
101
 
92
102
    f.write('<inventory>\n')
93
 
    f.write('<root_directory id="bogus-root-id">\n')
 
103
    f.write('<root_directory id="%s">\n' % escape_attr(inv.root.file_id))
94
104
 
95
105
    l = inv.root.children.items()
96
106
    l.sort()