Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support 'in' and 'not in' operator #40

Merged
merged 2 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -119,6 +119,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