~ubuntu-branches/ubuntu/trusty/bzr-xmloutput/trusty

« back to all changes in this revision

Viewing changes to .pc/02_elementtree/tests/elementtree_builder.py

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-02-21 11:30:46 UTC
  • Revision ID: package-import@ubuntu.com-20120221113046-n854cxkvrn6upq61
Tags: 0.8.8+bzr160-2
* Add patches to improve compatibility with newer versions of bzr:
 + 01_no_inventory: Don't rely on inventories being available
 + 02_elementtree: Use correct location of elementtree. Closes: #660728
 + 03_info_controldir: Fix support for 'bzr xmlinfo' in empty control
   directories.
 + 04_no_revision_history: Avoid using deprecated `Branch.revision_history`
   call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from bzrlib.xml_serializer import elementtree as elementtree
 
3
 
 
4
ET = elementtree.ElementTree
 
5
 
 
6
class _E(object):
 
7
    """ This is the E factory, taken from http://effbot.org/zone/element-builder.htm """
 
8
    def __call__(self, tag, *children, **attrib):
 
9
        elem = ET.Element(tag, attrib)
 
10
        for item in children:
 
11
            if isinstance(item, dict):
 
12
                elem.attrib.update(item)
 
13
            elif isinstance(item, basestring):
 
14
                if len(elem):
 
15
                    elem[-1].tail = (elem[-1].tail or "") + item
 
16
                else:
 
17
                    elem.text = (elem.text or "") + item
 
18
            elif ET.iselement(item):
 
19
                elem.append(item)
 
20
            else:
 
21
                raise TypeError("bad argument: %r" % item)
 
22
        return elem
 
23
 
 
24
    def __getattr__(self, tag):
 
25
        return self(tag)