When using rnc2rng in lxml.etree.RelaxNG.from_rnc_string() as described here, we get a crash with the following stack trace:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/dargueta/git/clinicalfiles/setup.py", line 107, in <module>
compile_all()
File "/Users/dargueta/git/clinicalfiles/setup.py", line 78, in compile_all
fileformat_xsd = xml.RelaxNG.from_rnc_string(rnc_fd.read())
File "src/lxml/relaxng.pxi", line 150, in lxml.etree.RelaxNG.from_rnc_string (src/lxml/lxml.etree.c:195588)
File "/Users/dargueta/.pyenv/versions/3.5.2/envs/clinical_files_35/lib/python3.5/site-packages/rnc2rng/__init__.py", line 7, in loads
return parser.parse(src)
File "/Users/dargueta/.pyenv/versions/3.5.2/envs/clinical_files_35/lib/python3.5/site-packages/rnc2rng/parser.py", line 529, in parse
return parser.parse(lex(src), state=State(fn, src))
UnboundLocalError: local variable 'fn' referenced before assignment
The problem is in parser.parse(), specifically here. If parse() is only given source code and no file, there is no else clause to set fn. We can fix this like so:
elif f is not None:
fn, src = f.name, f.read()
else:
fn = None
State properly handles a null filename (see here) so we know that None is a good default value.
When using
rnc2rng
inlxml.etree.RelaxNG.from_rnc_string()
as described here, we get a crash with the following stack trace:The problem is in
parser.parse()
, specifically here. Ifparse()
is only given source code and no file, there is noelse
clause to setfn
. We can fix this like so:State
properly handles a null filename (see here) so we know thatNone
is a good default value.