Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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)