summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/matcher/xpath.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2013-01-21 02:34:22 -0800
committerLance Stout <lancestout@gmail.com>2013-01-21 02:34:22 -0800
commitbad405bea96405eb952888dc6996b8b40be85ac4 (patch)
treeb5998707d5d8d836eaa807f1e755047c1aed5c48 /sleekxmpp/xmlstream/matcher/xpath.py
parent648f3f978a84445ed188be055453ac4cab3ed4f5 (diff)
parent4f9a95b011277ab64a137aceeb4df2e9fc0f1e25 (diff)
downloadslixmpp-bad405bea96405eb952888dc6996b8b40be85ac4.tar.gz
slixmpp-bad405bea96405eb952888dc6996b8b40be85ac4.tar.bz2
slixmpp-bad405bea96405eb952888dc6996b8b40be85ac4.tar.xz
slixmpp-bad405bea96405eb952888dc6996b8b40be85ac4.zip
Merge branch 'master' into develop
Diffstat (limited to 'sleekxmpp/xmlstream/matcher/xpath.py')
-rw-r--r--sleekxmpp/xmlstream/matcher/xpath.py37
1 files changed, 5 insertions, 32 deletions
diff --git a/sleekxmpp/xmlstream/matcher/xpath.py b/sleekxmpp/xmlstream/matcher/xpath.py
index 3f03e68e..f3d28429 100644
--- a/sleekxmpp/xmlstream/matcher/xpath.py
+++ b/sleekxmpp/xmlstream/matcher/xpath.py
@@ -9,16 +9,10 @@
:license: MIT, see LICENSE for more details
"""
-from sleekxmpp.xmlstream.stanzabase import ET
+from sleekxmpp.xmlstream.stanzabase import ET, fix_ns
from sleekxmpp.xmlstream.matcher.base import MatcherBase
-# Flag indicating if the builtin XPath matcher should be used, which
-# uses namespaces, or a custom matcher that ignores namespaces.
-# Changing this will affect ALL XPath matchers.
-IGNORE_NS = False
-
-
class MatchXPath(MatcherBase):
"""
@@ -38,6 +32,9 @@ class MatchXPath(MatcherBase):
expressions will be matched without using namespaces.
"""
+ def __init__(self, criteria):
+ self._criteria = fix_ns(criteria)
+
def match(self, xml):
"""
Compare a stanza's XML contents to an XPath expression.
@@ -59,28 +56,4 @@ class MatchXPath(MatcherBase):
x = ET.Element('x')
x.append(xml)
- if not IGNORE_NS:
- # Use builtin, namespace respecting, XPath matcher.
- if x.find(self._criteria) is not None:
- return True
- return False
- else:
- # Remove namespaces from the XPath expression.
- criteria = []
- for ns_block in self._criteria.split('{'):
- criteria.extend(ns_block.split('}')[-1].split('/'))
-
- # Walk the XPath expression.
- xml = x
- for tag in criteria:
- if not tag:
- # Skip empty tag name artifacts from the cleanup phase.
- continue
-
- children = [c.tag.split('}')[-1] for c in xml]
- try:
- index = children.index(tag)
- except ValueError:
- return False
- xml = list(xml)[index]
- return True
+ return x.find(self._criteria) is not None