~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/util/elementtree/ElementTree.py

  • Committer: Patch Queue Manager
  • Date: 2011-12-21 21:56:31 UTC
  • mfrom: (6393.2.4 907268-bazaar-DEFAULT)
  • Revision ID: pqm@pqm.ubuntu.com-20111221215631-coxvalt3phw8jaza
(vila) bzr config displays [DEFAULT] for bazaar.conf (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
# OF THIS SOFTWARE.
68
68
# --------------------------------------------------------------------
69
69
 
 
70
from __future__ import absolute_import
 
71
 
70
72
__all__ = [
71
73
    # public symbols
72
74
    "Comment",
572
574
    # @defreturn Element
573
575
 
574
576
    def parse(self, source, parser=None):
575
 
        if not hasattr(source, "read"):
 
577
        if getattr(source, "read", None) is None:
576
578
            source = open(source, "rb")
577
579
        if not parser:
578
580
            parser = XMLTreeBuilder()
651
653
 
652
654
    def write(self, file, encoding="us-ascii"):
653
655
        assert self._root is not None
654
 
        if not hasattr(file, "write"):
 
656
        if getattr(file, "write", None) is None:
655
657
            file = open(file, "wb")
656
658
        if not encoding:
657
659
            encoding = "us-ascii"
723
725
def iselement(element):
724
726
    # FIXME: not sure about this; might be a better idea to look
725
727
    # for tag/attrib/text attributes
726
 
    return isinstance(element, _ElementInterface) or hasattr(element, "tag")
 
728
    return isinstance(element, _ElementInterface) or (getattr(element, "tag", None) is not None)
727
729
 
728
730
##
729
731
# Writes an element tree or element structure to sys.stdout.  This
871
873
class iterparse:
872
874
 
873
875
    def __init__(self, source, events=None):
874
 
        if not hasattr(source, "read"):
 
876
        if getattr(source, "read", None) is None:
875
877
            source = open(source, "rb")
876
878
        self._file = source
877
879
        self._events = []
1037
1039
 
1038
1040
    def close(self):
1039
1041
        assert len(self._elem) == 0, "missing end tags"
1040
 
        assert self._last != None, "missing toplevel element"
 
1042
        assert self._last is not None, "missing toplevel element"
1041
1043
        return self._last
1042
1044
 
1043
1045
    def _flush(self):