[utils] Fix find_xpath_attr on 2.6
This commit is contained in:
parent
652f283135
commit
4eefbfdbfd
1 changed files with 5 additions and 0 deletions
|
@ -280,6 +280,11 @@ if sys.version_info >= (2, 7):
|
||||||
return node.find(expr)
|
return node.find(expr)
|
||||||
else:
|
else:
|
||||||
def find_xpath_attr(node, xpath, key, val):
|
def find_xpath_attr(node, xpath, key, val):
|
||||||
|
# Here comes the crazy part: In 2.6, if the xpath is a unicode,
|
||||||
|
# .//node does not match if a node is a direct child of . !
|
||||||
|
if isinstance(xpath, unicode):
|
||||||
|
xpath = xpath.encode('ascii')
|
||||||
|
|
||||||
for f in node.findall(xpath):
|
for f in node.findall(xpath):
|
||||||
if f.attrib.get(key) == val:
|
if f.attrib.get(key) == val:
|
||||||
return f
|
return f
|
||||||
|
|
Loading…
Reference in a new issue