<s> import os <EOL> import sys <EOL> import cgi <EOL> from time import time <EOL> from six . moves . urllib . parse import quote , unquote <EOL> from six import StringIO <EOL> from six . moves . configparser import SafeConfigParser <EOL> from pycsw . core . etree import etree <EOL> from pycsw import oaipmh , opensearch , sru <EOL> from pycsw . plugins . profiles import profile as pprofile <EOL> import pycsw . plugins . outputschemas <EOL> from pycsw . core import config , log , metadata , util <EOL> from pycsw . ogc . fes import fes2 <EOL> import logging <EOL> LOGGER = logging . getLogger ( __name__ ) <EOL> class Csw3 ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , server_csw ) : <EOL> '''<STR_LIT>''' <EOL> self . parent = server_csw <EOL> self . version = '<STR_LIT>' <EOL> def getcapabilities ( self ) : <EOL> '''<STR_LIT>''' <EOL> serviceidentification = True <EOL> serviceprovider = True <EOL> operationsmetadata = True <EOL> filtercaps = False <EOL> languages = False <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> LOGGER . debug ( self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> bfound = False <EOL> for fmt in self . parent . kvp [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> if fmt in self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> self . parent . mimetype = fmt <EOL> bfound = True <EOL> break <EOL> if not bfound : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % <EOL> self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in self . parent . kvp and self . parent . kvp [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> serviceidentification = False <EOL> serviceprovider = False <EOL> operationsmetadata = False <EOL> for section in self . parent . kvp [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> if section == '<STR_LIT>' : <EOL> serviceidentification = True <EOL> if section == '<STR_LIT>' : <EOL> serviceprovider = True <EOL> if section == '<STR_LIT>' : <EOL> operationsmetadata = True <EOL> if section == '<STR_LIT>' : <EOL> serviceidentification = True <EOL> serviceprovider = True <EOL> operationsmetadata = True <EOL> filtercaps = True <EOL> languages = True <EOL> else : <EOL> filtercaps = True <EOL> languages = True <EOL> if self . parent . profiles is not None : <EOL> for prof in self . parent . profiles [ '<STR_LIT>' ] . keys ( ) : <EOL> result = self . parent . profiles [ '<STR_LIT>' ] [ prof ] . check_parameters ( self . parent . kvp ) <EOL> if result is not None : <EOL> return self . exceptionreport ( result [ '<STR_LIT:code>' ] , <EOL> result [ '<STR_LIT>' ] , result [ '<STR_LIT:text>' ] ) <EOL> try : <EOL> updatesequence = util . get_time_iso2unix ( self . parent . repository . query_insert ( ) ) <EOL> except : <EOL> updatesequence = None <EOL> node = etree . Element ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , <EOL> nsmap = self . parent . context . namespaces , version = '<STR_LIT>' , <EOL> updateSequence = str ( updatesequence ) ) <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> if int ( self . parent . kvp [ '<STR_LIT>' ] ) == updatesequence : <EOL> return node <EOL> elif int ( self . parent . kvp [ '<STR_LIT>' ] ) > updatesequence : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % ( self . parent . kvp [ '<STR_LIT>' ] , <EOL> updatesequence ) ) <EOL> node . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = '<STR_LIT>' % ( self . parent . context . namespaces [ '<STR_LIT>' ] , <EOL> self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> metadata_main = dict ( self . parent . config . items ( '<STR_LIT>' ) ) <EOL> if serviceidentification : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> serviceidentification = etree . SubElement ( node , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> etree . SubElement ( serviceidentification , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( serviceidentification , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> keywords = etree . SubElement ( serviceidentification , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> for k in metadata_main . get ( '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) : <EOL> etree . SubElement ( <EOL> keywords , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = k <EOL> etree . SubElement ( keywords , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> codeSpace = '<STR_LIT>' ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( serviceidentification , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> codeSpace = '<STR_LIT>' ) . text = '<STR_LIT>' <EOL> for stv in self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] [ '<STR_LIT>' ] : <EOL> etree . SubElement ( serviceidentification , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = stv <EOL> if self . parent . profiles is not None : <EOL> for prof in self . parent . profiles [ '<STR_LIT>' ] . keys ( ) : <EOL> prof_name = self . parent . profiles [ '<STR_LIT>' ] [ prof ] . name <EOL> prof_val = self . parent . profiles [ '<STR_LIT>' ] [ prof ] . namespaces [ prof_name ] <EOL> etree . SubElement ( serviceidentification , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = prof_val <EOL> etree . SubElement ( serviceidentification , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( serviceidentification , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if serviceprovider : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> serviceprovider = etree . SubElement ( node , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> etree . SubElement ( serviceprovider , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> providersite = etree . SubElement ( serviceprovider , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> providersite . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = '<STR_LIT>' <EOL> providersite . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> servicecontact = etree . SubElement ( serviceprovider , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> etree . SubElement ( servicecontact , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( servicecontact , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> contactinfo = etree . SubElement ( servicecontact , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> phone = etree . SubElement ( contactinfo , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> etree . SubElement ( phone , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( phone , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> address = etree . SubElement ( contactinfo , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> etree . SubElement ( address , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( address , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( address , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( address , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( address , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( address , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> url = etree . SubElement ( contactinfo , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> url . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = '<STR_LIT>' <EOL> url . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( contactinfo , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( contactinfo , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> etree . SubElement ( servicecontact , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> codeSpace = '<STR_LIT>' ) . text = metadata_main . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if operationsmetadata : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> operationsmetadata = etree . SubElement ( node , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> for operation in self . parent . context . model [ '<STR_LIT>' ] : <EOL> oper = etree . SubElement ( operationsmetadata , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> name = operation ) <EOL> dcp = etree . SubElement ( oper , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> http = etree . SubElement ( dcp , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if self . parent . context . model [ '<STR_LIT>' ] [ operation ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> get = etree . SubElement ( http , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> get . attrib [ util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ] = '<STR_LIT>' <EOL> get . attrib [ util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ] = self . parent . config . get ( '<STR_LIT>' , '<STR_LIT:url>' ) <EOL> if self . parent . context . model [ '<STR_LIT>' ] [ operation ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> post = etree . SubElement ( http , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> post . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = '<STR_LIT>' <EOL> post . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = self . parent . config . get ( '<STR_LIT>' , '<STR_LIT:url>' ) <EOL> for parameter in sorted ( self . parent . context . model [ '<STR_LIT>' ] [ operation ] [ '<STR_LIT>' ] ) : <EOL> param = etree . SubElement ( oper , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , name = parameter ) <EOL> param . append ( self . _write_allowed_values ( self . parent . context . model [ '<STR_LIT>' ] [ operation ] [ '<STR_LIT>' ] [ parameter ] [ '<STR_LIT>' ] ) ) <EOL> if operation == '<STR_LIT>' : <EOL> for qbl in sorted ( self . parent . repository . queryables . keys ( ) ) : <EOL> if qbl not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> param = etree . SubElement ( oper , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , name = qbl ) <EOL> param . append ( self . _write_allowed_values ( self . parent . repository . queryables [ qbl ] ) ) <EOL> if self . parent . profiles is not None : <EOL> for con in sorted ( self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] . keys ( ) ) : <EOL> param = etree . SubElement ( oper , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , name = con ) <EOL> param . append ( self . _write_allowed_values ( self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ con ] [ '<STR_LIT>' ] ) ) <EOL> extra_constraints = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' % self . parent . config . get ( '<STR_LIT>' , '<STR_LIT:url>' ) ] , <EOL> '<STR_LIT>' : self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> } <EOL> for key in sorted ( extra_constraints . keys ( ) ) : <EOL> param = etree . SubElement ( oper , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , name = key ) <EOL> param . append ( self . _write_allowed_values ( extra_constraints [ key ] ) ) <EOL> if '<STR_LIT>' in self . parent . context . model [ '<STR_LIT>' ] : <EOL> param = etree . SubElement ( oper , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , name = '<STR_LIT>' ) <EOL> param . append ( self . _write_allowed_values ( self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ) <EOL> for parameter in sorted ( self . parent . context . model [ '<STR_LIT>' ] . keys ( ) ) : <EOL> param = etree . SubElement ( operationsmetadata , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> name = parameter ) <EOL> param . append ( self . _write_allowed_values ( self . parent . context . model [ '<STR_LIT>' ] [ parameter ] [ '<STR_LIT>' ] ) ) <EOL> for qbl in sorted ( self . parent . repository . queryables . keys ( ) ) : <EOL> if qbl == '<STR_LIT>' : <EOL> param = etree . SubElement ( operationsmetadata , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , name = '<STR_LIT>' ) <EOL> param . append ( self . _write_allowed_values ( self . parent . repository . queryables [ qbl ] ) ) <EOL> for constraint in sorted ( self . parent . context . model [ '<STR_LIT>' ] . keys ( ) ) : <EOL> param = etree . SubElement ( operationsmetadata , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> name = constraint ) <EOL> param . append ( self . _write_allowed_values ( self . parent . context . model [ '<STR_LIT>' ] [ constraint ] [ '<STR_LIT>' ] ) ) <EOL> if self . parent . profiles is not None : <EOL> for prof in self . parent . profiles [ '<STR_LIT>' ] . keys ( ) : <EOL> ecnode = self . parent . profiles [ '<STR_LIT>' ] [ prof ] . get_extendedcapabilities ( ) <EOL> if ecnode is not None : <EOL> operationsmetadata . append ( ecnode ) <EOL> if languages : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> langs = etree . SubElement ( node , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> etree . SubElement ( langs , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) . text = self . parent . language [ '<STR_LIT>' ] <EOL> if not filtercaps : <EOL> return node <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> fltcaps = etree . SubElement ( node , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> conformance = etree . SubElement ( fltcaps , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> for value in fes2 . MODEL [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> constraint = etree . SubElement ( conformance , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> name = value ) <EOL> etree . SubElement ( constraint , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> etree . SubElement ( constraint , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) . text = '<STR_LIT>' <EOL> idcaps = etree . SubElement ( fltcaps , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> for idcap in fes2 . MODEL [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> etree . SubElement ( idcaps , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , name = idcap ) <EOL> scalarcaps = etree . SubElement ( fltcaps , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> etree . SubElement ( scalarcaps , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> cmpops = etree . SubElement ( scalarcaps , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> for cmpop in sorted ( fes2 . MODEL [ '<STR_LIT>' ] . keys ( ) ) : <EOL> etree . SubElement ( cmpops , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , name = fes2 . MODEL [ '<STR_LIT>' ] [ cmpop ] [ '<STR_LIT>' ] ) <EOL> spatialcaps = etree . SubElement ( fltcaps , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> geomops = etree . SubElement ( spatialcaps , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> for geomtype in fes2 . MODEL [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> etree . SubElement ( geomops , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , name = geomtype ) <EOL> spatialops = etree . SubElement ( spatialcaps , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> for spatial_comparison in fes2 . MODEL [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> etree . SubElement ( spatialops , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> name = spatial_comparison ) <EOL> functions = etree . SubElement ( fltcaps , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> for fnop in sorted ( fes2 . MODEL [ '<STR_LIT>' ] . keys ( ) ) : <EOL> fn = etree . SubElement ( functions , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> name = fnop ) <EOL> etree . SubElement ( fn , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = fes2 . MODEL [ '<STR_LIT>' ] [ fnop ] [ '<STR_LIT>' ] <EOL> return node <EOL> def getdomain ( self ) : <EOL> '''<STR_LIT>''' <EOL> if ( '<STR_LIT>' not in self . parent . kvp and <EOL> '<STR_LIT>' not in self . parent . kvp ) : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> node = etree . Element ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , nsmap = self . parent . context . namespaces ) <EOL> node . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = '<STR_LIT>' % ( self . parent . context . namespaces [ '<STR_LIT>' ] , <EOL> self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> for pname in self . parent . kvp [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> LOGGER . debug ( '<STR_LIT>' % pname ) <EOL> domainvalue = etree . SubElement ( node , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> type = '<STR_LIT>' , resultType = '<STR_LIT>' ) <EOL> etree . SubElement ( domainvalue , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = pname <EOL> try : <EOL> operation , parameter = pname . split ( '<STR_LIT:.>' ) <EOL> except : <EOL> return node <EOL> if ( operation in self . parent . context . model [ '<STR_LIT>' ] and <EOL> parameter in self . parent . context . model [ '<STR_LIT>' ] [ operation ] [ '<STR_LIT>' ] ) : <EOL> listofvalues = etree . SubElement ( domainvalue , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> for val in sorted ( self . parent . context . model [ '<STR_LIT>' ] [ operation ] [ '<STR_LIT>' ] [ parameter ] [ '<STR_LIT>' ] ) : <EOL> etree . SubElement ( listofvalues , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = val <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> for pname in self . parent . kvp [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> LOGGER . debug ( '<STR_LIT>' % pname ) <EOL> if pname . find ( '<STR_LIT:/>' ) == <NUM_LIT:0> : <EOL> pname2 = pname <EOL> else : <EOL> try : <EOL> pname2 = self . parent . repository . queryables [ '<STR_LIT>' ] [ pname ] [ '<STR_LIT>' ] <EOL> except : <EOL> pname2 = pname <EOL> dvtype = None <EOL> if self . parent . profiles is not None : <EOL> for prof in self . parent . profiles [ '<STR_LIT>' ] . keys ( ) : <EOL> for prefix in self . parent . profiles [ '<STR_LIT>' ] [ prof ] . prefixes : <EOL> if pname2 . find ( prefix ) != - <NUM_LIT:1> : <EOL> dvtype = self . parent . profiles [ '<STR_LIT>' ] [ prof ] . typename <EOL> break <EOL> if not dvtype : <EOL> dvtype = '<STR_LIT>' <EOL> domainvalue = etree . SubElement ( node , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> type = dvtype , resultType = '<STR_LIT>' ) <EOL> etree . SubElement ( domainvalue , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = pname <EOL> try : <EOL> LOGGER . debug ( <EOL> '<STR_LIT>' % ( pname2 , dvtype , self . parent . domainquerytype ) ) <EOL> results = self . parent . repository . query_domain ( <EOL> pname2 , dvtype , self . parent . domainquerytype , True ) <EOL> LOGGER . debug ( '<STR_LIT>' % str ( len ( results ) ) ) <EOL> if self . parent . domainquerytype == '<STR_LIT>' : <EOL> rangeofvalues = etree . SubElement ( domainvalue , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> etree . SubElement ( rangeofvalues , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = results [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> etree . SubElement ( rangeofvalues , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = results [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> else : <EOL> listofvalues = etree . SubElement ( domainvalue , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> for result in results : <EOL> LOGGER . debug ( str ( result ) ) <EOL> if ( result is not None and <EOL> result [ <NUM_LIT:0> ] is not None ) : <EOL> etree . SubElement ( listofvalues , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , <EOL> count = str ( result [ <NUM_LIT:1> ] ) ) . text = result [ <NUM_LIT:0> ] <EOL> except Exception as err : <EOL> LOGGER . debug ( '<STR_LIT>' % <EOL> ( pname2 , str ( err ) ) ) <EOL> return node <EOL> def getrecords ( self ) : <EOL> '''<STR_LIT>''' <EOL> timestamp = util . get_today_and_now ( ) <EOL> if ( '<STR_LIT>' not in self . parent . kvp and <EOL> '<STR_LIT>' not in self . parent . kvp ) : <EOL> if self . parent . requesttype == '<STR_LIT:GET>' : <EOL> LOGGER . debug ( self . parent . requesttype ) <EOL> self . parent . kvp [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> if '<STR_LIT>' in self . parent . kvp and '<STR_LIT>' in self . parent . kvp : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> if '<STR_LIT>' not in self . parent . kvp : <EOL> self . parent . kvp [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in self . parent . kvp : <EOL> self . parent . kvp [ '<STR_LIT>' ] = self . parent . context . namespaces [ '<STR_LIT>' ] <EOL> LOGGER . debug ( self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if ( self . parent . kvp [ '<STR_LIT>' ] not in self . parent . context . model [ '<STR_LIT>' ] <EOL> [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % <EOL> self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' not in self . parent . kvp : <EOL> self . parent . kvp [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' in self . parent . environ : <EOL> LOGGER . debug ( '<STR_LIT>' , self . parent . environ [ '<STR_LIT>' ] ) <EOL> formats_match = False <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> LOGGER . debug ( self . parent . kvp [ '<STR_LIT>' ] ) <EOL> for ofmt in self . parent . environ [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> LOGGER . debug ( '<STR_LIT>' , ofmt , self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if ofmt . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] in self . parent . kvp [ '<STR_LIT>' ] : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> formats_match = True <EOL> if not formats_match : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % <EOL> ( self . parent . environ [ '<STR_LIT>' ] , self . parent . kvp [ '<STR_LIT>' ] ) ) <EOL> else : <EOL> for ofmt in self . parent . environ [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> if ofmt in self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> self . parent . kvp [ '<STR_LIT>' ] = ofmt <EOL> break <EOL> if ( self . parent . kvp [ '<STR_LIT>' ] not in self . parent . context . model [ '<STR_LIT>' ] <EOL> [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % <EOL> self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> self . parent . contenttype = self . parent . kvp [ '<STR_LIT>' ] <EOL> if self . parent . kvp [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> self . parent . kvp [ '<STR_LIT>' ] = self . parent . context . namespaces [ '<STR_LIT>' ] <EOL> self . parent . mode = '<STR_LIT>' <EOL> if ( ( '<STR_LIT>' not in self . parent . kvp or <EOL> len ( self . parent . kvp [ '<STR_LIT>' ] ) == <NUM_LIT:0> ) and <EOL> self . parent . kvp [ '<STR_LIT>' ] not in <EOL> self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % <EOL> self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' not in self . parent . kvp : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> if ( '<STR_LIT>' in self . parent . kvp and <EOL> self . parent . requesttype == '<STR_LIT:GET>' ) : <EOL> self . parent . kvp [ '<STR_LIT>' ] = [ '<STR_LIT>' if x == '<STR_LIT>' else x for x in self . parent . kvp [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) ] <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> LOGGER . debug ( self . parent . kvp [ '<STR_LIT>' ] ) <EOL> self . parent . kvp [ '<STR_LIT>' ] = self . resolve_nsmap ( self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> LOGGER . debug ( self . parent . kvp [ '<STR_LIT>' ] ) <EOL> self . parent . kvp [ '<STR_LIT>' ] = self . resolve_nsmap ( self . parent . kvp [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) ) <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> for tname in self . parent . kvp [ '<STR_LIT>' ] : <EOL> if ( tname not in self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % <EOL> tname ) <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> for ename in self . parent . kvp [ '<STR_LIT>' ] : <EOL> if ename not in self . parent . repository . queryables [ '<STR_LIT>' ] : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % <EOL> ename ) <EOL> maxrecords_cfg = - <NUM_LIT:1> <EOL> if self . parent . config . has_option ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> maxrecords_cfg = int ( self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if '<STR_LIT>' in self . parent . kvp and self . parent . kvp [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> self . parent . kvp . pop ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' not in self . parent . kvp : <EOL> if maxrecords_cfg > - <NUM_LIT:1> : <EOL> self . parent . kvp [ '<STR_LIT>' ] = maxrecords_cfg <EOL> else : <EOL> self . parent . kvp [ '<STR_LIT>' ] = <NUM_LIT:10> <EOL> else : <EOL> if self . parent . kvp [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> self . parent . kvp [ '<STR_LIT>' ] = <NUM_LIT:10> <EOL> if maxrecords_cfg > - <NUM_LIT:1> : <EOL> if int ( self . parent . kvp [ '<STR_LIT>' ] ) > maxrecords_cfg : <EOL> self . parent . kvp [ '<STR_LIT>' ] = maxrecords_cfg <EOL> if any ( x in [ '<STR_LIT>' , '<STR_LIT:q>' , '<STR_LIT:time>' ] for x in self . parent . kvp ) : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> self . parent . kvp [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> try : <EOL> tmp_filter = opensearch . kvp2filterxml ( self . parent . kvp , self . parent . context ) <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT>' , str ( err ) ) <EOL> if tmp_filter is not "<STR_LIT>" : <EOL> self . parent . kvp [ '<STR_LIT>' ] = tmp_filter <EOL> LOGGER . debug ( '<STR_LIT>' % self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if self . parent . requesttype == '<STR_LIT:GET>' : <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' not in self . parent . kvp : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> if ( self . parent . kvp [ '<STR_LIT>' ] not in <EOL> self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> % self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if self . parent . kvp [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> tmp = self . parent . kvp [ '<STR_LIT>' ] <EOL> self . parent . kvp [ '<STR_LIT>' ] = { } <EOL> self . parent . kvp [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> self . parent . kvp [ '<STR_LIT>' ] [ '<STR_LIT>' ] = self . parent . _cql_update_queryables_mappings ( tmp , <EOL> self . parent . repository . queryables [ '<STR_LIT>' ] ) <EOL> self . parent . kvp [ '<STR_LIT>' ] [ '<STR_LIT>' ] = { } <EOL> elif self . parent . kvp [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> try : <EOL> schema = os . path . join ( self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> LOGGER . debug ( '<STR_LIT>' % <EOL> self . parent . kvp [ '<STR_LIT>' ] ) <EOL> schema = etree . XMLSchema ( file = schema ) <EOL> parser = etree . XMLParser ( schema = schema , resolve_entities = False ) <EOL> doc = etree . fromstring ( self . parent . kvp [ '<STR_LIT>' ] , parser ) <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> self . parent . kvp [ '<STR_LIT>' ] = { } <EOL> self . parent . kvp [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> self . parent . kvp [ '<STR_LIT>' ] [ '<STR_LIT>' ] , self . parent . kvp [ '<STR_LIT>' ] [ '<STR_LIT>' ] = fes2 . parse ( doc , <EOL> self . parent . repository . queryables [ '<STR_LIT>' ] , <EOL> self . parent . repository . dbtype , <EOL> self . parent . context . namespaces , self . parent . orm , self . parent . language [ '<STR_LIT:text>' ] , self . parent . repository . fts ) <EOL> except Exception as err : <EOL> errortext = '<STR_LIT>' % str ( err ) <EOL> LOGGER . debug ( errortext ) <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % errortext ) <EOL> else : <EOL> self . parent . kvp [ '<STR_LIT>' ] = { } <EOL> if '<STR_LIT>' not in self . parent . kvp : <EOL> self . parent . kvp [ '<STR_LIT>' ] = None <EOL> elif '<STR_LIT>' in self . parent . kvp and self . parent . requesttype == '<STR_LIT:GET>' : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> tmp = self . parent . kvp [ '<STR_LIT>' ] <EOL> self . parent . kvp [ '<STR_LIT>' ] = { } <EOL> try : <EOL> name , order = tmp . rsplit ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> except : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> self . parent . kvp [ '<STR_LIT>' ] [ '<STR_LIT>' ] = self . parent . repository . queryables [ '<STR_LIT>' ] [ name ] [ '<STR_LIT>' ] <EOL> if name . find ( '<STR_LIT>' ) != - <NUM_LIT:1> or name . find ( '<STR_LIT>' ) != - <NUM_LIT:1> : <EOL> self . parent . kvp [ '<STR_LIT>' ] [ '<STR_LIT>' ] = True <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % name ) <EOL> if order not in [ '<STR_LIT:A>' , '<STR_LIT:D>' ] : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> if order == '<STR_LIT:D>' : <EOL> self . parent . kvp [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> self . parent . kvp [ '<STR_LIT>' ] [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in self . parent . kvp : <EOL> self . parent . kvp [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> if '<STR_LIT>' in self . parent . kvp and self . parent . kvp [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> LOGGER . debug ( '<STR_LIT>' % self . parent . kvp [ '<STR_LIT>' ] ) <EOL> results = self . parent . repository . query_ids ( self . parent . kvp [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) ) <EOL> matched = str ( len ( results ) ) <EOL> if len ( results ) == <NUM_LIT:0> : <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' % self . parent . kvp [ '<STR_LIT>' ] ) <EOL> else : <EOL> LOGGER . debug ( '<STR_LIT>' % <EOL> ( self . parent . kvp [ '<STR_LIT>' ] , self . parent . kvp [ '<STR_LIT>' ] , self . parent . kvp [ '<STR_LIT>' ] , <EOL> self . parent . kvp [ '<STR_LIT>' ] , self . parent . kvp [ '<STR_LIT>' ] ) ) <EOL> try : <EOL> matched , results = self . parent . repository . query ( <EOL> constraint = self . parent . kvp [ '<STR_LIT>' ] , <EOL> sortby = self . parent . kvp [ '<STR_LIT>' ] , typenames = self . parent . kvp [ '<STR_LIT>' ] , <EOL> maxrecords = self . parent . kvp [ '<STR_LIT>' ] , <EOL> startposition = int ( self . parent . kvp [ '<STR_LIT>' ] ) - <NUM_LIT:1> ) <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' % err ) <EOL> if int ( matched ) == <NUM_LIT:0> : <EOL> returned = nextrecord = '<STR_LIT:0>' <EOL> else : <EOL> if int ( matched ) < int ( self . parent . kvp [ '<STR_LIT>' ] ) : <EOL> returned = matched <EOL> nextrecord = '<STR_LIT:0>' <EOL> else : <EOL> returned = str ( self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if int ( self . parent . kvp [ '<STR_LIT>' ] ) + int ( self . parent . kvp [ '<STR_LIT>' ] ) >= int ( matched ) : <EOL> nextrecord = '<STR_LIT:0>' <EOL> else : <EOL> nextrecord = str ( int ( self . parent . kvp [ '<STR_LIT>' ] ) + int ( self . parent . kvp [ '<STR_LIT>' ] ) ) <EOL> LOGGER . debug ( '<STR_LIT>' % ( matched , returned , nextrecord ) ) <EOL> node = etree . Element ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , <EOL> nsmap = self . parent . context . namespaces , version = '<STR_LIT>' ) <EOL> node . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = '<STR_LIT>' % ( self . parent . context . namespaces [ '<STR_LIT>' ] , self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if '<STR_LIT>' in self . parent . kvp and self . parent . kvp [ '<STR_LIT>' ] is not None : <EOL> etree . SubElement ( node , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = self . parent . kvp [ '<STR_LIT>' ] <EOL> etree . SubElement ( node , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , timestamp = timestamp ) <EOL> searchresults = etree . SubElement ( node , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> numberOfRecordsMatched = matched , numberOfRecordsReturned = returned , <EOL> nextRecord = nextrecord , recordSchema = self . parent . kvp [ '<STR_LIT>' ] , <EOL> expires = timestamp , status = get_resultset_status ( matched , nextrecord ) ) <EOL> if self . parent . kvp [ '<STR_LIT>' ] is not None : <EOL> searchresults . attrib [ '<STR_LIT>' ] = self . parent . kvp [ '<STR_LIT>' ] <EOL> if results is not None : <EOL> if len ( results ) < int ( self . parent . kvp [ '<STR_LIT>' ] ) : <EOL> max1 = len ( results ) <EOL> else : <EOL> max1 = int ( self . parent . kvp [ '<STR_LIT>' ] ) + ( int ( self . parent . kvp [ '<STR_LIT>' ] ) - <NUM_LIT:1> ) <EOL> LOGGER . debug ( '<STR_LIT>' % <EOL> ( self . parent . kvp [ '<STR_LIT>' ] , max1 ) ) <EOL> for res in results : <EOL> try : <EOL> if ( self . parent . kvp [ '<STR_LIT>' ] == <EOL> '<STR_LIT>' and <EOL> '<STR_LIT>' in self . parent . kvp [ '<STR_LIT>' ] ) : <EOL> searchresults . append ( self . _write_record ( <EOL> res , self . parent . repository . queryables [ '<STR_LIT>' ] ) ) <EOL> elif ( self . parent . kvp [ '<STR_LIT>' ] == <EOL> '<STR_LIT>' and <EOL> '<STR_LIT>' not in self . parent . kvp [ '<STR_LIT>' ] ) : <EOL> for prof in self . parent . profiles [ '<STR_LIT>' ] : <EOL> if self . parent . profiles [ '<STR_LIT>' ] [ prof ] . typename in self . parent . kvp [ '<STR_LIT>' ] : <EOL> typename = self . parent . profiles [ '<STR_LIT>' ] [ prof ] . typename <EOL> break <EOL> util . transform_mappings ( self . parent . repository . queryables [ '<STR_LIT>' ] , <EOL> self . parent . context . model [ '<STR_LIT>' ] [ typename ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , reverse = True ) <EOL> searchresults . append ( self . _write_record ( <EOL> res , self . parent . repository . queryables [ '<STR_LIT>' ] ) ) <EOL> elif self . parent . kvp [ '<STR_LIT>' ] in self . parent . outputschemas : <EOL> searchresults . append ( self . parent . outputschemas [ self . parent . kvp [ '<STR_LIT>' ] ] . write_record ( res , self . parent . kvp [ '<STR_LIT>' ] , self . parent . context , self . parent . config . get ( '<STR_LIT>' , '<STR_LIT:url>' ) ) ) <EOL> else : <EOL> searchresults . append ( <EOL> self . parent . profiles [ '<STR_LIT>' ] [ self . parent . kvp [ '<STR_LIT>' ] ] . write_record ( res , self . parent . kvp [ '<STR_LIT>' ] , <EOL> self . parent . kvp [ '<STR_LIT>' ] , <EOL> self . parent . repository . queryables [ '<STR_LIT>' ] ) ) <EOL> except Exception as err : <EOL> self . parent . response = self . exceptionreport ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' % str ( err ) ) <EOL> return self . parent . response <EOL> if ( self . parent . config . has_option ( '<STR_LIT>' , '<STR_LIT>' ) and <EOL> '<STR_LIT>' in self . parent . kvp and <EOL> self . parent . kvp [ '<STR_LIT>' ] and self . parent . kvp [ '<STR_LIT>' ] > <NUM_LIT:0> ) : <EOL> LOGGER . debug ( '<STR_LIT>' % <EOL> self . parent . kvp [ '<STR_LIT>' ] ) <EOL> from owslib . csw import CatalogueServiceWeb <EOL> from owslib . ows import ExceptionReport <EOL> for fedcat in self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) : <EOL> LOGGER . debug ( '<STR_LIT>' % fedcat ) <EOL> try : <EOL> start_time = time ( ) <EOL> remotecsw = CatalogueServiceWeb ( fedcat , skip_caps = True ) <EOL> remotecsw . getrecords2 ( xml = self . parent . request , <EOL> esn = self . parent . kvp [ '<STR_LIT>' ] , <EOL> outputschema = self . parent . kvp [ '<STR_LIT>' ] ) <EOL> fsr = etree . SubElement ( searchresults , util . nspath_eval ( <EOL> '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , <EOL> catalogueURL = fedcat . request ) <EOL> msg = '<STR_LIT>' % ( fedcat , remotecsw . results ) <EOL> LOGGER . debug ( msg ) <EOL> fsr . append ( etree . Comment ( msg ) ) <EOL> search_result = etree . SubElement ( fsr , util . nspath_eval ( <EOL> '<STR_LIT>' , self . parent . context . namespaces ) , <EOL> recordSchema = self . parent . kvp [ '<STR_LIT>' ] , <EOL> elementSetName = self . parent . kvp [ '<STR_LIT>' ] , <EOL> numberOfRecordsMatched = fedcat . results [ '<STR_LIT>' ] , <EOL> numberOfRecordsReturned = fedcat . results [ '<STR_LIT>' ] , <EOL> nextRecord = fedcat . results [ '<STR_LIT>' ] , <EOL> elapsedTime = get_elapsed_time ( start_time , time ( ) ) , <EOL> status = get_resultset_status ( <EOL> fedcat . results [ '<STR_LIT>' ] , <EOL> fedcat . results [ '<STR_LIT>' ] ) ) <EOL> search_result . append ( remotecsw . records ) <EOL> except ExceptionReport as err : <EOL> error_string = '<STR_LIT>' % fedcat <EOL> searchresults . append ( etree . Comment ( <EOL> '<STR_LIT>' % ( error_string , err ) ) ) <EOL> LOGGER . debug ( str ( err ) ) <EOL> except Exception as err : <EOL> error_string = '<STR_LIT>' % fedcat <EOL> searchresults . append ( etree . Comment ( <EOL> '<STR_LIT>' % ( error_string , err ) ) ) <EOL> LOGGER . debug ( str ( err ) ) <EOL> searchresults . attrib [ '<STR_LIT>' ] = get_elapsed_time ( self . parent . process_time_start , time ( ) ) <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> self . parent . _process_responsehandler ( etree . tostring ( node , <EOL> pretty_print = self . parent . pretty_print ) ) <EOL> else : <EOL> return node <EOL> def getrecordbyid ( self , raw = False ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT:id>' not in self . parent . kvp : <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT:id>' , <EOL> '<STR_LIT>' ) <EOL> if len ( self . parent . kvp [ '<STR_LIT:id>' ] ) < <NUM_LIT:1> : <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT:id>' , <EOL> '<STR_LIT>' ) <EOL> if '<STR_LIT>' not in self . parent . kvp : <EOL> self . parent . kvp [ '<STR_LIT>' ] = self . parent . context . namespaces [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in self . parent . environ : <EOL> LOGGER . debug ( '<STR_LIT>' , self . parent . environ [ '<STR_LIT>' ] ) <EOL> formats_match = False <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> LOGGER . debug ( self . parent . kvp [ '<STR_LIT>' ] ) <EOL> for ofmt in self . parent . environ [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> LOGGER . debug ( '<STR_LIT>' , ofmt , self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if ofmt . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] in self . parent . kvp [ '<STR_LIT>' ] : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> formats_match = True <EOL> if not formats_match : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % <EOL> ( self . parent . environ [ '<STR_LIT>' ] , self . parent . kvp [ '<STR_LIT>' ] ) ) <EOL> else : <EOL> for ofmt in self . parent . environ [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> if ofmt in self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> self . parent . kvp [ '<STR_LIT>' ] = ofmt <EOL> break <EOL> if ( '<STR_LIT>' in self . parent . kvp and <EOL> self . parent . kvp [ '<STR_LIT>' ] not in <EOL> self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % <EOL> self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if ( '<STR_LIT>' in self . parent . kvp and self . parent . kvp [ '<STR_LIT>' ] not in <EOL> self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % <EOL> self . parent . kvp [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> self . parent . contenttype = self . parent . kvp [ '<STR_LIT>' ] <EOL> if self . parent . kvp [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> self . parent . kvp [ '<STR_LIT>' ] = self . parent . context . namespaces [ '<STR_LIT>' ] <EOL> self . parent . mode = '<STR_LIT>' <EOL> if '<STR_LIT>' not in self . parent . kvp : <EOL> self . parent . kvp [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> else : <EOL> if ( self . parent . kvp [ '<STR_LIT>' ] not in <EOL> self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % <EOL> self . parent . kvp [ '<STR_LIT>' ] ) <EOL> LOGGER . debug ( '<STR_LIT>' % self . parent . kvp [ '<STR_LIT:id>' ] ) <EOL> results = self . parent . repository . query_ids ( [ self . parent . kvp [ '<STR_LIT:id>' ] ] ) <EOL> if raw : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> if len ( results ) > <NUM_LIT:0> : <EOL> return etree . fromstring ( util . getqattr ( results [ <NUM_LIT:0> ] , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , self . parent . context . parser ) <EOL> for result in results : <EOL> if ( util . getqattr ( result , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) == '<STR_LIT>' <EOL> and self . parent . kvp [ '<STR_LIT>' ] == <EOL> '<STR_LIT>' ) : <EOL> node = self . _write_record ( <EOL> result , self . parent . repository . queryables [ '<STR_LIT>' ] ) <EOL> elif ( self . parent . kvp [ '<STR_LIT>' ] == <EOL> '<STR_LIT>' ) : <EOL> typename = None <EOL> for prof in self . parent . profiles [ '<STR_LIT>' ] : <EOL> if self . parent . profiles [ '<STR_LIT>' ] [ prof ] . typename in [ util . getqattr ( result , self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ] : <EOL> typename = self . parent . profiles [ '<STR_LIT>' ] [ prof ] . typename <EOL> break <EOL> if typename is not None : <EOL> util . transform_mappings ( self . parent . repository . queryables [ '<STR_LIT>' ] , <EOL> self . parent . context . model [ '<STR_LIT>' ] [ typename ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] , reverse = True ) <EOL> node = self . _write_record ( result , self . parent . repository . queryables [ '<STR_LIT>' ] ) <EOL> elif self . parent . kvp [ '<STR_LIT>' ] in self . parent . outputschemas : <EOL> node = self . parent . outputschemas [ self . parent . kvp [ '<STR_LIT>' ] ] . write_record ( result , self . parent . kvp [ '<STR_LIT>' ] , self . parent . context , self . parent . config . get ( '<STR_LIT>' , '<STR_LIT:url>' ) ) <EOL> else : <EOL> node = self . parent . profiles [ '<STR_LIT>' ] [ self . parent . kvp [ '<STR_LIT>' ] ] . write_record ( <EOL> result , self . parent . kvp [ '<STR_LIT>' ] , <EOL> self . parent . kvp [ '<STR_LIT>' ] , self . parent . repository . queryables [ '<STR_LIT>' ] ) <EOL> if raw and len ( results ) == <NUM_LIT:0> : <EOL> return None <EOL> if len ( results ) == <NUM_LIT:0> : <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT:id>' , <EOL> '<STR_LIT>' % self . parent . kvp [ '<STR_LIT:id>' ] ) <EOL> return node <EOL> def getrepositoryitem ( self ) : <EOL> '''<STR_LIT>''' <EOL> node = self . parent . getrecordbyid ( raw = True ) <EOL> if node is None : <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT:id>' , <EOL> '<STR_LIT>' % self . parent . kvp [ '<STR_LIT:id>' ] ) <EOL> else : <EOL> return node <EOL> def transaction ( self ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> self . parent . _test_manager ( ) <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT>' , <EOL> str ( err ) ) <EOL> inserted = <NUM_LIT:0> <EOL> updated = <NUM_LIT:0> <EOL> deleted = <NUM_LIT:0> <EOL> insertresults = [ ] <EOL> LOGGER . debug ( '<STR_LIT>' % self . parent . kvp [ '<STR_LIT>' ] ) <EOL> for ttype in self . parent . kvp [ '<STR_LIT>' ] : <EOL> if ttype [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> try : <EOL> record = metadata . parse_record ( self . parent . context , <EOL> ttype [ '<STR_LIT>' ] , self . parent . repository ) [ <NUM_LIT:0> ] <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' % str ( err ) ) <EOL> LOGGER . debug ( '<STR_LIT>' % record ) <EOL> if not hasattr ( record , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> self . parent . repository . insert ( record , '<STR_LIT>' , <EOL> util . get_today_and_now ( ) ) <EOL> inserted += <NUM_LIT:1> <EOL> insertresults . append ( <EOL> { '<STR_LIT>' : getattr ( record , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT:title>' : getattr ( record , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) } ) <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % str ( err ) ) <EOL> elif ttype [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> if '<STR_LIT>' not in ttype : <EOL> try : <EOL> record = metadata . parse_record ( self . parent . context , <EOL> ttype [ '<STR_LIT>' ] , self . parent . repository ) [ <NUM_LIT:0> ] <EOL> identifier = getattr ( record , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' % str ( err ) ) <EOL> LOGGER . debug ( '<STR_LIT>' % identifier ) <EOL> results = self . parent . repository . query_ids ( ids = [ identifier ] ) <EOL> if len ( results ) == <NUM_LIT:0> : <EOL> LOGGER . debug ( '<STR_LIT>' % identifier ) <EOL> else : <EOL> try : <EOL> self . parent . repository . update ( record ) <EOL> updated += <NUM_LIT:1> <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % str ( err ) ) <EOL> else : <EOL> for rp in ttype [ '<STR_LIT>' ] : <EOL> if rp [ '<STR_LIT:name>' ] not in self . parent . repository . queryables [ '<STR_LIT>' ] : <EOL> if rp [ '<STR_LIT:name>' ] . find ( '<STR_LIT:/>' ) != - <NUM_LIT:1> : <EOL> for osch in self . parent . outputschemas . values ( ) : <EOL> for key , value in osch . XPATH_MAPPINGS . items ( ) : <EOL> if value == rp [ '<STR_LIT:name>' ] : <EOL> rp [ '<STR_LIT>' ] = { '<STR_LIT>' : value , '<STR_LIT:name>' : key } <EOL> rp [ '<STR_LIT>' ] [ '<STR_LIT>' ] = self . parent . repository . queryables [ '<STR_LIT>' ] [ key ] <EOL> break <EOL> else : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % str ( rp [ '<STR_LIT:name>' ] ) ) <EOL> else : <EOL> rp [ '<STR_LIT>' ] = self . parent . repository . queryables [ '<STR_LIT>' ] [ rp [ '<STR_LIT:name>' ] ] <EOL> LOGGER . debug ( '<STR_LIT>' % <EOL> ttype [ '<STR_LIT>' ] ) <EOL> try : <EOL> updated += self . parent . repository . update ( record = None , <EOL> recprops = ttype [ '<STR_LIT>' ] , <EOL> constraint = ttype [ '<STR_LIT>' ] ) <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % str ( err ) ) <EOL> elif ttype [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> deleted += self . parent . repository . delete ( ttype [ '<STR_LIT>' ] ) <EOL> node = etree . Element ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , nsmap = self . parent . context . namespaces , version = '<STR_LIT>' ) <EOL> node . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = '<STR_LIT>' % ( self . parent . context . namespaces [ '<STR_LIT>' ] , self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> node . append ( <EOL> self . _write_transactionsummary ( <EOL> inserted = inserted , updated = updated , deleted = deleted ) ) <EOL> if ( len ( insertresults ) > <NUM_LIT:0> and self . parent . kvp [ '<STR_LIT>' ] ) : <EOL> node . append ( self . _write_verboseresponse ( insertresults ) ) <EOL> return node <EOL> def harvest ( self ) : <EOL> '''<STR_LIT>''' <EOL> service_identifier = None <EOL> old_identifier = None <EOL> deleted = [ ] <EOL> try : <EOL> self . parent . _test_manager ( ) <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT>' , str ( err ) ) <EOL> if self . parent . requesttype == '<STR_LIT:GET>' : <EOL> if '<STR_LIT>' not in self . parent . kvp : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> if '<STR_LIT:source>' not in self . parent . kvp : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT:source>' , '<STR_LIT>' ) <EOL> if ( self . parent . kvp [ '<STR_LIT>' ] not in <EOL> self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> [ '<STR_LIT>' ] ) : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' % ( self . parent . kvp [ '<STR_LIT>' ] , <EOL> '<STR_LIT:U+002C>' . join ( self . parent . context . model [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ) ) <EOL> if ( self . parent . kvp [ '<STR_LIT>' ] . find ( '<STR_LIT>' ) == - <NUM_LIT:1> and <EOL> self . parent . kvp [ '<STR_LIT>' ] . find ( '<STR_LIT>' ) == - <NUM_LIT:1> ) : <EOL> LOGGER . debug ( '<STR_LIT>' % self . parent . kvp [ '<STR_LIT:source>' ] ) <EOL> try : <EOL> content = util . http_request ( '<STR_LIT:GET>' , self . parent . kvp [ '<STR_LIT:source>' ] ) <EOL> except Exception as err : <EOL> errortext = '<STR_LIT>' % ( self . parent . kvp [ '<STR_LIT:source>' ] , str ( err ) ) <EOL> LOGGER . debug ( errortext ) <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT:source>' , <EOL> errortext ) <EOL> else : <EOL> content = self . parent . kvp [ '<STR_LIT:source>' ] <EOL> LOGGER . debug ( '<STR_LIT>' % content ) <EOL> results = self . parent . repository . query_source ( content ) <EOL> if len ( results ) > <NUM_LIT:0> : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> service_identifier = results [ <NUM_LIT:0> ] . identifier <EOL> service_results = results <EOL> LOGGER . debug ( '<STR_LIT>' % service_identifier ) <EOL> try : <EOL> records_parsed = metadata . parse_record ( self . parent . context , <EOL> content , self . parent . repository , self . parent . kvp [ '<STR_LIT>' ] , <EOL> pagesize = self . parent . csw_harvest_pagesize ) <EOL> except Exception as err : <EOL> LOGGER . exception ( err ) <EOL> return self . exceptionreport ( '<STR_LIT>' , '<STR_LIT:source>' , <EOL> '<STR_LIT>' % str ( err ) ) <EOL> inserted = <NUM_LIT:0> <EOL> updated = <NUM_LIT:0> <EOL> ir = [ ] <EOL> LOGGER . debug ( '<STR_LIT>' % len ( records_parsed ) ) <EOL> for record in records_parsed : <EOL> if self . parent . kvp [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> src = record . source <EOL> else : <EOL> src = self . parent . kvp [ '<STR_LIT:source>' ] <EOL> setattr ( record , self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> src ) <EOL> setattr ( record , self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> util . get_today_and_now ( ) ) <EOL> identifier = getattr ( record , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> source = getattr ( record , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> insert_date = getattr ( record , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> title = getattr ( record , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if record . type == '<STR_LIT>' and service_identifier is not None : <EOL> LOGGER . debug ( '<STR_LIT>' % ( record . identifier , service_identifier ) ) <EOL> old_identifier = record . identifier <EOL> identifier = record . identifier = service_identifier <EOL> if ( record . type != '<STR_LIT>' and service_identifier is not None <EOL> and old_identifier is not None ) : <EOL> if record . identifier . find ( old_identifier ) != - <NUM_LIT:1> : <EOL> new_identifier = record . identifier . replace ( old_identifier , service_identifier ) <EOL> LOGGER . debug ( '<STR_LIT>' % ( record . identifier , new_identifier ) ) <EOL> identifier = record . identifier = new_identifier <EOL> ir . append ( { '<STR_LIT>' : identifier , '<STR_LIT:title>' : title } ) <EOL> LOGGER . debug ( '<STR_LIT>' % identifier ) <EOL> results = self . parent . repository . query_ids ( ids = [ identifier ] ) <EOL> if len ( results ) == <NUM_LIT:0> : <EOL> LOGGER . debug ( '<STR_LIT>' % service_identifier ) <EOL> results = self . parent . repository . query_ids ( ids = [ service_identifier ] ) <EOL> LOGGER . debug ( str ( results ) ) <EOL> if len ( results ) == <NUM_LIT:0> : <EOL> inserted += <NUM_LIT:1> <EOL> try : <EOL> self . parent . repository . insert ( record , source , insert_date ) <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT:source>' , '<STR_LIT>' % str ( err ) ) <EOL> else : <EOL> if source != results [ <NUM_LIT:0> ] . source : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT:source>' , '<STR_LIT>' % ( identifier , source ) ) <EOL> try : <EOL> self . parent . repository . update ( record ) <EOL> except Exception as err : <EOL> return self . exceptionreport ( '<STR_LIT>' , <EOL> '<STR_LIT:source>' , '<STR_LIT>' % str ( err ) ) <EOL> updated += <NUM_LIT:1> <EOL> node = etree . Element ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , nsmap = self . parent . context . namespaces ) <EOL> node . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = '<STR_LIT>' % ( self . parent . context . namespaces [ '<STR_LIT>' ] , <EOL> self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> node2 = etree . SubElement ( node , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , version = '<STR_LIT>' ) <EOL> if service_identifier is not None : <EOL> fresh_records = [ str ( i [ '<STR_LIT>' ] ) for i in ir ] <EOL> existing_records = [ str ( i . identifier ) for i in service_results ] <EOL> deleted = set ( existing_records ) - set ( fresh_records ) <EOL> LOGGER . debug ( '<STR_LIT>' % str ( deleted ) ) <EOL> for to_delete in deleted : <EOL> delete_constraint = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ to_delete ] , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> self . parent . repository . delete ( delete_constraint ) <EOL> node2 . append ( <EOL> self . _write_transactionsummary ( inserted = inserted , updated = updated , <EOL> deleted = len ( deleted ) ) ) <EOL> if inserted > <NUM_LIT:0> : <EOL> node2 . append ( self . _write_verboseresponse ( ir ) ) <EOL> if '<STR_LIT>' in self . parent . kvp : <EOL> self . parent . _process_responsehandler ( etree . tostring ( node , <EOL> pretty_print = self . parent . pretty_print ) ) <EOL> else : <EOL> return node <EOL> def _write_record ( self , recobj , queryables ) : <EOL> '''<STR_LIT>''' <EOL> if self . parent . kvp [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> elname = '<STR_LIT>' <EOL> elif self . parent . kvp [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> elname = '<STR_LIT>' <EOL> else : <EOL> elname = '<STR_LIT>' <EOL> record = etree . Element ( util . nspath_eval ( '<STR_LIT>' % elname , <EOL> self . parent . context . namespaces ) , nsmap = self . parent . context . namespaces ) <EOL> if ( '<STR_LIT>' in self . parent . kvp and <EOL> len ( self . parent . kvp [ '<STR_LIT>' ] ) > <NUM_LIT:0> ) : <EOL> for req_term in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if req_term not in self . parent . kvp [ '<STR_LIT>' ] : <EOL> value = util . getqattr ( recobj , queryables [ req_term ] [ '<STR_LIT>' ] ) <EOL> etree . SubElement ( record , <EOL> util . nspath_eval ( req_term , <EOL> self . parent . context . namespaces ) ) . text = value <EOL> for elemname in self . parent . kvp [ '<STR_LIT>' ] : <EOL> if ( elemname . find ( '<STR_LIT>' ) != - <NUM_LIT:1> or <EOL> elemname . find ( '<STR_LIT>' ) != - <NUM_LIT:1> ) : <EOL> bboxel = write_boundingbox ( util . getqattr ( recobj , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <EOL> self . parent . context . namespaces ) <EOL> if bboxel is not None : <EOL> record . append ( bboxel ) <EOL> else : <EOL> value = util . getqattr ( recobj , queryables [ elemname ] [ '<STR_LIT>' ] ) <EOL> elem = etree . SubElement ( record , <EOL> util . nspath_eval ( elemname , <EOL> self . parent . context . namespaces ) ) <EOL> if value : <EOL> elem . text = value <EOL> elif '<STR_LIT>' in self . parent . kvp : <EOL> if ( self . parent . kvp [ '<STR_LIT>' ] == '<STR_LIT>' and <EOL> util . getqattr ( recobj , self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) == '<STR_LIT>' and <EOL> util . getqattr ( recobj , self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) == '<STR_LIT>' and <EOL> util . getqattr ( recobj , self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) != '<STR_LIT>' ) : <EOL> return etree . fromstring ( util . getqattr ( recobj , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , self . parent . context . parser ) <EOL> etree . SubElement ( record , <EOL> util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) . text = util . getqattr ( recobj , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> for i in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> val = util . getqattr ( recobj , queryables [ i ] [ '<STR_LIT>' ] ) <EOL> if not val : <EOL> val = '<STR_LIT>' <EOL> etree . SubElement ( record , util . nspath_eval ( i , <EOL> self . parent . context . namespaces ) ) . text = val <EOL> if self . parent . kvp [ '<STR_LIT>' ] in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> keywords = util . getqattr ( recobj , queryables [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if keywords is not None : <EOL> for keyword in keywords . split ( '<STR_LIT:U+002C>' ) : <EOL> etree . SubElement ( record , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = keyword <EOL> val = util . getqattr ( recobj , queryables [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if val : <EOL> etree . SubElement ( record , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = val <EOL> rlinks = util . getqattr ( recobj , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if rlinks : <EOL> links = rlinks . split ( '<STR_LIT>' ) <EOL> for link in links : <EOL> linkset = link . split ( '<STR_LIT:U+002C>' ) <EOL> etree . SubElement ( record , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , <EOL> scheme = linkset [ <NUM_LIT:2> ] ) . text = linkset [ - <NUM_LIT:1> ] <EOL> for i in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> val = util . getqattr ( recobj , queryables [ i ] [ '<STR_LIT>' ] ) <EOL> if val is not None : <EOL> etree . SubElement ( record , <EOL> util . nspath_eval ( i , self . parent . context . namespaces ) ) . text = val <EOL> if self . parent . kvp [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> for i in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> val = util . getqattr ( recobj , queryables [ i ] [ '<STR_LIT>' ] ) <EOL> if val : <EOL> etree . SubElement ( record , <EOL> util . nspath_eval ( i , self . parent . context . namespaces ) ) . text = val <EOL> bboxel = write_boundingbox ( getattr ( recobj , <EOL> self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <EOL> self . parent . context . namespaces ) <EOL> if bboxel is not None : <EOL> record . append ( bboxel ) <EOL> if self . parent . kvp [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> begin = util . getqattr ( record , self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> end = util . getqattr ( record , self . parent . context . md_core_model [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> if begin or end : <EOL> tempext = etree . SubElement ( record , util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> if begin : <EOL> etree . SubElement ( record , util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) . text = begin <EOL> if end : <EOL> etree . SubElement ( record , util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) . text = end <EOL> return record <EOL> def _parse_constraint ( self , element ) : <EOL> '''<STR_LIT>''' <EOL> query = { } <EOL> tmp = element . find ( util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> try : <EOL> query [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> query [ '<STR_LIT>' ] , query [ '<STR_LIT>' ] = fes2 . parse ( tmp , <EOL> self . parent . repository . queryables [ '<STR_LIT>' ] , self . parent . repository . dbtype , <EOL> self . parent . context . namespaces , self . parent . orm , self . parent . language [ '<STR_LIT:text>' ] , self . parent . repository . fts ) <EOL> except Exception as err : <EOL> return '<STR_LIT>' % err <EOL> tmp = element . find ( util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> LOGGER . debug ( '<STR_LIT>' % tmp . text ) <EOL> query [ '<STR_LIT:type>' ] = '<STR_LIT>' <EOL> query [ '<STR_LIT>' ] = self . parent . _cql_update_queryables_mappings ( tmp . text , <EOL> self . parent . repository . queryables [ '<STR_LIT>' ] ) <EOL> query [ '<STR_LIT>' ] = { } <EOL> return query <EOL> def parse_postdata ( self , postdata ) : <EOL> '''<STR_LIT>''' <EOL> request = { } <EOL> try : <EOL> LOGGER . debug ( '<STR_LIT>' % postdata ) <EOL> doc = etree . fromstring ( postdata , self . parent . context . parser ) <EOL> except Exception as err : <EOL> errortext = '<STR_LIT>' % str ( err ) <EOL> LOGGER . debug ( errortext ) <EOL> return errortext <EOL> if ( doc . tag == util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> self . parent . soap = True <EOL> doc = doc . find ( <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . xpath ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> xsd_filename = '<STR_LIT>' % util . xmltag_split ( doc . tag ) <EOL> schema = os . path . join ( self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , xsd_filename ) <EOL> try : <EOL> if doc . find ( '<STR_LIT>' % util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) is None and len ( doc . xpath ( '<STR_LIT>' , <EOL> namespaces = self . parent . context . namespaces ) ) == <NUM_LIT:0> : <EOL> LOGGER . debug ( '<STR_LIT>' % postdata ) <EOL> schema = etree . XMLSchema ( file = schema ) <EOL> parser = etree . XMLParser ( schema = schema , resolve_entities = False ) <EOL> if hasattr ( self . parent , '<STR_LIT>' ) and self . parent . soap : <EOL> doc = etree . fromstring ( etree . tostring ( doc ) , parser ) <EOL> else : <EOL> doc = etree . fromstring ( postdata , parser ) <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> else : <EOL> doc = etree . fromstring ( postdata , self . parent . context . parser ) <EOL> except Exception as err : <EOL> errortext = '<STR_LIT>' % str ( err ) <EOL> LOGGER . debug ( errortext ) <EOL> return errortext <EOL> request [ '<STR_LIT>' ] = util . xmltag_split ( doc . tag ) <EOL> LOGGER . debug ( '<STR_LIT>' % request [ '<STR_LIT>' ] ) <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT>' ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = tmp <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT:version>' ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT:version>' ] = tmp <EOL> tmp = doc . find ( '<STR_LIT>' % util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT:version>' ] = tmp . text <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT>' ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = tmp <EOL> if request [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = '<STR_LIT:U+002C>' . join ( [ section . text for section in doc . findall ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) ] ) <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = '<STR_LIT:U+002C>' . join ( [ aformat . text for aformat in doc . findall ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) ] ) <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = '<STR_LIT:U+002C>' . join ( [ version . text for version in doc . findall ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) ] ) <EOL> if request [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = tmp . text <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = tmp . text <EOL> if request [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT>' ) <EOL> request [ '<STR_LIT>' ] = tmp if tmp is not None else self . parent . context . namespaces [ '<STR_LIT>' ] <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT>' ) <EOL> request [ '<STR_LIT>' ] = tmp if tmp is not None else '<STR_LIT>' <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT>' ) <EOL> request [ '<STR_LIT>' ] = tmp if tmp is not None else <NUM_LIT:1> <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT>' ) <EOL> request [ '<STR_LIT>' ] = tmp if tmp is not None else None <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT>' ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = tmp <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = True <EOL> hopcount = tmp . attrib . get ( '<STR_LIT>' ) <EOL> request [ '<STR_LIT>' ] = int ( hopcount ) - <NUM_LIT:1> if hopcount is not None else <NUM_LIT:1> <EOL> else : <EOL> request [ '<STR_LIT>' ] = False <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = tmp . text <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> request [ '<STR_LIT>' ] = tmp . text if tmp is not None else None <EOL> tmp = doc . find ( util . nspath_eval ( <EOL> '<STR_LIT>' , self . parent . context . namespaces ) ) . attrib . get ( '<STR_LIT>' ) <EOL> request [ '<STR_LIT>' ] = tmp . split ( ) if tmp is not None else '<STR_LIT>' <EOL> request [ '<STR_LIT>' ] = [ elname . text for elname in doc . findall ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) ] <EOL> request [ '<STR_LIT>' ] = { } <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = self . _parse_constraint ( tmp ) <EOL> if isinstance ( request [ '<STR_LIT>' ] , str ) : <EOL> return '<STR_LIT>' % request [ '<STR_LIT>' ] <EOL> else : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> LOGGER . debug ( '<STR_LIT>' ) <EOL> request [ '<STR_LIT>' ] = { } <EOL> try : <EOL> elname = tmp . find ( util . nspath_eval ( <EOL> '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = self . parent . repository . queryables [ '<STR_LIT>' ] [ elname ] [ '<STR_LIT>' ] <EOL> if ( elname . find ( '<STR_LIT>' ) != - <NUM_LIT:1> or <EOL> elname . find ( '<STR_LIT>' ) != - <NUM_LIT:1> ) : <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = True <EOL> except Exception as err : <EOL> errortext = '<STR_LIT>' % str ( err ) <EOL> LOGGER . debug ( errortext ) <EOL> return errortext <EOL> tmp2 = tmp . find ( util . nspath_eval ( <EOL> '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> request [ '<STR_LIT>' ] [ '<STR_LIT>' ] = tmp2 . text if tmp2 is not None else '<STR_LIT>' <EOL> else : <EOL> request [ '<STR_LIT>' ] = None <EOL> if request [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> request [ '<STR_LIT:id>' ] = None <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT:id>' ] = tmp . text <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> request [ '<STR_LIT>' ] = tmp . text if tmp is not None else '<STR_LIT>' <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT>' ) <EOL> request [ '<STR_LIT>' ] = tmp if tmp is not None else self . parent . context . namespaces [ '<STR_LIT>' ] <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT>' ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = tmp <EOL> if request [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> request [ '<STR_LIT>' ] = True <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT>' ) <EOL> if tmp is not None : <EOL> if tmp in [ '<STR_LIT:false>' , '<STR_LIT:0>' ] : <EOL> request [ '<STR_LIT>' ] = False <EOL> tmp = doc . find ( '<STR_LIT:.>' ) . attrib . get ( '<STR_LIT>' ) <EOL> request [ '<STR_LIT>' ] = tmp if tmp is not None else None <EOL> request [ '<STR_LIT>' ] = [ ] <EOL> for ttype in doc . xpath ( '<STR_LIT>' , namespaces = self . parent . context . namespaces ) : <EOL> tname = ttype . attrib . get ( '<STR_LIT>' ) <EOL> for mdrec in ttype . xpath ( '<STR_LIT>' ) : <EOL> xml = mdrec <EOL> request [ '<STR_LIT>' ] . append ( <EOL> { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : tname , '<STR_LIT>' : xml } ) <EOL> for ttype in doc . xpath ( '<STR_LIT>' , namespaces = self . parent . context . namespaces ) : <EOL> child = ttype . xpath ( '<STR_LIT>' ) <EOL> update = { '<STR_LIT:type>' : '<STR_LIT>' } <EOL> if len ( child ) == <NUM_LIT:1> : <EOL> update [ '<STR_LIT>' ] = child [ <NUM_LIT:0> ] <EOL> else : <EOL> update [ '<STR_LIT>' ] = [ ] <EOL> for recprop in ttype . findall ( <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) : <EOL> rpname = recprop . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text <EOL> rpvalue = recprop . find ( <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text <EOL> update [ '<STR_LIT>' ] . append ( <EOL> { '<STR_LIT:name>' : rpname , '<STR_LIT:value>' : rpvalue } ) <EOL> update [ '<STR_LIT>' ] = self . _parse_constraint ( <EOL> ttype . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) ) <EOL> request [ '<STR_LIT>' ] . append ( update ) <EOL> for ttype in doc . xpath ( '<STR_LIT>' , namespaces = self . parent . context . namespaces ) : <EOL> tname = ttype . attrib . get ( '<STR_LIT>' ) <EOL> constraint = self . _parse_constraint ( <EOL> ttype . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) ) <EOL> if isinstance ( constraint , str ) : <EOL> return '<STR_LIT>' % constraint <EOL> request [ '<STR_LIT>' ] . append ( <EOL> { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : tname , '<STR_LIT>' : constraint } ) <EOL> if request [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> request [ '<STR_LIT:source>' ] = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text <EOL> request [ '<STR_LIT>' ] = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = tmp . text <EOL> else : <EOL> request [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = tmp . text <EOL> tmp = doc . find ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if tmp is not None : <EOL> request [ '<STR_LIT>' ] = tmp . text <EOL> return request <EOL> def _write_transactionsummary ( self , inserted = <NUM_LIT:0> , updated = <NUM_LIT:0> , deleted = <NUM_LIT:0> ) : <EOL> '''<STR_LIT>''' <EOL> node = etree . Element ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if '<STR_LIT>' in self . parent . kvp and self . parent . kvp [ '<STR_LIT>' ] is not None : <EOL> node . attrib [ '<STR_LIT>' ] = self . parent . kvp [ '<STR_LIT>' ] <EOL> etree . SubElement ( node , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = str ( inserted ) <EOL> etree . SubElement ( node , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = str ( updated ) <EOL> etree . SubElement ( node , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = str ( deleted ) <EOL> return node <EOL> def _write_acknowledgement ( self , root = True ) : <EOL> '''<STR_LIT>''' <EOL> node = etree . Element ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , <EOL> nsmap = self . parent . context . namespaces , timeStamp = util . get_today_and_now ( ) ) <EOL> if root : <EOL> node . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = '<STR_LIT>' % ( self . parent . context . namespaces [ '<STR_LIT>' ] , self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> node1 = etree . SubElement ( node , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> if self . parent . requesttype == '<STR_LIT:POST>' : <EOL> node1 . append ( etree . fromstring ( self . parent . request , self . parent . context . parser ) ) <EOL> else : <EOL> node2 = etree . SubElement ( node1 , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> node2 . text = self . parent . request <EOL> if self . parent . async : <EOL> etree . SubElement ( node , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = self . parent . kvp [ '<STR_LIT>' ] <EOL> return node <EOL> def _write_verboseresponse ( self , insertresults ) : <EOL> '''<STR_LIT>''' <EOL> insertresult = etree . Element ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> for ir in insertresults : <EOL> briefrec = etree . SubElement ( insertresult , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> etree . SubElement ( briefrec , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = ir [ '<STR_LIT>' ] <EOL> etree . SubElement ( briefrec , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = ir [ '<STR_LIT:title>' ] <EOL> return insertresult <EOL> def _write_allowed_values ( self , values ) : <EOL> '''<STR_LIT>''' <EOL> allowed_values = etree . Element ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) <EOL> for value in sorted ( values ) : <EOL> etree . SubElement ( allowed_values , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = value <EOL> return allowed_values <EOL> def exceptionreport ( self , code , locator , text ) : <EOL> '''<STR_LIT>''' <EOL> self . parent . exception = True <EOL> self . parent . status = code <EOL> try : <EOL> language = self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ogc_schemas_base = self . parent . config . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> except : <EOL> language = '<STR_LIT>' <EOL> ogc_schemas_base = self . parent . context . ogc_schemas_base <EOL> node = etree . Element ( util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , nsmap = self . parent . context . namespaces , <EOL> version = '<STR_LIT>' ) <EOL> node . attrib [ '<STR_LIT>' ] = language <EOL> node . attrib [ util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ] = '<STR_LIT>' % ( self . parent . context . namespaces [ '<STR_LIT>' ] , ogc_schemas_base ) <EOL> exception = etree . SubElement ( node , util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) , <EOL> exceptionCode = code , locator = locator ) <EOL> etree . SubElement ( exception , <EOL> util . nspath_eval ( '<STR_LIT>' , <EOL> self . parent . context . namespaces ) ) . text = text <EOL> return node <EOL> def resolve_nsmap ( self , list_ ) : <EOL> '''<STR_LIT>''' <EOL> nsmap = { } <EOL> tns = [ ] <EOL> LOGGER . debug ( '<STR_LIT>' , list_ ) <EOL> for ns in self . parent . kvp [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> nspair = ns . split ( '<STR_LIT:(>' ) [ <NUM_LIT:1> ] . split ( '<STR_LIT:)>' ) [ <NUM_LIT:0> ] . split ( '<STR_LIT:=>' ) <EOL> if len ( nspair ) == <NUM_LIT:1> : <EOL> nsmap [ '<STR_LIT>' ] = nspair [ <NUM_LIT:1> ] <EOL> else : <EOL> nsmap [ nspair [ <NUM_LIT:0> ] ] = nspair [ <NUM_LIT:1> ] <EOL> LOGGER . debug ( '<STR_LIT>' , nsmap ) <EOL> for tn in list_ : <EOL> LOGGER . debug ( tn ) <EOL> if tn . find ( '<STR_LIT::>' ) != - <NUM_LIT:1> : <EOL> prefix = tn . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] <EOL> if prefix in nsmap . keys ( ) : <EOL> uri = nsmap [ prefix ] <EOL> newprefix = next ( k for k , v in self . parent . context . namespaces . items ( ) if v == uri ) <EOL> LOGGER . debug ( uri ) <EOL> LOGGER . debug ( prefix ) <EOL> LOGGER . debug ( newprefix ) <EOL> newvalue = tn . replace ( prefix , newprefix ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> newvalue = tn <EOL> else : <EOL> newvalue = tn <EOL> tns . append ( newvalue ) <EOL> LOGGER . debug ( tns ) <EOL> return tns <EOL> def write_boundingbox ( bbox , nsmap ) : <EOL> '''<STR_LIT>''' <EOL> if bbox is not None : <EOL> try : <EOL> bbox2 = util . wkt2geom ( bbox ) <EOL> except : <EOL> return None <EOL> if len ( bbox2 ) == <NUM_LIT:4> : <EOL> boundingbox = etree . Element ( util . nspath_eval ( '<STR_LIT>' , <EOL> nsmap ) , crs = '<STR_LIT>' , <EOL> dimensions = '<STR_LIT:2>' ) <EOL> etree . SubElement ( boundingbox , util . nspath_eval ( '<STR_LIT>' , <EOL> nsmap ) ) . text = '<STR_LIT>' % ( bbox2 [ <NUM_LIT:1> ] , bbox2 [ <NUM_LIT:0> ] ) <EOL> etree . SubElement ( boundingbox , util . nspath_eval ( '<STR_LIT>' , <EOL> nsmap ) ) . text = '<STR_LIT>' % ( bbox2 [ <NUM_LIT:3> ] , bbox2 [ <NUM_LIT:2> ] ) <EOL> return boundingbox <EOL> else : <EOL> return None <EOL> else : <EOL> return None <EOL> if nextrecord == <NUM_LIT:0> : <EOL> searchresult_status = '<STR_LIT>' <EOL> elif nextrecord > <NUM_LIT:0> : <EOL> searchresult_status = '<STR_LIT>' <EOL> elif matched == <NUM_LIT:0> : <EOL> searchresult_status = '<STR_LIT:none>' <EOL> def get_resultset_status ( matched , nextrecord ) : <EOL> '''<STR_LIT>''' <EOL> status = '<STR_LIT>' <EOL> if nextrecord == <NUM_LIT:0> : <EOL> status = '<STR_LIT>' <EOL> elif matched == <NUM_LIT:0> : <EOL> status = '<STR_LIT:none>' <EOL> return status <EOL> def get_elapsed_time ( begin , end ) : <EOL> '''<STR_LIT>''' <EOL> return str ( int ( ( end - begin ) * <NUM_LIT:1000> ) ) </s>
