Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def write_record(result, esn, context, url=None):
''' Return csw:SearchResults child as lxml.etree.Element '''
typename = util.getqattr(result, context.md_core_model['mappings']['pycsw:Typename'])
if esn == 'full' and typename == 'atom:entry':
# dump record as is and exit
return etree.fromstring(util.getqattr(result, context.md_core_model['mappings']['pycsw:XML']), context.parser)
node = etree.Element(util.nspath_eval('atom:entry', NAMESPACES), nsmap=NAMESPACES)
node.attrib[util.nspath_eval('xsi:schemaLocation', context.namespaces)] = \
'%s http://www.kbcafe.com/rss/atom.xsd.xml' % NAMESPACES['atom']
# author
val = util.getqattr(result, context.md_core_model['mappings']['pycsw:Creator'])
if val:
author = etree.SubElement(node, util.nspath_eval('atom:author', NAMESPACES))
etree.SubElement(author, util.nspath_eval('atom:name', NAMESPACES)).text = val
# category
val = util.getqattr(result, context.md_core_model['mappings']['pycsw:Keywords'])
if val:
for kw in val.split(','):
def write_record(result, esn, context, url=None):
''' Return csw:SearchResults child as lxml.etree.Element '''
typename = util.getqattr(result, context.md_core_model['mappings']['pycsw:Typename'])
if esn == 'full' and typename == 'dif:DIF':
# dump record as is and exit
return etree.fromstring(util.getqattr(result, context.md_core_model['mappings']['pycsw:XML']), context.parser)
node = etree.Element(util.nspath_eval('dif:DIF', NAMESPACES))
node.attrib[util.nspath_eval('xsi:schemaLocation', context.namespaces)] = \
'%s http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/dif.xsd' % NAMESPACE
# identifier
etree.SubElement(node, util.nspath_eval('dif:Entry_ID', NAMESPACES)).text = util.getqattr(result, context.md_core_model['mappings']['pycsw:Identifier'])
# title
val = util.getqattr(result, context.md_core_model['mappings']['pycsw:Title'])
if not val:
val = ''
etree.SubElement(node, util.nspath_eval('dif:Entry_Title', NAMESPACES)).text = val
# citation
citation = etree.SubElement(node, util.nspath_eval('dif:Data_Set_Citation', NAMESPACES))
LOGGER.info('Harvesting %d CSW records', matches)
# loop over all catalogue records incrementally
for r in range(1, matches+1, pagesize):
try:
md.getrecords2(typenames=csw_typenames, startposition=r,
maxrecords=pagesize, outputschema=csw_outputschema, esn='full')
except Exception as err: # this is a CSW, but server rejects query
raise RuntimeError(md.response)
for k, v in md.records.items():
# try to parse metadata
try:
LOGGER.info('Parsing metadata record: %s', v.xml)
if csw_typenames == 'gmd:MD_Metadata':
recobjs.append(_parse_iso(context, repos,
etree.fromstring(v.xml, context.parser)))
else:
recobjs.append(_parse_dc(context, repos,
etree.fromstring(v.xml, context.parser)))
except Exception as err: # parsing failed for some reason
LOGGER.exception('Metadata parsing failed')
return recobjs
def write_record(result, esn, context, url=None):
''' Return csw:SearchResults child as lxml.etree.Element '''
typename = util.getqattr(result, context.md_core_model['mappings']['pycsw:Typename'])
if typename == 'gm03:TRANSFER':
# dump record as is and exit
# TODO: provide brief and summary elementsetname's
return etree.fromstring(util.getqattr(result, context.md_core_model['mappings']['pycsw:XML']), context.parser)
node = etree.Element(util.nspath_eval('gm03:TRANSFER', NAMESPACES), nsmap=NAMESPACES)
header = etree.SubElement(node, util.nspath_eval('gm03:HEADERSECTION', NAMESPACES))
header.attrib['version'] = '2.3'
header.attrib['sender'] = 'pycsw'
etree.SubElement(header, util.nspath_eval('gm03:MODELS', NAMESPACES))
data = etree.SubElement(node, util.nspath_eval('gm03:DATASECTION', NAMESPACES))
core = etree.SubElement(data, util.nspath_eval('gm03:GM03_2_1Core.Core', NAMESPACES))
core_meta = etree.SubElement(core, util.nspath_eval('gm03:GM03_2_1Core.Core.MD_Metadata', NAMESPACES))
val = util.getqattr(result, context.md_core_model['mappings']['pycsw:Identifier'])
etree.SubElement(core_meta, util.nspath_eval('gm03:fileIdentifier', NAMESPACES)).text = val
def write_record(self, result, esn, outputschema, queryables, caps=None):
''' Return csw:SearchResults child as lxml.etree.Element '''
typename = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:Typename'])
is_iso_anyway = False
xml_blob = util.getqattr(result, self.context.md_core_model['mappings']['pycsw:XML'])
if caps is None and xml_blob is not None and xml_blob.startswith(b'
self.parent.profiles['loaded'][self.parent.kvp['outputschema']].\
write_record(res, self.parent.kvp['elementsetname'],
self.parent.kvp['outputschema'],
self.parent.repository.queryables['_all']))
except Exception as err:
self.parent.response = self.exceptionreport(
'NoApplicableCode', 'service',
'Record serialization failed: %s' % str(err))
return self.parent.response
if len(dsresults) > 0: # return DistributedSearch results
for resultset in dsresults:
if isinstance(resultset, etree._Comment):
searchresults.append(resultset)
for rec in resultset:
searchresults.append(etree.fromstring(resultset[rec].xml, self.parent.context.parser))
if 'responsehandler' in self.parent.kvp: # process the handler
self.parent._process_responsehandler(etree.tostring(node,
pretty_print=self.parent.pretty_print))
else:
return node
else:
value = util.getqattr(recobj, queryables[elemname]['dbcol'])
if value:
etree.SubElement(record,
util.nspath_eval(elemname,
self.parent.context.namespaces)).text = value
elif 'elementsetname' in self.parent.kvp:
if (self.parent.kvp['elementsetname'] == 'full' and
util.getqattr(recobj, self.parent.context.md_core_model['mappings']\
['pycsw:Typename']) == 'csw:Record' and
util.getqattr(recobj, self.parent.context.md_core_model['mappings']\
['pycsw:Schema']) == 'http://www.opengis.net/cat/csw/2.0.2' and
util.getqattr(recobj, self.parent.context.md_core_model['mappings']\
['pycsw:Type']) != 'service'):
# dump record as is and exit
return etree.fromstring(util.getqattr(recobj,
self.parent.context.md_core_model['mappings']['pycsw:XML']), self.parent.context.parser)
etree.SubElement(record,
util.nspath_eval('dc:identifier', self.parent.context.namespaces)).text = \
util.getqattr(recobj,
self.parent.context.md_core_model['mappings']['pycsw:Identifier'])
for i in ['dc:title', 'dc:type']:
val = util.getqattr(recobj, queryables[i]['dbcol'])
if not val:
val = ''
etree.SubElement(record, util.nspath_eval(i,
self.parent.context.namespaces)).text = val
if self.parent.kvp['elementsetname'] in ['summary', 'full']:
# add summary elements