How to use the pycsw.core.etree.etree.XMLParser function in pycsw

To help you get started, we’ve selected a few pycsw examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github planetfederal / registry / test_registry.py View on Github external
def get_number_records(request):
    parsed = etree.fromstring(request.content,
                              etree.XMLParser(resolve_entities=False))
    search_param = '{http://www.opengis.net/cat/csw/2.0.2}SearchResults'
    search_results = parsed.findall(search_param)[0]

    return int(search_results.attrib['numberOfRecordsMatched'])
github cga-harvard / Hypermap-Registry / hypermap / search / pycsw_plugin.py View on Github external
def get_service(raw_xml):
    """
    Set a service object based on the XML metadata
       http://ngamaps.geointapps.org/arcgis
       /services/RIO/Rio_Foundation_Transportation/MapServer/WMSServer
       
    :param instance:
    :return: Layer
    """
    from pycsw.core.etree import etree

    parsed = etree.fromstring(raw_xml, etree.XMLParser(resolve_entities=False))

    # OGC:WMS
    source_tag = parsed.find("{http://purl.org/dc/elements/1.1/}source")
    # 
    #    http://ngamaps.geointapps.org/arcgis/services/RIO/Rio_Foundation_Transportation/MapServer/WMSServer
    # 
    format_tag = parsed.find("{http://purl.org/dc/elements/1.1/}format")

    service_url = None
    service_type = None

    if hasattr(source_tag, 'text'):
        service_url = source_tag.text

    if hasattr(format_tag, 'text'):
        service_type = format_tag.text
github planetfederal / registry / registry.py View on Github external
def include_registry_tags(record_dict, xml_file,
                          query_string='{http://gis.harvard.edu/HHypermap/registry/0.1}property'):

    parsed = etree.fromstring(xml_file, etree.XMLParser(resolve_entities=False))
    registry_tags = parsed.findall(query_string)

    registry_dict = {}
    for tag in registry_tags:
        registry_dict[tag.attrib['name']] = tag.attrib['value'].encode('ascii', 'ignore').decode('utf-8')

    record_dict['registry'] = registry_dict
    return record_dict
github geopython / pycsw / pycsw / ogc / csw / csw3.py View on Github external
self.parent.kvp['constraint']['where'], self.parent.kvp['constraint']['values'] = fes1.parse(cql,
                        self.parent.repository.queryables['_all'], self.parent.repository.dbtype,
                        self.parent.context.namespaces, self.parent.orm, self.parent.language['text'], self.parent.repository.fts)
                        self.parent.kvp['constraint']['_dict'] = xml2dict(etree.tostring(cql), self.parent.context.namespaces)
                    except Exception as err:
                        LOGGER.exception('Invalid CQL query %s', tmp)
                        return self.exceptionreport('InvalidParameterValue',
                        'constraint', 'Invalid Filter syntax')
                elif self.parent.kvp['constraintlanguage'] == 'FILTER':
                    # validate filter XML
                    try:
                        schema = os.path.join(self.parent.config.get('server', 'home'),
                        'core', 'schemas', 'ogc', 'filter', '1.1.0', 'filter.xsd')
                        LOGGER.info('Validating Filter %s.', self.parent.kvp['constraint'])
                        schema = etree.XMLSchema(file=schema)
                        parser = etree.XMLParser(schema=schema, resolve_entities=False)
                        doc = etree.fromstring(self.parent.kvp['constraint'], parser)
                        LOGGER.debug('Filter is valid XML.')
                        self.parent.kvp['constraint'] = {}
                        self.parent.kvp['constraint']['type'] = 'filter'
                        self.parent.kvp['constraint']['where'], self.parent.kvp['constraint']['values'] = \
                        fes2.parse(doc,
                        self.parent.repository.queryables['_all'],
                        self.parent.repository.dbtype,
                        self.parent.context.namespaces, self.parent.orm, self.parent.language['text'], self.parent.repository.fts)
                        self.parent.kvp['constraint']['_dict'] = xml2dict(etree.tostring(doc), self.parent.context.namespaces)
                    except Exception as err:
                        errortext = \
                        'Exception: document not valid.\nError: %s' % str(err)

                        LOGGER.exception(errortext)
                        return self.exceptionreport('InvalidParameterValue',
github geopython / pycsw / pycsw / ogc / csw / csw3.py View on Github external
schema = os.path.join(self.parent.config.get('server', 'home'),
        'core', 'schemas', 'ogc', 'cat', 'csw', '3.0', xsd_filename)

        try:
            # it is virtually impossible to validate a csw:Transaction
            # csw:Insert|csw:Update (with single child) XML document.
            # Only validate non csw:Transaction XML

            if doc.find('.//%s' % util.nspath_eval('csw30:Insert',
            self.parent.context.namespaces)) is None and \
            len(doc.xpath('//csw30:Update/child::*',
            namespaces=self.parent.context.namespaces)) == 0:

                LOGGER.info('Validating %s', postdata)
                schema = etree.XMLSchema(file=schema)
                parser = etree.XMLParser(schema=schema, resolve_entities=False)
                if hasattr(self.parent, 'soap') and self.parent.soap:
                # validate the body of the SOAP request
                    doc = etree.fromstring(etree.tostring(doc), parser)
                else:  # validate the request normally
                    doc = etree.fromstring(postdata, parser)
                LOGGER.debug('Request is valid XML')
            else:  # parse Transaction without validation
                doc = etree.fromstring(postdata, self.parent.context.parser)
        except Exception as err:
            errortext = \
            'Exception: the document is not valid.\nError: %s' % str(err)
            LOGGER.exception(errortext)
            return errortext

        request['request'] = etree.QName(doc).localname
        LOGGER.debug('Request operation %s specified.', request['request'])