kopia lustrzana https://github.com/micropython/micropython-lib
xmltok: Change StopIteration to EOFError due to PEP-479.
Due to changes in MicroPython to support PEP-479, StopIteration has been deprecated for return. This results in xmltok to raise RuntimeError every time. This commit is a simple fix to just change from StopIteration to EOFError and then return it in the generator.pull/411/head
rodzic
fe3e0a2fae
commit
66924d9fa1
|
@ -31,7 +31,7 @@ class XMLTokenizer:
|
||||||
def nextch(self):
|
def nextch(self):
|
||||||
self.c = self.f.read(1)
|
self.c = self.f.read(1)
|
||||||
if not self.c:
|
if not self.c:
|
||||||
raise StopIteration
|
raise EOFError
|
||||||
return self.c
|
return self.c
|
||||||
|
|
||||||
def skip_ws(self):
|
def skip_ws(self):
|
||||||
|
@ -87,36 +87,39 @@ class XMLTokenizer:
|
||||||
|
|
||||||
def tokenize(self):
|
def tokenize(self):
|
||||||
while not self.eof():
|
while not self.eof():
|
||||||
if self.match("<"):
|
try:
|
||||||
if self.match("/"):
|
if self.match("<"):
|
||||||
yield (END_TAG, self.getnsident())
|
|
||||||
self.expect(">")
|
|
||||||
elif self.match("?"):
|
|
||||||
yield (PI, self.getident())
|
|
||||||
yield from self.lex_attrs_till()
|
|
||||||
self.expect("?")
|
|
||||||
self.expect(">")
|
|
||||||
elif self.match("!"):
|
|
||||||
self.expect("-")
|
|
||||||
self.expect("-")
|
|
||||||
last3 = ""
|
|
||||||
while True:
|
|
||||||
last3 = last3[-2:] + self.getch()
|
|
||||||
if last3 == "-->":
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
tag = self.getnsident()
|
|
||||||
yield (START_TAG, tag)
|
|
||||||
yield from self.lex_attrs_till()
|
|
||||||
if self.match("/"):
|
if self.match("/"):
|
||||||
yield (END_TAG, tag)
|
yield (END_TAG, self.getnsident())
|
||||||
self.expect(">")
|
self.expect(">")
|
||||||
else:
|
elif self.match("?"):
|
||||||
text = ""
|
yield (PI, self.getident())
|
||||||
while self.curch() != "<":
|
yield from self.lex_attrs_till()
|
||||||
text += self.getch()
|
self.expect("?")
|
||||||
if text:
|
self.expect(">")
|
||||||
yield (TEXT, text)
|
elif self.match("!"):
|
||||||
|
self.expect("-")
|
||||||
|
self.expect("-")
|
||||||
|
last3 = ""
|
||||||
|
while True:
|
||||||
|
last3 = last3[-2:] + self.getch()
|
||||||
|
if last3 == "-->":
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
tag = self.getnsident()
|
||||||
|
yield (START_TAG, tag)
|
||||||
|
yield from self.lex_attrs_till()
|
||||||
|
if self.match("/"):
|
||||||
|
yield (END_TAG, tag)
|
||||||
|
self.expect(">")
|
||||||
|
else:
|
||||||
|
text = ""
|
||||||
|
while self.curch() != "<":
|
||||||
|
text += self.getch()
|
||||||
|
if text:
|
||||||
|
yield (TEXT, text)
|
||||||
|
except EOFError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def gfind(gen, pred):
|
def gfind(gen, pred):
|
||||||
|
|
Ładowanie…
Reference in New Issue