Ejemplo n.º 1
0
 def evaluate(self, context):
     """Returns a string"""
     (prefix, local) = self._key
     uri = context.processorNss.get(prefix)
     if prefix and not uri:
         raise RuntimeException(RuntimeException.UNDEFINED_PREFIX, prefix)
     expanded = (prefix and uri or EMPTY_NAMESPACE, local)
     try:
         return context.varBindings[expanded]
     except:
         raise RuntimeException(RuntimeException.UNDEFINED_VARIABLE,
                                expanded[0], expanded[1])
Ejemplo n.º 2
0
 def evaluate(self, context):
     arg0 = self._arg0.evaluate(context)
     if not self._func:
         (prefix, local) = self._key
         uri = context.processorNss.get(prefix)
         if prefix and not uri:
             raise RuntimeException(RuntimeException.UNDEFINED_PREFIX, prefix)
         expanded = (prefix and uri or EMPTY_NAMESPACE, local)
         self._func = (g_extFunctions.get(expanded) or
                       CoreFunctions.CoreFunctions.get(expanded, self.error))
     try:
         result = self._func(context, arg0)
     except TypeError:
         raise RuntimeException(RuntimeException.WRONG_ARGUMENTS, str(expanded), '')
     return result
Ejemplo n.º 3
0
def Concat(context, *args):
    """Function: <string> concat(<string>, <string>, ...)"""
    if len(args) < 1:
        raise RuntimeException(RuntimeException.WRONG_ARGUMENTS, 'concat',
                               _("at least 2 arguments expected"))
    return reduce(lambda a, b, c=context: a + Conversions.StringValue(b),
                  args,
                  '')
Ejemplo n.º 4
0
 def match(self, context, node, principalType=Node.ELEMENT_NODE):
     if node.nodeType == principalType:
         if node.localName == self._localName:
             try:
                 return node.namespaceURI == context.processorNss[
                     self._prefix]
             except KeyError:
                 raise RuntimeException(RuntimeException.UNDEFINED_PREFIX,
                                        self._prefix)
     return 0
Ejemplo n.º 5
0
 def match(self, context, node, principalType=Node.ELEMENT_NODE):
     if node.nodeType != principalType:
         return 0
     try:
         uri = self._prefix and context.processorNss[
             self._prefix] or EMPTY_NAMESPACE
     except KeyError:
         raise RuntimeException(RuntimeException.UNDEFINED_PREFIX,
                                self._prefix)
     return node.namespaceURI == uri
Ejemplo n.º 6
0
def LocalName(context, nodeSet=None):
    """Function: <string> local-name(<node-set>?)"""
    if nodeSet is None:
        node = context.node
    else:
        if type(nodeSet) != type([]):
            raise RuntimeException(RuntimeException.WRONG_ARGUMENTS,
                                   'local-name', _("expected node set"))
        nodeSet = Util.SortDocOrder(nodeSet)
        if type(nodeSet) != type([]) or len(nodeSet) == 0:
            return ''
        node = nodeSet[0]
    en = ExpandedName(node)
    if en == None or en.localName == None:
        return ''
    return en.localName
Ejemplo n.º 7
0
def Id(context, object):
    """Function: <node-set> id(<object>)"""
    id_list = []
    if type(object) != type([]):
        st = Conversions.StringValue(object)
        id_list = string.split(st)
    else:
        for n in object:
            id_list.append(Conversions.StringValue(n))
    rt = []
    for id in id_list:
        doc = context.node.ownerDocument or context.node
        elements = Util.ElementsById(doc.documentElement, id)
        if len(elements) > 1:
            raise RuntimeException(RuntimeException.WRONG_ARGUMENTS, 'id',
                                   _("argument not unique"))
        elif elements:
            # Must be 1
            rt.append(elements[0])
    return rt
Ejemplo n.º 8
0
def Count(context, nodeSet):
    """Function: <number> count(<node-set>)"""
    if type(nodeSet) != type([]):
        raise RuntimeException(RuntimeException.WRONG_ARGUMENTS, 'count',
                               _("expected node set argument"))
    return len(nodeSet)