Exemplo n.º 1
0
    def processXml(self, context, data_node):

        tagname, namespace = utils.fixtag(data_node.tag, context.ns_map)

        if tagname == 'metadata':
            # ignore the container
            return False

        elif tagname in ('compound', 'array'):
            # basic at field specified, find the matching attribute
            # and annotate the data node with it
            schema_name = data_node.attrib.get('name', None)
            if schema_name is None:
                schema_name = data_node.attrib.get('id', )
                log("field %s: 'id' attribute is deprecated, use 'name' instead"
                    % schema_name)

            assert schema_name, "No field name specified in cf:[array|compound] element"
            #print "field", schema_name
            self.last_schema_id = schema_name
            attribute = self.getAttributeByName(schema_name, context)
            if attribute is None:
                #print "na", schema_name
                return False
            data_node.attribute = attribute
            return True

        return False
Exemplo n.º 2
0
    def processXml(self, context, data_node):

        tagname, namespace = utils.fixtag(data_node.tag, context.ns_map)
        
        if tagname == 'metadata':
            # ignore the container
            return False

        elif tagname in ('compound','array'):
            # basic at field specified, find the matching attribute
            # and annotate the data node with it
            schema_name = data_node.attrib.get('name', None)
            if schema_name is None:
                schema_name = data_node.attrib.get('id',)
                log("field %s: 'id' attribute is deprecated, use 'name' instead" % schema_name)

            assert schema_name, "No field name specified in cf:[array|compound] element"
            #print "field", schema_name
            self.last_schema_id = schema_name
            attribute = self.getAttributeByName(schema_name, context)
            if attribute is None:
                #print "na", schema_name
                return False
            data_node.attribute = attribute
            return True

        return False
Exemplo n.º 3
0
    def parseXmlNode(self, context, node):
        '''parses the xml node and converts it into a compound field
        compliant dictionary'''

        tagname, namespace = utils.fixtag(node.tag, context.ns_map)
        
        if tagname == 'compound':
            return self.parseCompound(context,node)
        elif tagname == 'array':
            return self.parseArray(context,node)
        elif tagname == 'field':
            return node.text and node.text.strip()
Exemplo n.º 4
0
    def parseXmlNode(self, context, node):
        '''parses the xml node and converts it into a compound field
        compliant dictionary'''

        tagname, namespace = utils.fixtag(node.tag, context.ns_map)

        if tagname == 'compound':
            return self.parseCompound(context, node)
        elif tagname == 'array':
            return self.parseArray(context, node)
        elif tagname == 'field':
            return node.text and node.text.strip()
Exemplo n.º 5
0
    def processXml(self, context, node):
        """ handle the start of a xml tag with this namespace
        the namespace and the name of the tag are bound to node.

        if this method return false then the node is assumed to
        be junk and it is discarded.
        """
        tag, ns = utils.fixtag(node.tag, context.ns_map)
        attribute = self.getAttributeByName(tag)
        if attribute is None:
            return False
        node.set('attribute', attribute)
        return attribute.processXml(context, node)
Exemplo n.º 6
0
    def processXml(self, context, node):
        """ handle the start of a xml tag with this namespace
        the namespace and the name of the tag are bound to node.

        if this method return false then the node is assumed to
        be junk and it is discarded.
        """
        tag, ns = utils.fixtag(node.tag, context.ns_map)
        attribute = self.getAttributeByName(tag)
        if attribute is None:
            return False
        node.set('attribute', attribute)
        return attribute.processXml(context, node)
Exemplo n.º 7
0
    def processXml(self, context, node):

        tag, namespace = utils.fixtag(node.tag, context.ns_map)
        data = context.getDataFor(self.namespace.xmlns)
        nsprefix = node.tag[:node.tag.find('}') + 1]

        #iworkflow
        wf_nodes = node.findall(nsprefix + 'workflow')
        wf_ids = [(node.attrib.get(nsprefix + 'id') or
                   node.attrib.get('id')) for node in wf_nodes]
                   # be tolerant of namespace sloppyness ;)
        # ensure we have some ids at all
        assert wf_ids
        for wf_id in wf_ids:
            # ensure we have an id for each workflow
            assert wf_id

        wf_data = data.setdefault(self.name, {})
        for wf_id in wf_ids:
            wf_data.setdefault(wf_id, [])
        # set _wf_pstate to the __last__ wf id in the list (the most recent)
        wf_pstate = data.setdefault('_wf_pstate', wf_ids[-1])

        #history
        for idx, wf_node in enumerate(wf_nodes):
            wf_id = wf_ids[idx]
            hist_nodes = wf_node.findall(nsprefix + 'history')
            for hist_node in hist_nodes:
                record = {}
                data[self.name][wf_id].append(record)

                #var
                var_nodes = hist_node.findall(nsprefix + 'var')
                vid = vtype = value = None

                for var_node in var_nodes:
                    vid = (var_node.attrib.get(nsprefix + 'id') or
                           var_node.attrib.get('id'))
                    vtype = (var_node.attrib.get(nsprefix + 'type', None) or
                             var_node.attrib.get('type'))
                    value = (var_node.attrib.get(nsprefix + 'value', None) or
                             var_node.attrib.get('value') or '')

                    assert vid and vtype and not value is None

                    value = demarshall_value(value, vtype)
                    data[self.name][wf_id][-1][vid] = value

        return True
Exemplo n.º 8
0
Arquivo: atxml.py Projeto: a25kk/stv2
    def parseXml(self, root, context, ns_map):
        """
        input read and dispatch loop
        """
        read_result = 1
        for node in root:
            tag, namespace = utils.fixtag(node.tag, context.ns_map)
                
            if namespace.processXml(context, node):
                context.node=node
                context.node.attribute.processXmlValue(context, node.text)
            else:
                ## XXX: raise a warning that the attribute isnt defined in the schema
                pass

        return read_result
Exemplo n.º 9
0
    def parseXml(self, root, context, ns_map):
        """
        input read and dispatch loop
        """
        read_result = 1
        for node in root:
            tag, namespace = utils.fixtag(node.tag, context.ns_map)
            if namespace.processXml(context, node):
                context.node = node
                context.node.get('attribute').processXmlValue(
                    context, node.text)
            else:
                ## XXX: raise a warning that the attribute isnt defined
                ## XXX: in the schema
                pass

        return read_result
Exemplo n.º 10
0
    def processXml(self, context, node):

        tag, namespace = utils.fixtag(node.tag, context.ns_map)
        data = context.getDataFor(self.namespace.xmlns)
        nsprefix = node.tag[:node.tag.find('}') + 1]

        #iworkflow
        wf_node = node.find(nsprefix + 'workflow')
        wf_id = (wf_node.attrib.get(nsprefix + 'id') or
                 wf_node.attrib.get('id'))
                 #be tolerant with namespace sloppyness;)
        assert wf_id

        wf_data = data.setdefault(self.name, {})
        wf_data.setdefault(wf_id, [])
        wf_pstate = data.setdefault('_wf_pstate', wf_id)

        #history
        hist_nodes = wf_node.findall(nsprefix + 'history')
        wf_pstate = data['_wf_pstate']
        for hist_node in hist_nodes:
            record = {}
            data[self.name][wf_pstate].append(record)

            #var
            var_nodes = hist_node.findall(nsprefix + 'var')
            vid = vtype = value = None

            for var_node in var_nodes:
                vid = (var_node.attrib.get(nsprefix + 'id') or
                       var_node.attrib.get('id'))
                vtype = (var_node.attrib.get(nsprefix + 'type', None) or
                         var_node.attrib.get('type'))
                value = (var_node.attrib.get(nsprefix + 'value', None) or
                         var_node.attrib.get('value') or '')

                assert vid and vtype and not value is None

                value = demarshall_value(value, vtype)
                wf_pstate = data['_wf_pstate']
                data[self.name][wf_pstate][-1][vid] = value

        return True
Exemplo n.º 11
0
    def processXml(self, context, node):

        tag, namespace = utils.fixtag(node.tag, context.ns_map)
        data = context.getDataFor(self.namespace.xmlns)
        nsprefix = node.tag[:node.tag.find('}') + 1]

        #iworkflow
        wf_node = node.find(nsprefix + 'workflow')
        wf_id = (wf_node.attrib.get(nsprefix + 'id') or
                 wf_node.attrib.get('id'))
                 #be tolerant with namespace sloppyness;)
        assert wf_id

        wf_data = data.setdefault(self.name, {})
        wf_data.setdefault(wf_id, [])
        wf_pstate = data.setdefault('_wf_pstate', wf_id)

        #history
        hist_nodes = wf_node.findall(nsprefix + 'history')
        wf_pstate = data['_wf_pstate']
        for hist_node in hist_nodes:
            record = {}
            data[self.name][wf_pstate].append(record)

            #var
            var_nodes = hist_node.findall(nsprefix + 'var')
            vid = vtype = value = None

            for var_node in var_nodes:
                vid = (var_node.attrib.get(nsprefix + 'id') or
                       var_node.attrib.get('id'))
                vtype = (var_node.attrib.get(nsprefix + 'type', None) or
                         var_node.attrib.get('type'))
                value = (var_node.attrib.get(nsprefix + 'value', None) or
                         var_node.attrib.get('value') or '')

                assert vid and vtype and not value is None

                value = demarshall_value(value, vtype)
                wf_pstate = data['_wf_pstate']
                data[self.name][wf_pstate][-1][vid] = value

        return True
Exemplo n.º 12
0
    def processXml(self, context, node):

        tag, namespace = utils.fixtag(node.tag, context.ns_map)
        data = context.getDataFor(self.namespace.xmlns)
        nsprefix = node.tag[: node.tag.find("}") + 1]

        # iworkflow
        wf_node = node.find(nsprefix + "workflow")
        wf_id = wf_node.attrib.get(nsprefix + "id") or wf_node.attrib.get("id")
        # be tolerant with namespace sloppyness;)
        assert wf_id

        wf_data = data.setdefault(self.name, {})
        wf_data.setdefault(wf_id, [])
        wf_pstate = data.setdefault("_wf_pstate", wf_id)

        # history
        hist_nodes = wf_node.findall(nsprefix + "history")
        wf_pstate = data["_wf_pstate"]
        for hist_node in hist_nodes:
            record = {}
            data[self.name][wf_pstate].append(record)

            # var
            var_nodes = hist_node.findall(nsprefix + "var")
            vid = vtype = value = None

            for var_node in var_nodes:
                vid = var_node.attrib.get(nsprefix + "id") or var_node.attrib.get("id")
                vtype = var_node.attrib.get(nsprefix + "type", None) or var_node.attrib.get("type")
                value = var_node.attrib.get(nsprefix + "value", None) or var_node.attrib.get("value") or ""

                assert vid and vtype and not value is None

                value = demarshall_value(value, vtype)
                wf_pstate = data["_wf_pstate"]
                data[self.name][wf_pstate][-1][vid] = value

        return True
Exemplo n.º 13
0
Arquivo: atns.py Projeto: a25kk/stv2
    def processXml(self, context, data_node):

        tagname, namespace = utils.fixtag(data_node.tag, context.ns_map)
        
        if tagname == 'metadata':
            # ignore the container
            return False

        elif tagname == 'reference':
            # switch to reference mode, we tell the parser that we want
            # to explictly recieve all new node parse events, so we
            # can introspect the nested metadata that can be used
            # in reference specification.
            self.in_reference_mode = True
            self.new_reference_p = True
            assert self.last_schema_id
            context.setNamespaceDelegate( self )
            return False

        elif tagname == 'field':
            # basic at field specified, find the matching attribute
            # and annotate the data node with it
            schema_name = data_node.attrib.get('name', None)
            if schema_name is None:
                log("'id' attribute for at:field is deprecated, use 'name' instead")
                schema_name = data_node.attrib.get('id')
##            while context.reader.MoveToNextAttribute():
##                if context.reader.LocalName() == 'id':
##                    schema_name = context.reader.Value()
##                    break
            assert schema_name, "No field name specified in at:field element"
            #print "field", schema_name
            self.last_schema_id = schema_name
            attribute = self.getAttributeByName(schema_name, context)
            if attribute is None:
                #print "na", schema_name
                return False
            data_node.attribute = attribute
            return True
        
        elif self.in_reference_mode:
            # if we get new metadata elements while in references, they
            # are stored as additional data for resolving the reference
            # latter.
            data = context.getDataFor(self.xmlns)
            srefs = data.setdefault( self.last_schema_id, [])
            
            # if we've already added a reference to the node data,
            # put additional reference specification data onto the
            # existing reference.
            if self.new_reference_p:
                ref = Reference()
                srefs.append( ref )
                self.new_reference_p = False
            else:
                ref = srefs[-1]
                
            attribute = ReferenceAttribute( data_node.name, ref )
            data_node.attribute = attribute
            return True

        elif tagname in self.at_fields:
            # pseudo fields like uid which are specified in a custom manner
            attribute = self.getAttributeByName( tagname )
            if attribute is None:
                return False
            data_node.attribute = attribute
            return True

        return False
Exemplo n.º 14
0
    def processXml(self, context, data_node):

        tagname, namespace = utils.fixtag(data_node.tag, context.ns_map)

        if tagname == 'metadata':
            # ignore the container
            return False

        elif tagname == 'reference':
            # switch to reference mode, we tell the parser that we want
            # to explictly recieve all new node parse events, so we
            # can introspect the nested metadata that can be used
            # in reference specification.
            self.in_reference_mode = True
            self.new_reference_p = True
            assert self.last_schema_id
            context.setNamespaceDelegate(self)
            return False

        elif tagname == 'field':
            # basic at field specified, find the matching attribute
            # and annotate the data node with it
            schema_name = data_node.attrib.get('name', None)
            if schema_name is None:
                log("'id' attribute for at:field is deprecated, "
                    "use 'name' instead")
                schema_name = data_node.attrib.get('id')
            assert schema_name, "No field name specified in at:field element"
            #print "field", schema_name
            self.last_schema_id = schema_name
            attribute = self.getAttributeByName(schema_name, context)
            if attribute is None:
                #print "na", schema_name
                return False
            data_node.set('attribute', attribute)
            return True

        elif self.in_reference_mode:
            # if we get new metadata elements while in references, they
            # are stored as additional data for resolving the reference
            # latter.
            data = context.getDataFor(self.xmlns)
            srefs = data.setdefault(self.last_schema_id, [])

            # if we've already added a reference to the node data,
            # put additional reference specification data onto the
            # existing reference.
            if self.new_reference_p:
                ref = Reference()
                srefs.append(ref)
                self.new_reference_p = False
            else:
                ref = srefs[-1]

            attribute = ReferenceAttribute(data_node.name, ref)
            data_node.set('attribute', attribute)
            return True

        elif tagname in self.at_fields:
            # pseudo fields like uid which are specified in a custom manner
            attribute = self.getAttributeByName(tagname)
            if attribute is None:
                return False
            data_node.set('attribute', attribute)
            return True

        return False