
Bob Kline schrieb am 22.03.2017 um 00:41:
When I actually tried to apply the approach I just described, I discovered that I'm not able to get to the context_node member of the context argument at all (not even to print its type), even though I can see that it's there (by looking at the output of print(dir(context))).
def ext_function(context, arg=None): print(dir(context)) print(type(context.context_node)) ....
The first print statement shows [..., 'context_node', 'eval_context'] but the second triggers an exception:
.... print(type(context.context_node)) File "src\lxml\extensions.pxi", line 315, in lxml.etree._BaseContext.context_node.__get__ (src\lxml\lxml.etree.c:159971) File "src\lxml\lxml.etree.pyx", line 1617, in lxml.etree._elementFactory (src\lxml\lxml.etree.c:59684) File "src\lxml\classlookup.pxi", line 407, in lxml.etree._parser_class_lookup (src\lxml\lxml.etree.c:92440) File "src\lxml\classlookup.pxi", line 259, in lxml.etree._callLookupFallback (src\lxml\lxml.etree.c:90672) File "src\lxml\classlookup.pxi", line 338, in lxml.etree._lookupDefaultElementClass (src\lxml\lxml.etree.c:91744) AssertionError: Unknown node type: 9
I can't recall ever failing to print out the type of something which I can see is there. Any idea what's going on?
This fails because the context_node is actually the document node, which does not have a Python representation in lxml. I guess it shouldn't fail to access that, though... Stefan