use 'next(iter)' instead of 'iter.next()' to support py2/py3 compatibiity. refs #1350.

This commit is contained in:
Takayuki Shimizukawa 2014-05-01 12:49:47 +09:00
parent 27ac856300
commit 071fb45a54

View File

@ -177,7 +177,7 @@ class _SelectorContext:
def find(elem, path): def find(elem, path):
try: try:
return findall(elem, path).next() return next(findall(elem, path))
except StopIteration: except StopIteration:
return None return None
@ -194,17 +194,17 @@ def findall(elem, path):
if path[:1] == "/": if path[:1] == "/":
raise SyntaxError("cannot use absolute path on element") raise SyntaxError("cannot use absolute path on element")
stream = iter(xpath_tokenizer(path)) stream = iter(xpath_tokenizer(path))
next = stream.next; token = next() next_ = lambda: next(stream); token = next_()
selector = [] selector = []
while 1: while 1:
try: try:
selector.append(ops[token[0]](next, token)) selector.append(ops[token[0]](next_, token))
except StopIteration: except StopIteration:
raise SyntaxError("invalid path") raise SyntaxError("invalid path")
try: try:
token = next() token = next_()
if token[0] == "/": if token[0] == "/":
token = next() token = next_()
except StopIteration: except StopIteration:
break break
_cache[path] = selector _cache[path] = selector
@ -220,7 +220,7 @@ def findall(elem, path):
def findtext(elem, path, default=None): def findtext(elem, path, default=None):
try: try:
elem = findall(elem, path).next() elem = next(findall(elem, path))
return elem.text return elem.text
except StopIteration: except StopIteration:
return default return default