Skip to content

Commit 66924d9

Browse files
ThunderEXdpgeorge
authored andcommitted
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.
1 parent fe3e0a2 commit 66924d9

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

micropython/xmltok/xmltok.py

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def eof(self):
3131
def nextch(self):
3232
self.c = self.f.read(1)
3333
if not self.c:
34-
raise StopIteration
34+
raise EOFError
3535
return self.c
3636

3737
def skip_ws(self):
@@ -87,36 +87,39 @@ def lex_attrs_till(self):
8787

8888
def tokenize(self):
8989
while not self.eof():
90-
if self.match("<"):
91-
if self.match("/"):
92-
yield (END_TAG, self.getnsident())
93-
self.expect(">")
94-
elif self.match("?"):
95-
yield (PI, self.getident())
96-
yield from self.lex_attrs_till()
97-
self.expect("?")
98-
self.expect(">")
99-
elif self.match("!"):
100-
self.expect("-")
101-
self.expect("-")
102-
last3 = ""
103-
while True:
104-
last3 = last3[-2:] + self.getch()
105-
if last3 == "-->":
106-
break
107-
else:
108-
tag = self.getnsident()
109-
yield (START_TAG, tag)
110-
yield from self.lex_attrs_till()
90+
try:
91+
if self.match("<"):
11192
if self.match("/"):
112-
yield (END_TAG, tag)
113-
self.expect(">")
114-
else:
115-
text = ""
116-
while self.curch() != "<":
117-
text += self.getch()
118-
if text:
119-
yield (TEXT, text)
93+
yield (END_TAG, self.getnsident())
94+
self.expect(">")
95+
elif self.match("?"):
96+
yield (PI, self.getident())
97+
yield from self.lex_attrs_till()
98+
self.expect("?")
99+
self.expect(">")
100+
elif self.match("!"):
101+
self.expect("-")
102+
self.expect("-")
103+
last3 = ""
104+
while True:
105+
last3 = last3[-2:] + self.getch()
106+
if last3 == "-->":
107+
break
108+
else:
109+
tag = self.getnsident()
110+
yield (START_TAG, tag)
111+
yield from self.lex_attrs_till()
112+
if self.match("/"):
113+
yield (END_TAG, tag)
114+
self.expect(">")
115+
else:
116+
text = ""
117+
while self.curch() != "<":
118+
text += self.getch()
119+
if text:
120+
yield (TEXT, text)
121+
except EOFError:
122+
pass
120123

121124

122125
def gfind(gen, pred):

0 commit comments

Comments
 (0)