예제 #1
0
    def serialize_task(self, task, skip_children=False):
        assert isinstance(task, Task)

        if isinstance(task.task_spec, SubWorkflow):
            raise TaskNotSupportedError(
                "Subworkflow tasks cannot be serialized (due to their use of" +
                " internal_data to store the subworkflow).")

        # We are not serializing task.workflow; the deserializer accepts
        # an already-deserialized Workflow instead.
        elem = etree.Element('task')
        if task.id is not None:
            SubElement(elem, 'id').text = str(task.id)
        if task.parent is not None:
            SubElement(elem, 'parent').text = str(task.parent.id)

        if not skip_children:
            children_elem = SubElement(elem, 'children')
            for child in task.children:
                child_elem = self.serialize_task(child)
                children_elem.append(child_elem)

        SubElement(elem, 'state').text = task.get_state_name()
        if task.triggered:
            SubElement(elem, 'triggered')
        SubElement(elem, 'spec').text = task.task_spec.name
        SubElement(elem, 'last-state-change').text = str(
            task.last_state_change)
        self.serialize_value_map(SubElement(elem, 'data'), task.data)
        internal_data_elem = SubElement(elem, 'internal-data')
        self.serialize_value_map(internal_data_elem, task.internal_data)

        return elem
예제 #2
0
    def __call__(self):
        self.request.environ[DISABLE_TRANSFORM_REQUEST_KEY] = True

        cat = getToolByName(self.context, 'portal_catalog')
        root = Element("casestudies")

        for brain in cat.searchResults(
            portal_type='eea.climateadapt.casestudy', review_state='published'):
            cs = brain.getObject()
            cs = cs._repr_for_arcgis()
            e_cs = SubElement(root, 'casestudy')
            e_attrs = SubElement(e_cs, 'attributes')
            for k, v in cs['attributes'].items():
                el = Element(k)

                if isinstance(v, str):
                    el.text = v.decode('utf-8').strip()
                else:
                    el.text = unicode(v).strip()
                e_attrs.append(el)
            e_geo = SubElement(e_cs, 'geometry')
            for k, v in cs['geometry'].items():
                el = Element(k)
                el.text = unicode(v)
                e_geo.append(el)

        res = tostring(root, pretty_print=True)
        return res
    def process(self, lxmlNode):
        def prefixForNamespace(ns):
            if ns in prefixes:
                return prefixes[ns]
            return self._namespaceEnum.get(ns)

        def filterOac(nodes):
            result = []
            for node in nodes:
                namespace, name = splitType(getAttrib(node, 'rdf:resource'))
                if namespace == namespaces['oa']:
                    result.append(node)
            return result

        descriptions = xpath(lxmlNode, "//rdf:Description[rdf:type]")
        for description in descriptions:
            nodes = xpath(description, "rdf:type")
            oacNodes = filterOac(nodes)
            typeNode = nodes[0]
            if len(oacNodes) > 0:
                typeNode = oacNodes[0]

            parent = description.getparent()
            namespace, name = splitType(getAttrib(typeNode, 'rdf:resource'))
            prefix = prefixForNamespace(namespace)
            newNode = SubElement(
                parent, 
                "{%(ns)s}%(tag)s" % {'ns': namespace, 'tag': name}, 
                attrib=description.attrib,
                nsmap={prefix: namespace})
            for child in (child for child in description.getchildren() if child != typeNode):
                newNode.append(child)
            parent.remove(description)

        yield self.all.process(lxmlNode=lxmlNode)
    def _to_xsd_type(self, type_prefix):
        xsd_uri = self.nsmap["xs"]

        # Create an xs:complexType element

        # Note: This type-name will not be prefixed with type_prefix, as it is
        # computed from the object's type-name (and we want to re-use it).

        tname = self.typename
        e = Element(QName(xsd_uri, "complexType"), attrib={"name": tname})
        e1 = SubElement(e, QName(xsd_uri, "all"))

        # Create an xs:element for each field

        ys_prefix = type_prefix + "_" + self.typename
        tdefs = {}
        for k, yf in self.obj.iter_fields(exclude_properties=True):
            yv = yf.get(self.obj)
            yf1 = yf.bind(FieldContext(key=k, value=yv))
            ys = serializer_for_field(yf1)
            ys.target_namespace = self.target_namespace
            ye, ye_tdefs = ys.to_xsd(type_prefix=ys_prefix)
            e1.append(ye)
            tdefs.update(ye_tdefs)

        tdefs[tname] = e
        return ("target:" + tname, tdefs)
예제 #5
0
파일: wsdl11.py 프로젝트: 1-bit/spyne
    def add_port_type(self, service, root, service_name, types, url):
        # FIXME: I don't think this call is working.
        cb_port_type = self._add_callbacks(service, root, types,
                                                              service_name, url)
        applied_service_name = self._get_applied_service_name(service)

        port_binding_names = []
        port_type_list = service.get_port_types()
        if len(port_type_list) > 0:
            for port_type_name in port_type_list:
                port_type = self._get_or_create_port_type(port_type_name)
                port_type.set('name', port_type_name)

                binding_name = self._get_binding_name(port_type_name)
                port_binding_names.append((port_type_name, binding_name))

        else:
            port_type = self._get_or_create_port_type(service_name)
            port_type.set('name', service_name)

            binding_name = self._get_binding_name(service_name)
            port_binding_names.append((service_name, binding_name))

        for method in service.public_methods.values():
            check_method_port(service, method)

            if method.is_callback:
                operation = SubElement(cb_port_type, WSDL11("operation"))
            else:
                operation = SubElement(port_type, WSDL11("operation"))

            operation.set('name', method.operation_name)

            if method.doc is not None:
                operation.append(E(WSDL11("documentation"), method.doc))

            operation.set('parameterOrder', method.in_message.get_element_name())

            op_input = SubElement(operation, WSDL11("input"))
            op_input.set('name', method.in_message.get_element_name())
            op_input.set('message',
                          method.in_message.get_element_name_ns(self.interface))

            if (not method.is_callback) and (not method.is_async):
                op_output = SubElement(operation, WSDL11("output"))
                op_output.set('name', method.out_message.get_element_name())
                op_output.set('message', method.out_message.get_element_name_ns(
                                                                self.interface))

                if not (method.faults is None):
                    for f in method.faults:
                        fault = SubElement(operation, WSDL11("fault"))
                        fault.set('name', f.get_type_name())
                        fault.set('message', '%s:%s' % (
                                        f.get_namespace_prefix(self.interface),
                                        f.get_type_name()))

        ser = self.service_elt_dict[applied_service_name]
        for port_name, binding_name in port_binding_names:
            self._add_port_to_service(ser, port_name, binding_name)
예제 #6
0
    def add_custom_option(self, optionstr, content):
        """
        Add custom configuration option

        optionstr -- XPath-like expression for specifying XMvn configuration
                     option location with '/' used as delimiter

                     example: buildSettings/compilerSource
        content -- XML content to be added to specified node. Can be just text, XML node or multiple nodes.

                   examples:
                   someText
                   <someNode>someText</someNode><someOtherNode/>
        """
        node_names = optionstr.split("/")
        confpath = self.__get_current_config()
        root = self.__init_xml()
        par = root
        for node in node_names:
            par = SubElement(par, node)

        try:
            # wrap content into something to allow text content
            inserted = "<root>{0}</root>".format(content)
            contentRoot = ET.fromstring(inserted)
            par.text = contentRoot.text
            for element in contentRoot:
                par.append(element)
        except lxml.etree.XMLSyntaxError:
            raise XMvnConfigException("content is not valid content for XML node")
        self.__write_xml(confpath, root)
예제 #7
0
    def identify(self):
        envelope, e_identify = self._outputEnvelope(verb='Identify')
        identify = self._server.identify()
        e_repositoryName = SubElement(e_identify, nsoai('repositoryName'))
        e_repositoryName.text = identify.repositoryName()
        e_baseURL = SubElement(e_identify, nsoai('baseURL'))
        e_baseURL.text = identify.baseURL()
        e_protocolVersion = SubElement(e_identify, nsoai('protocolVersion'))
        e_protocolVersion.text = identify.protocolVersion()
        for adminEmail in identify.adminEmails():
            e = SubElement(e_identify, nsoai('adminEmail'))
            e.text = adminEmail
        e_earliestDatestamp = SubElement(e_identify,
                                         nsoai('earliestDatestamp'))
        e_earliestDatestamp.text = datetime_to_datestamp(
            identify.earliestDatestamp())
        e_deletedRecord = SubElement(e_identify,
                                     nsoai('deletedRecord'))
        e_deletedRecord.text = identify.deletedRecord()
        e_granularity = SubElement(e_identify, nsoai('granularity'))
        e_granularity.text = identify.granularity()
        compressions = identify.compression()
        if compressions != ['identity']:
            for compression in compressions:
                e_compression = SubElement(e_identify, nsoai('compression'))
                e_compression.text = compression

        for description in identify.descriptions():
            e_description = SubElement(e_identify, nsoai('description'))
            e_description.append(etree.fromstring(description))
        return envelope
예제 #8
0
파일: web.py 프로젝트: bbqsrc/hardvote
	def get_form(self, node):
		ns = NS['poll']
		form = Element("form", method="post", id="poll-form")
		qn = 0
		for n, element in enumerate(node.getiterator(ns + "section")):
			section = SubElement(form, "div", {
				"class": "section",
				"id": str(n + 1)
			})

			if element.attrib.get("title"):
				SubElement(section, 'h1').text = element.attrib["title"]

			for question in element.getchildren():
				qn += 1
				try:
					if question.tag != ns + "question":
						continue
					#func = getattr(self, "get_%s" % question.attrib.get('type'))
					#div = func(question, qn)
					div = Handlers.get(question, qn)
					#div = self.set_validation(question, div)	
					
					section.append(div)
				
				except AttributeError as e:
					print(e) # XXX stub
					print(question.attrib)
		
		form.append(self.get_submit_section())
		return form
예제 #9
0
파일: ymir.py 프로젝트: karlcow/ymir
def makefeedentry(feedentry_data):
    """Create an individual Atom feed entry from a ready to be publish post."""
    entry = Element('{http://www.w3.org/2005/Atom}entry', nsmap=NSMAP2)
    id_element = SubElement(entry, 'id')
    id_element.text = feedentry_data['tagid']
    linkfeedentry = SubElement(entry, 'link')
    linkfeedentry.attrib["rel"] = "alternate"
    linkfeedentry.attrib["type"] = "text/html"
    linkfeedentry.attrib["href"] = feedentry_data['url']
    title = SubElement(entry, 'title')
    title.text = feedentry_data['title']
    published = SubElement(entry, 'published')
    published.text = feedentry_data['created']
    updated = SubElement(entry, 'updated')
    updated.text = feedentry_data['modified']
    content = SubElement(entry, 'content')
    content.attrib["type"] = "xhtml"
    # changing the namespace to HTML
    # so only the local root element (div) will get the namespace
    divcontent = SubElement(content, "{%s}div" % HTMLNS, nsmap=NSMAP)
    # Adding a full tree fragment.
    divcontent.append(feedentry_data['content'])
    linkselfatom = SubElement(entry, 'link', nsmap=NSMAP2)
    linkselfatom.attrib["rel"] = "license"
    linkselfatom.attrib["href"] = LICENSELIST['ccby']
    entry = etree.parse(StringIO(etree.tostring(entry, encoding='utf-8')))
    logging.info("makefeedentry: new entry created")
    return entry
예제 #10
0
파일: tei.py 프로젝트: OpenPhilology/nidaba
 def _wrap_choices(alternatives, sic, parent):
     choice = SubElement(parent, self.tei_ns + 'choice')
     sic_el = SubElement(choice, self.tei_ns + 'sic')
     sic_el.append(sic)
     for alt in alternatives['content']:
         corr = SubElement(choice, self.tei_ns + 'corr')
         corr.text = alt['alternative']
         _set_confidence(corr, alternatives, alt)
예제 #11
0
    def export_comments(self, base_url):
        rss = Element('rss', self.nsmap)
        channel = SubElement(rss, 'channel')

        for nid in self.comments:
            channel.append(self.export_post_comments(nid, base_url))

        return rss
예제 #12
0
    def toxml(self, root, outfile=None, envelope=False):
        """Method creates sample xml file

        Args:
           root (str): root element name
           outfile (str): output filename, default sample.xml
           envelope (bool): create SOAP envelope 

        Returns:
           bool: result

        Raises:
           event: xmlgen_before_write
           event: xmlgen_after_write    

        """

        try:

            self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
                'datagen_xmlgen_write_sample'), self._mh.fromhere())
            ev = event.Event('xmlgen_before_write', root, outfile, envelope)
            if (self._mh.fire_event(ev) > 0):
                root = ev.argv(0)
                outfile = ev.argv(1)
                envelope = ev.argv(2)

            if (ev.will_run_default()):
                if (self._client == None):
                    raise ValueError('Specification is not imported yet')

                if (envelope):
                    ns = '{%s}' % 'http://schemas.xmlsoap.org/soap/envelope/'
                    doc = Element(ns + 'Envelope')
                    SubElement(doc, 'Header')
                    body = SubElement(doc, 'Body')
                    body.append(self._toxml_rec(root))
                else:
                    doc = self._toxml_rec(root)

                outfile = 'sample.xml' if (outfile == None) else outfile
                with open(outfile, 'w') as f:
                    f.write(tostring(
                        doc, encoding='UTF-8', xml_declaration=True, pretty_print=True).decode())

            self._mh.demsg('htk_on_debug_info', self._mh._trn.msg(
                'datagen_xmlgen_sample_written', outfile), self._mh.fromhere())
            ev = event.Event('xmlgen_after_write')
            self._mh.fire_event(ev)

            return True

        except (Exception, ValueError) as ex:
            self._mh.demsg(
                'htk_on_error', 'error: {0}'.format(ex), self._mh.fromhere())
            return False
예제 #13
0
파일: wsdl11.py 프로젝트: 1-bit/spyne
    def build_interface_document(self, url):
        """Build the wsdl for the application."""

        self.build_schema_nodes()

        self.url = REGEX_WSDL.sub('', url)

        service_name = self.interface.get_name()

        # create wsdl root node
        self.root_elt = root = etree.Element(WSDL11("definitions"),
                                                     nsmap=self.interface.nsmap)

        root.set('targetNamespace', self.interface.tns)
        root.set('name', service_name)

        # create types node
        types = SubElement(root, WSDL11("types"))
        for s in self.schema_dict.values():
            types.append(s)

        messages = set()
        for s in self.interface.services:
            self.add_messages_for_methods(s, root, messages)

        if self._with_plink:
            plink = SubElement(root, PLINK("partnerLinkType"))
            plink.set('name', service_name)
            self.__add_partner_link(service_name, plink)

        # create service nodes in advance. they're to be filled in subsequent
        # add_port_type calls.
        for s in self.interface.services:
            if not s.is_auxiliary():
                self._get_or_create_service_node(self._get_applied_service_name(s))

        # create portType nodes
        for s in self.interface.services:
            if not s.is_auxiliary():
                self.add_port_type(s, root, service_name, types, self.url)

        cb_binding = None
        for s in self.interface.services:
            if not s.is_auxiliary():
                cb_binding = self.add_bindings_for_methods(s, root,
                                                   service_name, cb_binding)

        if self.interface.app.transport is None:
            raise Exception("You must set the 'transport' property of the "
                            "parent 'Application' instance")

        self.event_manager.fire_event('document_built', self)
        self.event_manager.fire_event('wsdl_document_built', self)

        self.__wsdl = etree.tostring(root, xml_declaration=True,
                                                               encoding="UTF-8")
예제 #14
0
 def serialize_workflow_spec(self, spec, **kwargs):
     wf_elem = etree.Element('workflow')
     SubElement(wf_elem, 'name').text = spec.name
     SubElement(wf_elem, 'description').text = spec.description
     if spec.file:
         SubElement(wf_elem, 'filename').text = spec.file
     tasks_elem = SubElement(wf_elem, 'tasks')
     for task_name, task_spec in sorted(spec.task_specs.items()):
         tasks_elem.append(task_spec.serialize(self))
     return wf_elem
예제 #15
0
def write_landuse(lod, name, geometry_list, function = None, generic_attrib_dict = None):
    """
    This function writes the landuse cityobject member. Currently, only works for lod1.
 
    Parameters
    ----------
    lod : str
        The level of detail of the geometry of the landuse. The string should be in this form: "lod1". 
        
    name : str
        The name of the landuse.
        
    geometry_list : list of SurfaceMember
        The geometry of the landuse.
    
    function : str, optional
        The function of the landuse in gml code, e.g. for residential specify "1010", Default = None. Refer to CityGML 
        documentation for more information. https://www.citygml.org/
        
    generic_attrib_dict : dictionary, optional
        Extra attributes to be appended to the object, Default = None.
        The dictionary must have a string key which will be the name of the generic attributes, and either an int, float or str value.
            
    """
    cityObjectMember = Element('cityObjectMember')

    luse = SubElement(cityObjectMember, "{" + XMLNamespaces.luse+ "}" +'LandUse')
    luse.attrib["{" + XMLNamespaces.gml+ "}" +'id'] = name

    gml_name = SubElement(luse, "{" + XMLNamespaces.gml+ "}" + 'name')
    gml_name.text = name
   
    #=======================================================================================================
    #attribs
    #=======================================================================================================
    if function != None:
        luse_function = SubElement(luse, "{" + XMLNamespaces.luse+ "}" +'function')
        luse_function.text = function
       
    if generic_attrib_dict != None:
        write_gen_attribute(luse, generic_attrib_dict)

    #=======================================================================================================
    #geometries
    #=======================================================================================================
    if lod == "lod1":
        luse_lod1MultiSurface = SubElement(luse, "{" + XMLNamespaces.luse+ "}" + 'lod1MultiSurface')

        gml_MultiSurface = SubElement(luse_lod1MultiSurface, "{" + XMLNamespaces.gml+ "}" + 'MultiSurface')
        gml_MultiSurface.attrib["{" + XMLNamespaces.gml+ "}" +'id'] = 'UUID_' + str(uuid.uuid1())

    for geometry in geometry_list:
        gml_MultiSurface.append(geometry.construct())
      
    return cityObjectMember
예제 #16
0
    def add_analyses(self, elm):
        """
        Anlayses are added to the end of the regulation or notice.
        """

        analysis_elm = SubElement(elm, 'analysis')

        for label, analyses in self.layers['analyses'].items():
            for analysis_ref in analyses:
                analysis_section_elm = self.build_analysis(analysis_ref)
                analysis_elm.append(analysis_section_elm)
    def _to_xsd_type(self, type_prefix):
        xsd_uri = self.nsmap["xs"]
        xs = lambda name: QName(xsd_uri, name)

        # Create an xs:complexType element

        e = Element(xs("complexType"))
        e1 = SubElement(e, xs("sequence"))

        yf = self.field.value_type
        ys = serializer_for_field(yf)
        ys.target_namespace = self.target_namespace

        ys_prefix = "_".join((type_prefix, self.typename, "Y"))
        ye, ye_tdefs = ys.to_xsd(type_prefix=ys_prefix)

        ye.attrib["maxOccurs"] = "unbounded"
        e1.append(ye)

        # Extend type for item's element (ye) to carry a "key" attribute

        tdefs = ye_tdefs

        kf = self.field.key_type
        ks = serializer_for_field(kf)
        ks.target_namespace = self.target_namespace

        ks_prefix = "_".join((type_prefix, self.typename, "K"))
        ke, ke_tdefs = ks.to_xsd(type_prefix=ks_prefix)
        kt = ke.find(xs("simpleType"))

        ae = Element(xs("attribute"), attrib={"name": ks.name, "use": "required"})
        ae.append(kt)

        yt = ye.find(xs("complexType"))
        if yt is None:
            yt = ye.find(xs("simpleType"))
            # Handle an xs:simpleType definition
            yt_tname = "_".join((ys_prefix, ys.typename))
            yt.attrib["name"] = yt_tname
            # Move original xs:simpleType definition to the global scope
            ye.remove(yt)
            tdefs[yt_tname] = yt
            # Define a new xs:complexType based on yt type definition
            ye1 = SubElement(ye, xs("complexType"))
            ye11 = SubElement(ye1, xs("simpleContent"))
            ye111 = SubElement(ye11, xs("extension"), attrib={"base": "target:" + yt_tname})
            ye111.append(ae)
        else:
            # Handle an xs:complexType definition
            yt.append(ae)

        return (e, tdefs)
예제 #18
0
 def _set_parameter(self, _xpath_result, i, value_node):
     u"./{%(DEFAULT_NAMESPACE)s}parameter[$i+1]"
     arg_count = self.FUNCTIONS[ self.get(u'function') ]
     if _xpath_result:
         parent = _xpath_result[0]
     elif i < arg_count:
         while len(self) <= i:
             parent = SubElement(self, u'{%s}parameter' % SLOSL_NAMESPACE_URI)
     else:
         raise IndexError, "Maximum %s parameters allowed." % arg_count
     parent.clear()
     parent.append(value_node)
예제 #19
0
파일: tei.py 프로젝트: OpenPhilology/nidaba
 def _wrap_alternatives(alternatives, ins, parent):
     span = SubElement(parent, 'span')
     span.set('class', 'alternatives')
     ins_el = SubElement(span, 'ins')
     ins_el.set('class', 'alt')
     ins_el.append(ins)
     for alt in alternatives['content']:
         corr = SubElement(span, 'del')
         corr.set('class', 'alt')
         corr.text = alt['alternative']
         if 'confidence' in alt:
             corr.set('title', 'x_cost {}'.format(100 - alt['confidence']))
예제 #20
0
 def serialize_multi_choice(self, spec, elem=None):
     if elem is None:
         elem = etree.Element('multi-choice')
     if spec.choice:
         self.serialize_value_list(SubElement(elem, 'choice'), spec.choice)
     options = SubElement(elem, 'options')
     for condition, spec_name in spec.cond_task_specs:
         option_elem = SubElement(options, 'option')
         if condition is not None:
             cond_elem = SubElement(option_elem, 'condition')
             cond_elem.append(condition.serialize(self))
         SubElement(option_elem, 'output').text = spec_name
     return self.serialize_task_spec(spec, elem)
예제 #21
0
def identify(**kwargs):
    """Create OAI-PMH response for verb Identify."""
    cfg = current_app.config

    e_tree, e_identify = verb(**kwargs)

    e_repositoryName = SubElement(
        e_identify, etree.QName(NS_OAIPMH, 'repositoryName'))
    e_repositoryName.text = cfg['OAISERVER_REPOSITORY_NAME']

    e_baseURL = SubElement(e_identify, etree.QName(NS_OAIPMH, 'baseURL'))
    e_baseURL.text = url_for('invenio_oaiserver.response', _external=True)

    e_protocolVersion = SubElement(e_identify,
                                   etree.QName(NS_OAIPMH, 'protocolVersion'))
    e_protocolVersion.text = cfg['OAISERVER_PROTOCOL_VERSION']

    for adminEmail in cfg['OAISERVER_ADMIN_EMAILS']:
        e = SubElement(e_identify, etree.QName(NS_OAIPMH, 'adminEmail'))
        e.text = adminEmail

    e_earliestDatestamp = SubElement(
        e_identify, etree.QName(
            NS_OAIPMH, 'earliestDatestamp'))
    e_earliestDatestamp.text = datetime_to_datestamp(
        db.session.query(db.func.min(RecordMetadata.created)).scalar() or
        datetime(MINYEAR, 1, 1)
    )

    e_deletedRecord = SubElement(e_identify,
                                 etree.QName(NS_OAIPMH, 'deletedRecord'))
    e_deletedRecord.text = 'no'

    e_granularity = SubElement(e_identify,
                               etree.QName(NS_OAIPMH, 'granularity'))
    assert cfg['OAISERVER_GRANULARITY'] in DATETIME_FORMATS
    e_granularity.text = cfg['OAISERVER_GRANULARITY']

    compressions = cfg['OAISERVER_COMPRESSIONS']
    if compressions != ['identity']:
        for compression in compressions:
            e_compression = SubElement(e_identify,
                                       etree.QName(NS_OAIPMH, 'compression'))
            e_compression.text = compression

    for description in cfg.get('OAISERVER_DESCRIPTIONS', []):
        e_description = SubElement(e_identify,
                                   etree.QName(NS_OAIPMH, 'description'))
        e_description.append(etree.fromstring(description))

    return e_tree
    def _to_xsd_type(self, type_prefix):
        xsd_uri = self.nsmap["xs"]

        # Create an xs:simpleType element

        e = Element(QName(xsd_uri, "simpleType"))
        e1 = SubElement(e, QName(xsd_uri, "restriction"), attrib={"base": "xs:string"})

        # Enumerate possible values

        for t in self.field.vocabulary:
            e1.append(Element(QName(xsd_uri, "enumeration"), attrib={"value": t.value}))

        return (e, {})
예제 #23
0
    def change_service(self, service, customer=None, payer=None, subscriber=None, status=None, params={}):
        """Method changes service

        Args: 
           service (int): service id, lov_service.id
           customer (int): assigned customer id
           payer (int): assigned payer id
           subscriber (int): assigned subscriber id
           status (str): status, lov_status.title, default active
           params (dict): key (int), lov_service_param.id, value (str)  

        Returns:
           bool: result

        """

        msg = 'service:{0}, customer:{1}, payer:{2}, subscriber:{3}, status:{4}, params:{5}'.format(
              service, customer, payer, subscriber, status, params)
        self._mh.dmsg('htk_on_debug_info', self._mh._trn.msg('te_soap_func', 'change_service', msg),
                      self._mh.fromhere())

        root = Element(self._ns + 'change_service')
        SubElement(root, 'service').text = str(service)
        if (customer != None):
            SubElement(root, 'customer').text = str(customer)
        if (payer != None):
            SubElement(root, 'payer').text = str(payer)
        if (subscriber != None):
            SubElement(root, 'subscriber').text = str(subscriber)
        if (status != None):
            SubElement(root, 'status').text = status

        el_params = SubElement(root, 'params')
        for key, value in params.items():
            entry = Element('entry')
            SubElement(entry, 'key').text = str(key)
            SubElement(entry, 'value').text = value
            el_params.append(entry)

        res = self._client.send_request(
            'change_service', body=tostring(root), headers={'SOAPAction': 'change_service'})

        if (self.is_soap_fault(res)):
            self._mh.dmsg(
                'htk_on_extension_error', 'SOAP fault {0}'.format(res), self._mh.fromhere())
            return False
        else:
            self._mh.dmsg('htk_on_debug_info', self._mh._trn.msg('te_soap_entity_changed', 'service', service),
                          self._mh.fromhere())
            return True
예제 #24
0
def identify(**kwargs):
    """Create OAI-PMH response for verb Identify."""
    cfg = current_app.config

    e_tree, e_identify = verb(**kwargs)

    e_repositoryName = SubElement(e_identify,
                                  etree.QName(NS_OAIPMH, 'repositoryName'))
    e_repositoryName.text = cfg['OAISERVER_REPOSITORY_NAME']

    e_baseURL = SubElement(e_identify, etree.QName(NS_OAIPMH, 'baseURL'))
    e_baseURL.text = url_for('invenio_oaiserver.response', _external=True)

    e_protocolVersion = SubElement(e_identify,
                                   etree.QName(NS_OAIPMH, 'protocolVersion'))
    e_protocolVersion.text = cfg['OAISERVER_PROTOCOL_VERSION']

    for adminEmail in cfg['OAISERVER_ADMIN_EMAILS']:
        e = SubElement(e_identify, etree.QName(NS_OAIPMH, 'adminEmail'))
        e.text = adminEmail

    e_earliestDatestamp = SubElement(
        e_identify, etree.QName(NS_OAIPMH, 'earliestDatestamp'))
    e_earliestDatestamp.text = datetime_to_datestamp(
        db.session.query(db.func.min(RecordMetadata.created)).scalar()
        or datetime(MINYEAR, 1, 1))

    e_deletedRecord = SubElement(e_identify,
                                 etree.QName(NS_OAIPMH, 'deletedRecord'))
    e_deletedRecord.text = 'no'  # FIXME

    e_granularity = SubElement(e_identify, etree.QName(NS_OAIPMH,
                                                       'granularity'))
    e_granularity.text = ''  # FIXME identify.granularity()

    compressions = cfg['OAISERVER_COMPRESSIONS']
    if compressions != ['identity']:
        for compression in compressions:
            e_compression = SubElement(e_identify,
                                       etree.QName(NS_OAIPMH, 'compression'))
            e_compression.text = compression

    for description in cfg.get('OAISERVER_DESCRIPTIONS', []):
        e_description = SubElement(e_identify,
                                   etree.QName(NS_OAIPMH, 'description'))
        e_description.append(etree.fromstring(description))

    return e_tree
예제 #25
0
def write_tin_relief(lod, name, geometry_list):
    """
    This function writes the TIN relief cityobject member. Currently, only works for lod1.
 
    Parameters
    ----------
    lod : str
        The level of detail of the geometry of the tin relief. The string should be in this form: "lod1". 
        
    name : str
        The name of the relief feature.
        
    geometry_list : list of Triangle
        The geometry of the tin relief.
    """
    cityObjectMember = Element('cityObjectMember')
    
    relief_feature = SubElement(cityObjectMember, "{" + XMLNamespaces.dem+ "}" +'ReliefFeature')
    relief_feature.attrib["{" + XMLNamespaces.gml+ "}" +'id'] = name
    
    gml_name = SubElement(relief_feature, "{" + XMLNamespaces.gml+ "}" + 'name')
    gml_name.text = name
    
    #=======================================================================================================
    #geometries
    #=======================================================================================================
    if lod == "lod1":
        dem_lod = SubElement(relief_feature, "{" + XMLNamespaces.dem+ "}" + 'lod')
        dem_lod.text = "1"
        dem_reliefComponent = SubElement(relief_feature, "{" + XMLNamespaces.dem+ "}" + 'reliefComponent')
        
        dem_TINRelief = SubElement(dem_reliefComponent, "{" + XMLNamespaces.dem+ "}" + 'TINRelief')
        dem_TINRelief.attrib["{" + XMLNamespaces.gml+ "}" +'id'] = name+"dem"
        
        gml_name = SubElement(dem_TINRelief, "{" + XMLNamespaces.gml+ "}" + 'name')
        gml_name.text = "ground"
        dem_lod = SubElement(dem_TINRelief, "{" + XMLNamespaces.dem+ "}" + 'lod')
        dem_lod.text = "1"
        dem_tin =  SubElement(dem_TINRelief, "{" + XMLNamespaces.dem+ "}" + 'tin')
        
        gml_TriangulatedSurface = SubElement(dem_tin, "{" + XMLNamespaces.gml+ "}" + 'TriangulatedSurface')
        
        gml_trianglePatches = SubElement(gml_TriangulatedSurface, "{" + XMLNamespaces.gml+ "}" + 'trianglePatches')
        
        for geometry in geometry_list:
            gml_trianglePatches.append(geometry.construct())
            
    return cityObjectMember
    def _format_content(self, article, news_item, nitf):
        """Adds the content set to the xml

        :param dict article:
        :param Element newsItem:
        :param Element nitf:
        """
        content_set = SubElement(news_item, 'contentSet')
        if article.get(FORMAT) == FORMATS.PRESERVED:
            inline_data = text_utils.get_text(self.append_body_footer(article))
            SubElement(content_set, 'inlineData',
                       attrib={'contenttype': 'text/plain'}).text = inline_data
        elif article[ITEM_TYPE] in [CONTENT_TYPE.TEXT, CONTENT_TYPE.COMPOSITE]:
            inline = SubElement(content_set, 'inlineXML',
                                attrib={'contenttype': 'application/nitf+xml'})
            inline.append(nitf)
예제 #27
0
def Apply(parent, name, *args):
    """Create a new apply tag under the parent element, given the name
    of a function or operator and (optionally) its parameter elements
    as further arguments."""
    if isinstance(parent, MathDOM):
        parent = parent.getroot()
    apply_tag    = SubElement(parent,
                              '{%s}apply' % MATHML_NAMESPACE_URI)
    function_tag = SubElement(apply_tag,
                              '{%s}%s' % (MATHML_NAMESPACE_URI, name))
    if args:
        if len(args) == 1 and isinstance(args[0], (list, tuple)):
            args = args[0]
        for child in args:
            apply_tag.append(child)
    return apply_tag
예제 #28
0
    def _format_content(self, article, news_item, nitf):
        """Adds the content set to the xml

        :param dict article:
        :param Element newsItem:
        :param Element nitf:
        """
        content_set = SubElement(news_item, 'contentSet')
        if article.get(FORMAT) == FORMATS.PRESERVED:
            inline_data = text_utils.get_text(self.append_body_footer(article))
            SubElement(content_set, 'inlineData',
                       attrib={'contenttype': 'text/plain'}).text = inline_data
        elif article[ITEM_TYPE] in [CONTENT_TYPE.TEXT, CONTENT_TYPE.COMPOSITE]:
            inline = SubElement(content_set, 'inlineXML',
                                attrib={'contenttype': 'application/nitf+xml'})
            inline.append(nitf)
예제 #29
0
파일: Statistics.py 프로젝트: espro/bcfg2
    def updateStats(self, xml, client):
        """Updates the statistics of a current node with new data."""

        # Current policy:
        # - Keep anything less than 24 hours old
        #   - Keep latest clean run for clean nodes
        #   - Keep latest clean and dirty run for dirty nodes
        newstat = xml.find("Statistics")

        if newstat.get("state") == "clean":
            node_dirty = 0
        else:
            node_dirty = 1

        # Find correct node entry in stats data
        # The following list comprehension should be guarenteed to return at
        # most one result
        nodes = [elem for elem in self.element.findall("Node") if elem.get("name") == client]
        nummatch = len(nodes)
        if nummatch == 0:
            # Create an entry for this node
            node = SubElement(self.element, "Node", name=client)
        elif nummatch == 1 and not node_dirty:
            # Delete old instance
            node = nodes[0]
            [node.remove(elem) for elem in node.findall("Statistics") if self.isOlderThan24h(elem.get("time"))]
        elif nummatch == 1 and node_dirty:
            # Delete old dirty statistics entry
            node = nodes[0]
            [
                node.remove(elem)
                for elem in node.findall("Statistics")
                if (elem.get("state") == "dirty" and self.isOlderThan24h(elem.get("time")))
            ]
        else:
            # Shouldn't be reached
            self.logger.error("Duplicate node entry for %s" % (client))

        # Set current time for stats
        newstat.set("time", asctime(localtime()))

        # Add statistic
        node.append(copy.copy(newstat))

        # Set dirty
        self.dirty = 1
        self.WriteBack(force=1)
예제 #30
0
파일: Statistics.py 프로젝트: sbworth/bcfg2
    def updateStats(self, xml, client):
        """Updates the statistics of a current node with new data."""

        # Current policy:
        # - Keep anything less than 24 hours old
        #   - Keep latest clean run for clean nodes
        #   - Keep latest clean and dirty run for dirty nodes
        newstat = xml.find('Statistics')

        if newstat.get('state') == 'clean':
            node_dirty = 0
        else:
            node_dirty = 1

        # Find correct node entry in stats data
        # The following list comprehension should be guarenteed to return at
        # most one result
        nodes = [elem for elem in self.element.findall('Node') \
                 if elem.get('name') == client]
        nummatch = len(nodes)
        if nummatch == 0:
            # Create an entry for this node
            node = SubElement(self.element, 'Node', name=client)
        elif nummatch == 1 and not node_dirty:
            # Delete old instance
            node = nodes[0]
            [node.remove(elem) for elem in node.findall('Statistics') \
             if self.isOlderThan24h(elem.get('time'))]
        elif nummatch == 1 and node_dirty:
            # Delete old dirty statistics entry
            node = nodes[0]
            [node.remove(elem) for elem in node.findall('Statistics') \
             if (elem.get('state') == 'dirty' \
                 and self.isOlderThan24h(elem.get('time')))]
        else:
            # Shouldn't be reached
            self.logger.error("Duplicate node entry for %s" % (client))

        # Set current time for stats
        newstat.set('time', asctime(localtime()))

        # Add statistic
        node.append(copy.copy(newstat))

        # Set dirty
        self.dirty = 1
        self.WriteBack(force=1)
예제 #31
0
def write_transportation(trpt_type,
                         lod,
                         name,
                         geometry_list,
                         rd_class=None,
                         function=None,
                         generic_attrib_dict=None):
    cityObjectMember = Element('cityObjectMember')
    tran_trpt_type = SubElement(cityObjectMember,
                                "{" + XMLNamespaces.trans + "}" + trpt_type)
    tran_trpt_type.attrib["{" + XMLNamespaces.gml + "}" + 'id'] = name

    gml_name = SubElement(tran_trpt_type,
                          "{" + XMLNamespaces.gml + "}" + 'name')
    gml_name.text = name

    #=======================================================================================================
    #attrib
    #=======================================================================================================
    if rd_class != None:
        tran_class = SubElement(tran_trpt_type,
                                "{" + XMLNamespaces.trans + "}" + 'class')
        tran_class.text = rd_class
    if function != None:
        tran_function = SubElement(
            tran_trpt_type, "{" + XMLNamespaces.trans + "}" + 'function')
        tran_function.text = function
    if generic_attrib_dict != None:
        write_gen_Attribute(tran_trpt_type, generic_attrib_dict)

    #=======================================================================================================
    #geometries
    #=======================================================================================================
    if lod == "lod0":
        tran_lod0Network = SubElement(
            tran_trpt_type, "{" + XMLNamespaces.trans + "}" + 'lod0Network')
        gml_GeometricComplex = SubElement(
            tran_lod0Network,
            "{" + XMLNamespaces.gml + "}" + 'GeometricComplex')

        for geometry in geometry_list:
            gml_element = SubElement(gml_GeometricComplex,
                                     "{" + XMLNamespaces.gml + "}" + 'element')
            gml_element.append(geometry.construct())
            gml_GeometricComplex.append(gml_element)

    return cityObjectMember
예제 #32
0
def create_mets_xml_subelement(parent, element):
    """Create METS sub elements."""
    sub_element = SubElement(parent, element.tag)
    for attribute, value in element.atts.items():
        if not value:
            continue
        if not isinstance(value, str) and not isinstance(value, unicode):
            sub_element.set(attribute, str(value))
        else:
            sub_element.set(attribute, value)
    if element.content:
        sub_element.text = element.content
    for child in element.children:
        if element.tag == "xmlData":
            sub_element.append(child)
        else:
            create_mets_xml_subelement(sub_element, child)
예제 #33
0
def write_tin_relief(lod, name, geometry_list):
    cityObjectMember = Element('cityObjectMember')

    relief_feature = SubElement(
        cityObjectMember, "{" + XMLNamespaces.dem + "}" + 'ReliefFeature')
    relief_feature.attrib["{" + XMLNamespaces.gml + "}" + 'id'] = name

    gml_name = SubElement(relief_feature,
                          "{" + XMLNamespaces.gml + "}" + 'name')
    gml_name.text = name

    #=======================================================================================================
    #geometries
    #=======================================================================================================
    if lod == "lod1":
        dem_lod = SubElement(relief_feature,
                             "{" + XMLNamespaces.dem + "}" + 'lod')
        dem_lod.text = "1"
        dem_reliefComponent = SubElement(
            relief_feature, "{" + XMLNamespaces.dem + "}" + 'reliefComponent')

        dem_TINRelief = SubElement(dem_reliefComponent,
                                   "{" + XMLNamespaces.dem + "}" + 'TINRelief')
        dem_TINRelief.attrib["{" + XMLNamespaces.gml + "}" +
                             'id'] = name + "dem"

        gml_name = SubElement(dem_TINRelief,
                              "{" + XMLNamespaces.gml + "}" + 'name')
        gml_name.text = "ground"
        dem_lod = SubElement(dem_TINRelief,
                             "{" + XMLNamespaces.dem + "}" + 'lod')
        dem_lod.text = "1"
        dem_tin = SubElement(dem_TINRelief,
                             "{" + XMLNamespaces.dem + "}" + 'tin')

        gml_TriangulatedSurface = SubElement(
            dem_tin, "{" + XMLNamespaces.gml + "}" + 'TriangulatedSurface')

        gml_trianglePatches = SubElement(
            gml_TriangulatedSurface,
            "{" + XMLNamespaces.gml + "}" + 'trianglePatches')

        for geometry in geometry_list:
            gml_trianglePatches.append(geometry.construct())

    return cityObjectMember
예제 #34
0
 def call(self, action,tree):
     # build SOAP envelope
     envelope = Element(NS_SOAP_ENV + "Envelope")
     body = SubElement(envelope, NS_SOAP_ENV + "Body")
     request = SoapRequest("{http://www.cisco.com/AXL/API/9.1}" + action)
     if type(tree) == list:
         for l in tree:
             request.append(l)
     else:
         request.append(tree)
     body.append(request)
     # call the server
     print tostring(envelope,pretty_print=True)
     resp,resstr = self.__client.request(self.url,"POST",body=tostring(envelope),headers={'SOAPAction':'"CUCM:DB ver=9.1 ' + action + '"'})
     #Convert results back into element
     response = etree.fromstring(resstr)
     return response.find(body.tag)[0]
예제 #35
0
파일: objs.py 프로젝트: akx/foamy
    def marshal_multipart(self, wrapper, message):
        if not isinstance(message, dict):
            raise TypeError("Input must be dict when marshalling multipart messages (got %r)" % message)

        for name, type in self.parts:
            if name not in message:
                raise ValueError("While marshalling multipart message: Missing part %r" % name)
            subel = SubElement(wrapper, "{%s}%s" % (self.ns, name))
            marshalled = type.marshal(message[name])
            if hasattr(marshalled, "tag"):
                for child in marshalled.getchildren():
                    subel.append(child)
                subel.text = marshalled.text
                marshalled = None
            else:
                subel.text = marshalled
        return wrapper
예제 #36
0
파일: objs.py 프로젝트: akx/foamy
    def envelope_message(self, message, operation):
        # XXX: `encoded`/`literal` is blissfully ignored
        envelope = Element(NS.tag("soapenv", "Envelope"), nsmap=dict(NS))
        header = SubElement(envelope, NS.tag("soapenv", "Header"))
        body = SubElement(envelope, NS.tag("soapenv", "Body"))

        opbind = self.operation_bindings[operation]
        for el in operation.input.message.marshal(message, style=opbind["style"]):
            body.append(el)

        cleanup_namespaces(envelope)
        xml = tostring(envelope, pretty_print=True, encoding="UTF-8", xml_declaration=True)
        req = Request(
            None, {"Content-type": "text/xml; charset=utf-8", "SOAPAction": '"%s"' % opbind.get("soapAction")}, xml
        )

        return req
예제 #37
0
def getrecord(**kwargs):
    """Create OAI-PMH response for verb Identify."""
    record_dumper = serializer(kwargs['metadataPrefix'])
    pid = OAIIDProvider.get(pid_value=kwargs['identifier']).pid
    record = RecordMetadata.query.get(pid.object_uuid)

    e_tree, e_getrecord = verb(**kwargs)

    header(
        e_getrecord,
        identifier=str(pid.object_uuid),
        datestamp=record.updated,
        sets=record.json.get('_oai', []).get('sets', []),
    )
    e_metadata = SubElement(e_getrecord, etree.QName(NS_OAIPMH, 'metadata'))
    e_metadata.append(record_dumper(record.json))

    return e_tree
예제 #38
0
파일: xml.py 프로젝트: adbar/trafilatura
def write_teitree(docmeta):
    '''Bundle the extracted post and comments into a TEI tree'''
    teidoc = Element('TEI', xmlns='http://www.tei-c.org/ns/1.0')
    header = write_fullheader(teidoc, docmeta)
    textelem = SubElement(teidoc, 'text')
    textbody = SubElement(textelem, 'body')
    # post
    postbody = clean_attributes(docmeta.body)
    postbody.tag = 'div'
    postbody.set('type', 'entry') # rendition='#pst'
    textbody.append(postbody)
    # comments
    if docmeta.commentsbody is not None:
        commentsbody = clean_attributes(docmeta.commentsbody)
        commentsbody.tag = 'div'
        commentsbody.set('type', 'comments') # rendition='#cmt'
        textbody.append(commentsbody)
    return teidoc
예제 #39
0
    def _to_xsd_type(self, type_prefix):
        xsd_uri = self.nsmap['xs']

        # Create an xs:simpleType element

        e = Element(QName(xsd_uri, 'simpleType'))
        e1 = SubElement(e,
                        QName(xsd_uri, 'restriction'),
                        attrib={'base': 'xs:string'})

        # Enumerate possible values

        for t in self.field.vocabulary:
            e1.append(
                Element(QName(xsd_uri, 'enumeration'),
                        attrib={'value': t.value}))

        return (e, {})
예제 #40
0
def listrecords(**kwargs):
    """Create OAI-PMH response for verb ListIdentifiers."""
    record_dumper = serializer(kwargs['metadataPrefix'])

    e_tree, e_listrecords = verb(**kwargs)

    for record in get_records():
        pid = oaiid_fetcher(record['id'], record['json'])
        e_record = SubElement(e_listrecords,
                              etree.QName(NS_OAIPMH, 'record'))
        header(
            e_record,
            identifier=pid.pid_value,
            datestamp=record['updated'],
        )
        e_metadata = SubElement(e_record, etree.QName(NS_OAIPMH, 'metadata'))
        e_metadata.append(record_dumper(record['json']))

    return e_tree
예제 #41
0
def load_configuration(module, candidate=None, action='merge', rollback=None, format='xml'):

    if all((candidate is None, rollback is None)):
        module.fail_json(msg='one of candidate or rollback must be specified')

    elif all((candidate is not None, rollback is not None)):
        module.fail_json(msg='candidate and rollback are mutually exclusive')

    if format not in FORMATS:
        module.fail_json(msg='invalid format specified')

    if format == 'json' and action not in JSON_ACTIONS:
        module.fail_json(msg='invalid action for format json')
    elif format in ('text', 'xml') and action not in ACTIONS:
        module.fail_json(msg='invalid action format %s' % format)
    if action == 'set' and not format == 'text':
        module.fail_json(msg='format must be text when action is set')

    if rollback is not None:
        _validate_rollback_id(module, rollback)
        xattrs = {'rollback': str(rollback)}
    else:
        xattrs = {'action': action, 'format': format}

    obj = Element('load-configuration', xattrs)

    if candidate is not None:
        lookup = {'xml': 'configuration', 'text': 'configuration-text',
                  'set': 'configuration-set', 'json': 'configuration-json'}

        if action == 'set':
            cfg = SubElement(obj, 'configuration-set')
        else:
            cfg = SubElement(obj, lookup[format])

        if isinstance(candidate, string_types):
            if format == 'xml':
                cfg.append(fromstring(candidate))
            else:
                cfg.text = to_text(candidate, encoding='latin1')
        else:
            cfg.append(candidate)
    return send_request(module, obj)
예제 #42
0
def write_landuse(lod,
                  name,
                  geometry_list,
                  function=None,
                  generic_attrib_dict=None):
    cityObjectMember = Element('cityObjectMember')

    luse = SubElement(cityObjectMember,
                      "{" + XMLNamespaces.luse + "}" + 'LandUse')
    luse.attrib["{" + XMLNamespaces.gml + "}" + 'id'] = name

    gml_name = SubElement(luse, "{" + XMLNamespaces.gml + "}" + 'name')
    gml_name.text = name

    #=======================================================================================================
    #attribs
    #=======================================================================================================
    if function != None:
        luse_function = SubElement(luse,
                                   "{" + XMLNamespaces.luse + "}" + 'function')
        luse_function.text = function

    if generic_attrib_dict != None:
        write_gen_Attribute(luse, generic_attrib_dict)

    #=======================================================================================================
    #geometries
    #=======================================================================================================
    if lod == "lod1":
        luse_lod1MultiSurface = SubElement(
            luse, "{" + XMLNamespaces.luse + "}" + 'lod1MultiSurface')

        gml_MultiSurface = SubElement(
            luse_lod1MultiSurface,
            "{" + XMLNamespaces.gml + "}" + 'MultiSurface')
        gml_MultiSurface.attrib["{" + XMLNamespaces.gml + "}" +
                                'id'] = 'UUID_' + str(uuid.uuid1())

        for geometry in geometry_list:
            gml_MultiSurface.append(geometry.construct())

    return cityObjectMember
예제 #43
0
def getrecord(**kwargs):
    """Create OAI-PMH response for verb Identify."""
    record_dumper = serializer(kwargs['metadataPrefix'])
    pid_value = kwargs['identifier'].replace('oai:inspirehep.net:', '')
    pid = PersistentIdentifier.get('lit', pid_value)
    record = Record.get_record(pid.object_uuid)

    e_tree, e_getrecord = verb(**kwargs)
    e_record = SubElement(e_getrecord, etree.QName(NS_OAIPMH, 'record'))

    header(
        e_record,
        identifier=pid.pid_value,
        datestamp=record.updated,
        sets=record.get('_oai', {}).get('sets', []),
    )
    e_metadata = SubElement(e_record, etree.QName(NS_OAIPMH, 'metadata'))
    e_metadata.append(record_dumper(pid, {'_source': record}))

    return e_tree
예제 #44
0
    def filter_CoT(self, event):
        try:
            from lxml.etree import SubElement
            outputEvent = etree.fromstring(event)
            tempDetail = outputEvent.find('detail')
            outputEvent.remove(tempDetail)
            detail = etree.fromstring(event).find('detail')
            try:
                marti = detail.find('marti')
                outputDetail = SubElement(outputEvent, 'detail')
                outputDetail.append(marti)
                print('dest client found')
                self.object.martiPresent = True
            except:
                SubElement(outputEvent, 'detail')
                print('no dest client found')

            return outputEvent
        except Exception as e:
            print('exception filtering CoT ' + str(e))
예제 #45
0
def create_inputs(tool, model, **kwargs):
    inputs_node = SubElement(tool, "inputs")

    # some suites (such as OpenMS) need some advanced options when handling inputs
    expand_advanced_node = add_child_node(tool, "expand", OrderedDict([("macro", ADVANCED_OPTIONS_MACRO_NAME)]))
    parameter_hardcoder = kwargs["parameter_hardcoder"]

    # treat all non output-file parameters as inputs
    for param in utils.extract_and_flatten_parameters(model):
        # no need to show hardcoded parameters
        hardcoded_value = parameter_hardcoder.get_hardcoded_value(param.name, model.name)
        if param.name in kwargs["blacklisted_parameters"] or hardcoded_value:
            # let's not use an extra level of indentation and use NOP
            continue
        if param.type is not _OutFile:
            if param.advanced:
                if expand_advanced_node is not None:
                    parent_node = expand_advanced_node
                else:
                    # something went wrong... we are handling an advanced parameter and the
                    # advanced input macro was not set... inform the user about it
                    logger.info("The parameter %s has been set as advanced, but advanced_input_macro has "
                                "not been set." % param.name, 1)
                    # there is not much we can do, other than use the inputs_node as a parent node!
                    parent_node = inputs_node
            else:
                parent_node = inputs_node

            # for lists we need a repeat tag
            if param.is_list and param.type is not _InFile:
                rep_node = add_child_node(parent_node, "repeat")
                create_repeat_attribute_list(rep_node, param)
                parent_node = rep_node

            param_node = add_child_node(parent_node, "param")
            create_param_attribute_list(param_node, param, kwargs["supported_file_formats"])

    # advanced parameter selection should be at the end
    # and only available if an advanced parameter exists
    if expand_advanced_node is not None and len(expand_advanced_node) > 0:
        inputs_node.append(expand_advanced_node)
예제 #46
0
    def marshal_multipart(self, wrapper, message):
        if not isinstance(message, dict):
            raise TypeError(
                "Input must be dict when marshalling multipart messages (got %r)"
                % message)

        for name, type in self.parts:
            if name not in message:
                raise ValueError(
                    "While marshalling multipart message: Missing part %r" %
                    name)
            subel = SubElement(wrapper, "{%s}%s" % (self.ns, name))
            marshalled = type.marshal(message[name])
            if hasattr(marshalled, "tag"):
                for child in marshalled.getchildren():
                    subel.append(child)
                subel.text = marshalled.text
                marshalled = None
            else:
                subel.text = marshalled
        return wrapper
예제 #47
0
def listrecords(**kwargs):
    """Create OAI-PMH response for verb ListRecords."""
    record_dumper = serializer(kwargs['metadataPrefix'])

    e_tree, e_listrecords = verb(**kwargs)
    result = get_records(**kwargs)

    for record in result.items:
        pid = oaiid_fetcher(record['id'], record['json']['_source'])
        e_record = SubElement(e_listrecords, etree.QName(NS_OAIPMH, 'record'))
        header(
            e_record,
            identifier=pid.pid_value,
            datestamp=record['updated'],
            sets=record['json']['_source'].get('_oai', {}).get('sets', []),
        )
        e_metadata = SubElement(e_record, etree.QName(NS_OAIPMH, 'metadata'))
        e_metadata.append(record_dumper(pid, record['json']))

    resumption_token(e_listrecords, result, **kwargs)
    return e_tree
예제 #48
0
    def _to_xsd_type(self, type_prefix):
        xsd_uri = self.nsmap['xs']

        # Create an xs:simpleType element

        e = Element(QName(xsd_uri, 'simpleType'))
        e1 = SubElement(e,
                        QName(xsd_uri, 'restriction'),
                        attrib={'base': 'xs:string'})

        # Put restrictions on length

        if self.field.min_length:
            e1.append(
                Element(QName(xsd_uri, 'minLength'),
                        attrib={
                            'value': str(self.field.min_length),
                        }))
        if self.field.max_length:
            e1.append(
                Element(QName(xsd_uri, 'maxLength'),
                        attrib={
                            'value': str(self.field.max_length),
                        }))

        # Put restrictions with a pattern (if detected)

        e1p = self._build_xsd_restriction_with_pattern()
        if e1p is not None:
            e1.append(e1p)

        return (e, {})
예제 #49
0
    def build_entity_descriptor(self) -> str:
        """Build full EntityDescriptor"""
        entity_descriptor = Element(f"{{{NS_SAML_METADATA}}}EntityDescriptor",
                                    nsmap=NS_MAP)
        entity_descriptor.attrib["ID"] = self.xml_id
        entity_descriptor.attrib["entityID"] = self.provider.issuer

        if self.provider.signing_kp:
            self._prepare_signature(entity_descriptor)

        idp_sso_descriptor = SubElement(
            entity_descriptor, f"{{{NS_SAML_METADATA}}}IDPSSODescriptor")
        idp_sso_descriptor.attrib[
            "protocolSupportEnumeration"] = "urn:oasis:names:tc:SAML:2.0:protocol"

        signing_descriptor = self.get_signing_key_descriptor()
        if signing_descriptor is not None:
            idp_sso_descriptor.append(signing_descriptor)

        for name_id_format in self.get_name_id_formats():
            idp_sso_descriptor.append(name_id_format)

        for binding in self.get_bindings():
            idp_sso_descriptor.append(binding)

        if self.provider.signing_kp:
            self._sign(entity_descriptor)

        return tostring(entity_descriptor, pretty_print=True).decode()
예제 #50
0
    def __add_config(self, level1, level2, level3=None, content=None):
        if not content:
            raise XMvnConfigException("Provide content as keyword argument")

        confpath = self.__get_current_config()
        root = self.__init_xml()

        level1 = SubElement(root, level1)
        level2 = SubElement(level1, level2)
        cont_level = level2
        if level3:
            cont_level = SubElement(level2, level3)

        if isinstance(content, six.string_types):
            cont_level.text = content
        elif isinstance(content, list):
            for elem in content:
                cont_level.append(elem)
        else:
            cont_level.append(content)

        self.__write_xml(confpath, root)
예제 #51
0
파일: xml.py 프로젝트: LipotesOps/lipotes-b
    def serialize_workflow(self, workflow, **kwargs):
        assert isinstance(workflow, Workflow)
        elem = etree.Element('workflow')
        wf_spec_elem = self.serialize_workflow_spec(workflow.spec)
        wf_spec_elem.tag = 'spec'
        elem.append(wf_spec_elem)

        data_elem = SubElement(elem, 'data')
        self.serialize_value_map(data_elem, workflow.data)

        if workflow.last_task is not None:
            SubElement(elem, 'last-task').text = str(workflow.last_task.id)

        # outer_workflow
        # SubElement(elem, 'outer-workflow').text = workflow.outer_workflow.id

        if workflow.success:
            SubElement(elem, 'success')
        task_tree_elem = SubElement(elem, 'task-tree')
        task_tree_elem.append(self.serialize_task(workflow.task_tree))

        return elem
예제 #52
0
    def toXML(self):
        e1 = XMLElement("state")

        e2 = XMLSubelement(e1, "workflow")
        e2.text = self.workflowReference

        e3 = XMLSubelement(e1, "workflow_status")
        e3.text = self.workflowStatusReference

        e4 = XMLSubelement(e1, "developers")

        for developer in self.developers:
            e4.append(developer.toXML())

        e5 = XMLSubelement(e1, "assignee")
        e5.text = self.assignee

        e6 = XMLSubelement(e1, "priority")
        e6.text = self.priority

        e7 = XMLSubelement(e1, "labels")

        for label in self.labels:
            e8 = XMLSubelement(e7, "label")
            e8.text = label

        e9 = XMLSubelement(e1, "watchers")

        for watcher in self.watchers:
            e10 = XMLSubelement(e9, "watcher")
            e10.text = watcher

        e11 = XMLSubelement(e1, "versions")

        for version in self.versions:
            e11.append(version.toXML())

        return e1
예제 #53
0
    def envelope_message(self, message, operation):
        # XXX: `encoded`/`literal` is blissfully ignored
        envelope = Element(NS.tag("soapenv", "Envelope"), nsmap=dict(NS))
        header = SubElement(envelope, NS.tag("soapenv", "Header"))
        body = SubElement(envelope, NS.tag("soapenv", "Body"))

        opbind = self.operation_bindings[operation]
        for el in operation.input.message.marshal(message,
                                                  style=opbind["style"]):
            body.append(el)

        cleanup_namespaces(envelope)
        xml = tostring(envelope,
                       pretty_print=True,
                       encoding="UTF-8",
                       xml_declaration=True)
        req = Request(
            None, {
                "Content-type": "text/xml; charset=utf-8",
                "SOAPAction": '"%s"' % opbind.get("soapAction")
            }, xml)

        return req
예제 #54
0
    def _to_xsd_type(self, type_prefix):
        xsd_uri = self.nsmap['xs']

        # Create an xs:complexType element

        e = Element(QName(xsd_uri, 'complexType'))
        e1 = SubElement(e, QName(xsd_uri, 'sequence'))

        yf = self.field.value_type

        ys = serializer_for_field(yf)
        ys.target_namespace = self.target_namespace

        ys_prefix = '_'.join((type_prefix, self.typename, 'Y'))
        ye, ye_tdefs = ys.to_xsd(type_prefix=ys_prefix)

        ye.attrib.update({
            'maxOccurs': str(self.field.max_length or 'unbounded'),
            'minOccurs': str(self.field.min_length or 0),
        })
        e1.append(ye)

        return (e, ye_tdefs)
예제 #55
0
def copyNode(node, children=False, parent=False):
    """ Copy an XML Node

    :param node: Etree Node
    :param children: Copy children nodes is set to True
    :param parent: Append copied node to parent if given
    :return: New Element
    """
    if parent is not False:
        element = SubElement(parent,
                             node.tag,
                             attrib=node.attrib,
                             nsmap={None: "http://www.tei-c.org/ns/1.0"})
    else:
        element = Element(node.tag,
                          attrib=node.attrib,
                          nsmap={None: "http://www.tei-c.org/ns/1.0"})
    if children:
        if node.text:
            element._setText(node.text)
        for child in xmliter(node):
            element.append(copy(child))
    return element
예제 #56
0
	def add(self, parent, xml):
		ns = self.ns
		if parent not in self.elements:
			raise AttributeError("Element '%s' not supported." % parent)
		
		# Get new node, fix namespace prefix
		old_node = None
		new_node = etree.fromstring(xml)
		if not new_node.tag.startswith(ns):
			new_node.tag = ns + new_node.tag
		
		# If parent node doesn't exist, create it
		parent_node = self.root.find(ns + parent)
		if parent_node is None: 
			parent_node = SubElement(self.root, ns + parent)
		
		# Try to find an equal node for second level node
		for i in parent_node.getiterator(new_node.tag):
			if self.node_equal(new_node, i):
				old_node = i
				break
	
		if old_node is None:
			parent_node.append(new_node)
			return
		
		# Try to find an equal node for third level node
		rev_node = new_node.find("revision")	
		for i in old_node.getiterator(rev_node.tag):
			a = i.attrib.get("value")
			b = rev_node.attrib.get("value")
			if not None in (a, b) and a == b:
				i = rev_node # Overwrite old data
				return
		
		# Else append as no override required
		old_node.append(new_node.find("revision"))
예제 #57
0
	def publish(self, server, node, title, content, return_function=None, stanza_id=None):

		entry=Element("entry")
		title1=SubElement(entry,"title")
		title1.text = title
		content1 = SubElement(entry,"content")
		content1.text = content
		print(etree.tostring(entry))
		
		stanza = Element('iq', attrib={'type':'set', 'from':self.jid.jid, 'to':"pubsub."+str(server)})
		pubsub = SubElement(stanza, 'pubsub', attrib={'xmlns':'http://jabber.org/protocol/pubsub'})
		publish = SubElement(pubsub, 'publish', attrib={'node':str(node)})
		item = SubElement(publish, 'item')		
		item.append(entry)


		def handler(stanza, callback):
			# <iq type='result'
			#    from='pubsub.shakespeare.lit'
			#    to='[email protected]/blogbot'
			#    id='publish1'>
			#  <pubsub xmlns='http://jabber.org/protocol/pubsub'>
			#    <publish node='princely_musings'>
			#      <item id='ae890ac52d0df67ed7cfdf51b644e901'/>
			#    </publish>
			#  </pubsub>

			# print (etree.tostring(stanza))
			if callback is not None:
				reply=[]
				if stanza.get("type") == "result":
					reply.append(stanza)
					callback(reply)
				else:
					print("error in publishing")

		self.send(stanza, handler, return_function)
예제 #58
0
def output_fragment(fragment_path, fragment, mappings, add_versions):
    """Writes fragment into fragment_path in specialised format
    compatible with jpp"""
    root = None
    try:
        et = ElementTree()
        parser = XMLParser(remove_blank_text=True)
        root = et.parse(fragment_path, parser=parser)
    except IOError:
        root = Element("dependencyMap")

    if not add_versions:
        versions = set()
    else:
        versions = set(add_versions.split(','))

    if add_versions or add_versions == "":
        # skip RPM provides in compat packages
        SubElement(root, "skipProvides")

    versions.add(fragment.upstream_artifact.version)
    versions = list(versions)
    for ver in sorted(versions):
        for fragment in mappings:
            dep = SubElement(root, "dependency")
            if add_versions or add_versions == "":
                fragment.local_artifact.version = ver
            else:
                fragment.local_artifact.version = ""
            mvn_xml = fragment.upstream_artifact.get_xml_element(root="maven")
            local_xml = fragment.local_artifact.get_xml_element(root="jpp")

            dep.append(mvn_xml)
            dep.append(local_xml)
    xmlstr = prettify_element(root)
    with codecs.open(fragment_path, 'w', "utf-8") as fout:
        fout.write(xmlstr)
def backup_data(data, path='out.xml'):
    """ Makes an XML backup data from existing data in ArcGIS
    """
    root = Element("casestudies")

    for cs in data:
        e_cs = SubElement(root, 'casestudy')
        e_attrs = SubElement(e_cs, 'attributes')

        for k, v in cs['attributes'].items():
            el = Element(k)
            el.text = unicode(v)
            e_attrs.append(el)

        e_geo = SubElement(e_cs, 'geometry')

        for k, v in cs.get('geometry', {}).items():
            el = Element(k)
            el.text = unicode(v)
            e_geo.append(el)

    with open(path, 'w') as f:
        out = tostring(root, pretty_print=True)
        f.write(out)
예제 #60
0
    def _to_xsd_type(self, type_prefix):
        xsd_uri = self.nsmap['xs']
        f = self.field

        obj = None
        if f.context and isinstance(f.context.value, Object):
            obj = f.context.value
        else:
            obj = Object.Factory(f.schema)()

        # Create an xs:complexType element

        e = Element(QName(xsd_uri, 'complexType'))
        e1 = SubElement(e, QName(xsd_uri, 'sequence'))

        # Append the XSD definition for obj-typed objects

        ys = serializer_for_object(obj)
        ys.target_namespace = self.target_namespace

        ye, ye_tdefs = ys.to_xsd(type_prefix=type_prefix)
        e1.append(ye)

        return (e, ye_tdefs)