Skip to content

Commit

Permalink
Merge pull request #40 from reverbc/support-membership-operator
Browse files Browse the repository at this point in the history
support 'in' and 'not in' operator
  • Loading branch information
Christian Stefanescu authored Jul 20, 2017
2 parents 39a05da + 87fb7f1 commit a18c171
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Christian Stefanescu <chris@0chris.com>

Florian Idelberger <flo@terrorpop.de>
Apalala <apalala@gmail.com>
Reverb Chu <reverbc@me.com>
8 changes: 8 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ def test_basic(self):
self.assert_(o.a is not None)
self.assert_(o.a.b is not None)
self.assert_(o.a.c is not None)
self.assert_('a' in o)
self.assert_('b' in o.a)
self.assert_('c' in o.a)
self.assert_('d' not in o.a)

def test_basic_with_decl(self):
o = untangle.parse("<?xml version='1.0'?><a><b/><c/></a>")
self.assert_(o is not None)
self.assert_(o.a is not None)
self.assert_(o.a.b is not None)
self.assert_(o.a.c is not None)
self.assert_('a' in o)
self.assert_('b' in o.a)
self.assert_('c' in o.a)
self.assert_('d' not in o.a)

def test_with_attributes(self):
o = untangle.parse('''
Expand Down
3 changes: 3 additions & 0 deletions untangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def __dir__(self):
def __len__(self):
return len(self.children)

def __contains__(self, key):
return key in dir(self)


class Handler(handler.ContentHandler):
"""
Expand Down

0 comments on commit a18c171

Please sign in to comment.