def compile(self, compiler): """ Generates opcodes for the expression: context.variables[namespaceUri, localName] where `namespaceUri` is the URI bound to the prefix of the qualified name for the variable reference. """ # Construct the expanded-name tuple prefix, local = splitqname(self._name) if prefix: try: namespace = compiler.namespaces[prefix] except KeyError: raise XPathError(XPathError.UNDEFINED_PREFIX, prefix=prefix) else: namespace = None if (namespace, local) not in compiler.variables: raise XPathError(XPathError.UNDEFINED_VARIABLE, variable=self._name, key=(namespace, local)) # Add the actual opcodes compiler.emit('LOAD_FAST', 'context', 'LOAD_ATTR', 'variables', 'LOAD_CONST', namespace, 'LOAD_CONST', local, 'BUILD_TUPLE', 2, 'BINARY_SUBSCR') return
def expand_qname(self, name): if not name: return None prefix, name = splitqname(name) if prefix: try: namespace = self.namespaces[prefix] except KeyError: raise XPathError(XPathError.UNDEFINED_PREFIX, prefix=prefix) else: namespace = None return (namespace, name)