#NEWLINE# def getrecords( self ) : #NEWLINE# #INDENT# ' Handle GetRecords request ' #NEWLINE# timestamp = util . get_today_and_now ( ) #NEWLINE# if ( ( 'elementsetname' not in self . parent . kvp ) and ( 'elementname' not in self . parent . kvp ) ) : #NEWLINE# #INDENT# return self . exceptionreport ( 'MissingParameterValue' , 'elementsetname' , 'Missing one of ElementSetName or ElementName parameter(s)' ) #NEWLINE# #UNINDENT# if ( 'outputschema' not in self . parent . kvp ) : #NEWLINE# #INDENT# self . parent . kvp [ 'outputschema' ] = self . parent . context . namespaces [ 'csw' ] #NEWLINE# #UNINDENT# if ( self . parent . kvp [ 'outputschema' ] not in self . parent . context . model [ 'operations' ] [ 'GetRecords' ] [ 'parameters' ] [ 'outputSchema' ] [ 'values' ] ) : #NEWLINE# #INDENT# return self . exceptionreport ( 'InvalidParameterValue' , 'outputschema' , ( 'Invalid outputSchema parameter value: %s' % self . parent . kvp [ 'outputschema' ] ) ) #NEWLINE# #UNINDENT# if ( 'outputformat' not in self . parent . kvp ) : #NEWLINE# #INDENT# self . parent . kvp [ 'outputformat' ] = 'application/xml' #NEWLINE# #UNINDENT# if ( self . parent . kvp [ 'outputformat' ] not in self . parent . context . model [ 'operations' ] [ 'GetRecords' ] [ 'parameters' ] [ 'outputFormat' ] [ 'values' ] ) : #NEWLINE# #INDENT# return self . exceptionreport ( 'InvalidParameterValue' , 'outputformat' , ( 'Invalid outputFormat parameter value: %s' % self . parent . kvp [ 'outputformat' ] ) ) #NEWLINE# #UNINDENT# if ( 'resulttype' not in self . parent . kvp ) : #NEWLINE# #INDENT# self . parent . kvp [ 'resulttype' ] = 'hits' #NEWLINE# #UNINDENT# if ( self . parent . kvp [ 'resulttype' ] is not None ) : #NEWLINE# #INDENT# if ( self . parent . kvp [ 'resulttype' ] not in self . parent . context . model [ 'operations' ] [ 'GetRecords' ] [ 'parameters' ] [ 'resultType' ] [ 'values' ] ) : #NEWLINE# #INDENT# return self . exceptionreport ( 'InvalidParameterValue' , 'resulttype' , ( 'Invalid resultType parameter value: %s' % self . parent . kvp [ 'resulttype' ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( ( 'elementname' not in self . parent . kvp ) or ( len ( self . parent . kvp [ 'elementname' ] ) == 0 ) ) and ( self . parent . kvp [ 'elementsetname' ] not in self . parent . context . model [ 'operations' ] [ 'GetRecords' ] [ 'parameters' ] [ 'ElementSetName' ] [ 'values' ] ) ) : #NEWLINE# #INDENT# return self . exceptionreport ( 'InvalidParameterValue' , 'elementsetname' , ( 'Invalid ElementSetName parameter value: %s' % self . parent . kvp [ 'elementsetname' ] ) ) #NEWLINE# #UNINDENT# if ( ( 'elementname' in self . parent . kvp ) and ( self . parent . requesttype == 'GET' ) ) : #NEWLINE# #INDENT# self . parent . kvp [ 'elementname' ] = self . parent . kvp [ 'elementname' ] . split ( ',' ) #NEWLINE# self . parent . kvp [ 'elementsetname' ] = 'summary' #NEWLINE# #UNINDENT# if ( 'typenames' not in self . parent . kvp ) : #NEWLINE# #INDENT# return self . exceptionreport ( 'MissingParameterValue' , 'typenames' , 'Missing typenames parameter' ) #NEWLINE# #UNINDENT# if ( ( 'typenames' in self . parent . kvp ) and ( self . parent . requesttype == 'GET' ) ) : #NEWLINE# #INDENT# self . parent . kvp [ 'typenames' ] = self . parent . kvp [ 'typenames' ] . split ( ',' ) #NEWLINE# #UNINDENT# if ( 'typenames' in self . parent . kvp ) : #NEWLINE# #INDENT# for tname in self . parent . kvp [ 'typenames' ] : #NEWLINE# #INDENT# if ( tname not in self . parent . context . model [ 'operations' ] [ 'GetRecords' ] [ 'parameters' ] [ 'typeNames' ] [ 'values' ] ) : #NEWLINE# #INDENT# return self . exceptionreport ( 'InvalidParameterValue' , 'typenames' , ( 'Invalid typeNames parameter value: %s' % tname ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( 'elementname' in self . parent . kvp ) : #NEWLINE# #INDENT# for ename in self . parent . kvp [ 'elementname' ] : #NEWLINE# #INDENT# enamelist = self . parent . repository . queryables [ '_all' ] . keys ( ) #NEWLINE# if ( ename not in enamelist ) : #NEWLINE# #INDENT# return self . exceptionreport ( 'InvalidParameterValue' , 'elementname' , ( 'Invalid ElementName parameter value: %s' % ename ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( self . parent . kvp [ 'resulttype' ] == 'validate' ) : #NEWLINE# #INDENT# return self . _write_acknowledgement ( ) #NEWLINE# #UNINDENT# maxrecords_cfg = ( - 1 ) #NEWLINE# if self . parent . config . has_option ( 'server' , 'maxrecords' ) : #NEWLINE# #INDENT# maxrecords_cfg = int ( self . parent . config . get ( 'server' , 'maxrecords' ) ) #NEWLINE# #UNINDENT# if ( 'maxrecords' not in self . parent . kvp ) : #NEWLINE# #INDENT# if ( maxrecords_cfg > ( - 1 ) ) : #NEWLINE# #INDENT# self . parent . kvp [ 'maxrecords' ] = maxrecords_cfg #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . parent . kvp [ 'maxrecords' ] = 10 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . parent . kvp [ 'maxrecords' ] == '' ) : #NEWLINE# #INDENT# self . parent . kvp [ 'maxrecords' ] = 10 #NEWLINE# #UNINDENT# if ( maxrecords_cfg > ( - 1 ) ) : #NEWLINE# #INDENT# if ( int ( self . parent . kvp [ 'maxrecords' ] ) > maxrecords_cfg ) : #NEWLINE# #INDENT# self . parent . kvp [ 'maxrecords' ] = maxrecords_cfg #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if any ( ( ( x in [ 'bbox' , 'q' , 'time' ] ) for x in self . parent . kvp ) ) : #NEWLINE# #INDENT# LOGGER . debug ( 'OpenSearch Geo/Time parameters detected.' ) #NEWLINE# self . parent . kvp [ 'constraintlanguage' ] = 'FILTER' #NEWLINE# tmp_filter = opensearch . kvp2filterxml ( self . parent . kvp , self . parent . context ) #NEWLINE# if ( tmp_filter is not '' ) : #NEWLINE# #INDENT# self . parent . kvp [ 'constraint' ] = tmp_filter #NEWLINE# LOGGER . debug ( ( 'OpenSearch Geo/Time parameters to Filter: %s.' % self . parent . kvp [ 'constraint' ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( self . parent . requesttype == 'GET' ) : #NEWLINE# #INDENT# if ( 'constraint' in self . parent . kvp ) : #NEWLINE# #INDENT# LOGGER . debug ( 'csw:Constraint passed over HTTP GET.' ) #NEWLINE# if ( 'constraintlanguage' not in self . parent . kvp ) : #NEWLINE# #INDENT# return self . exceptionreport ( 'MissingParameterValue' , 'constraintlanguage' , 'constraintlanguage required when constraint specified' ) #NEWLINE# #UNINDENT# if ( self . parent . kvp [ 'constraintlanguage' ] not in self . parent . context . model [ 'operations' ] [ 'GetRecords' ] [ 'parameters' ] [ 'CONSTRAINTLANGUAGE' ] [ 'values' ] ) : #NEWLINE# #INDENT# return self . exceptionreport ( 'InvalidParameterValue' , 'constraintlanguage' , ( 'Invalid constraintlanguage: %s' % self . parent . kvp [ 'constraintlanguage' ] ) ) #NEWLINE# #UNINDENT# if ( self . parent . kvp [ 'constraintlanguage' ] == 'CQL_TEXT' ) : #NEWLINE# #INDENT# tmp = self . parent . kvp [ 'constraint' ] #NEWLINE# self . parent . kvp [ 'constraint' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# self . parent . kvp [ 'constraint' ] [ 'type' ] = 'cql' #NEWLINE# self . parent . kvp [ 'constraint' ] [ 'where' ] = self . parent . _cql_update_queryables_mappings ( tmp , self . parent . repository . queryables [ '_all' ] ) #NEWLINE# self . parent . kvp [ 'constraint' ] [ 'values' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( plural . parent . kvp [ 'constraintlanguage' ] == 'FILTER' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# schema = os . path . join ( self . parent . config . get ( 'server' , 'home' ) , 'core' , 'schemas' , 'ogc' , 'filter' , '1.1.0' , 'filter.xsd' ) #NEWLINE# LOGGER . debug ( ( 'Validating Filter %s.' % self . parent . kvp [ 'constraint' ] ) ) #NEWLINE# schema = etree . XMLSchema ( file = schema ) #NEWLINE# parser = etree . XMLParser ( schema = schema , resolve_entities = False ) #NEWLINE# doc = etree . fromstring ( self . parent . kvp [ 'constraint' ] , parser ) #NEWLINE# LOGGER . debug ( 'Filter is valid XML.' ) #NEWLINE# self . parent . kvp [ 'constraint' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# self . parent . kvp [ 'constraint' ] [ 'type' ] = 'filter' #NEWLINE# ( self . parent . kvp [ 'constraint' ] [ 'where' ] , self . parent . kvp [ 'constraint' ] [ 'values' ] ) = fes1 . 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 ) #NEWLINE# #UNINDENT# except Exception as err : #NEWLINE# #INDENT# errortext = ( 'Exception: document not valid.\nError: %s.' % str ( err ) ) #NEWLINE# LOGGER . debug ( errortext ) #NEWLINE# return self . exceptionreport ( 'InvalidParameterValue' , 'constraint' , ( 'Invalid Filter query: %s' % errortext ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# self . parent . kvp [ 'constraint' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# if ( 'sortby' not in self . parent . kvp ) : #NEWLINE# #INDENT# self . parent . kvp [ 'sortby' ] = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( 'sortby' in self . parent . kvp ) and ( self . parent . requesttype == 'GET' ) ) : #NEWLINE# #INDENT# LOGGER . debug ( 'Sorted query specified.' ) #NEWLINE# tmp = self . parent . kvp [ 'sortby' ] #NEWLINE# self . parent . kvp [ 'sortby' ] = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# ( name , order ) = tmp . rsplit ( ':' , 1 ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return self . exceptionreport ( 'InvalidParameterValue' , 'sortby' , 'Invalid SortBy value: must be in the format                propertyname:A or propertyname:D' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# self . parent . kvp [ 'sortby' ] [ 'propertyname' ] = self . parent . repository . queryables [ '_all' ] [ name ] [ 'dbcol' ] #NEWLINE# if ( ( name . find ( 'BoundingBox' ) != ( - 1 ) ) or ( name . find ( 'Envelope' ) != ( - 1 ) ) ) : #NEWLINE# #INDENT# self . parent . kvp [ 'sortby' ] [ 'spatial' ] = True #NEWLINE# #UNINDENT# #UNINDENT# except Exception as err : #NEWLINE# #INDENT# return self . exceptionreport ( 'InvalidParameterValue' , 'sortby' , ( 'Invalid SortBy propertyname: %s' % name ) ) #NEWLINE# #UNINDENT# if ( order not in [ 'A' , 'D' ] ) : #NEWLINE# #INDENT# return self . exceptionreport ( 'InvalidParameterValue' , 'sortby' , 'Invalid SortBy value: sort order must be "A" or "D"' ) #NEWLINE# #UNINDENT# if ( order == 'D' ) : #NEWLINE# #INDENT# self . parent . kvp [ 'sortby' ] [ 'order' ] = 'DESC' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . parent . kvp [ 'sortby' ] [ 'order' ] = 'ASC' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( 'startposition' not in self . parent . kvp ) : #NEWLINE# #INDENT# self . parent . kvp [ 'startposition' ] = 1 #NEWLINE# #UNINDENT# LOGGER . debug ( ( 'Querying repository with constraint: %s,        sortby: %s, typenames: %s, maxrecords: %s, startposition: %s.' % ( self . parent . kvp [ 'constraint' ] , self . parent . kvp [ 'sortby' ] , self . parent . kvp [ 'typenames' ] , self . parent . kvp [ 'maxrecords' ] , self . parent . kvp [ 'startposition' ] ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# ( matched , results ) = self . parent . repository . query ( constraint = self . parent . kvp [ 'constraint' ] , sortby = self . parent . kvp [ 'sortby' ] , typenames = self . parent . kvp [ 'typenames' ] , maxrecords = self . parent . kvp [ 'maxrecords' ] , startposition = ( int ( self . parent . kvp [ 'startposition' ] ) - 1 ) ) #NEWLINE# #UNINDENT# except Exception as err : #NEWLINE# #INDENT# return self . exceptionreport ( 'InvalidParameterValue' , 'constraint' , ( 'Invalid query: %s' % err ) ) #NEWLINE# #UNINDENT# dsresults = [ ] #NEWLINE# if ( self . parent . config . has_option ( 'server' , 'federatedcatalogues' ) and ( 'distributedsearch' in self . parent . kvp ) and self . parent . kvp [ 'distributedsearch' ] and ( self . parent . kvp [ 'hopcount' ] > 0 ) ) : #NEWLINE# #INDENT# LOGGER . debug ( ( 'DistributedSearch specified (hopCount: %s).' % self . parent . kvp [ 'hopcount' ] ) ) #NEWLINE# from owslib.csw import CatalogueServiceWeb #NEWLINE# from owslib.ows import ExceptionReport #NEWLINE# for fedcat in self . parent . config . get ( 'server' , 'federatedcatalogues' ) . split ( ',' ) : #NEWLINE# #INDENT# LOGGER . debug ( ( 'Performing distributed search on federated                 catalogue: %s.' % fedcat ) ) #NEWLINE# remotecsw = CatalogueServiceWeb ( fedcat , skip_caps = True ) #NEWLINE# try : #NEWLINE# #INDENT# remotecsw . getrecords2 ( xml = self . parent . request , esn = self . parent . kvp [ 'elementsetname' ] , outputschema = self . parent . kvp [ 'outputschema' ] ) #NEWLINE# if hasattr ( remotecsw , 'results' ) : #NEWLINE# #INDENT# LOGGER . debug ( ( 'Distributed search results from catalogue                         %s: %s.' % ( fedcat , remotecsw . results ) ) ) #NEWLINE# remotecsw_matches = int ( remotecsw . results [ 'matches' ] ) #NEWLINE# plural = ( 's' if ( remotecsw_matches != 1 ) else '' ) #NEWLINE# if ( remotecsw_matches > 0 ) : #NEWLINE# #INDENT# matched = str ( ( int ( matched ) + remotecsw_matches ) ) #NEWLINE# dsresults . append ( etree . Comment ( ( ' %d result%s from %s ' % ( remotecsw_matches , plural , fedcat ) ) ) ) #NEWLINE# dsresults . append ( remotecsw . records ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except ExceptionReport as err : #NEWLINE# #INDENT# error_string = ( 'remote CSW %s returned exception: ' % fedcat ) #NEWLINE# dsresults . append ( etree . Comment ( ( ' %s\n\n%s ' % ( error_string , err ) ) ) ) #NEWLINE# LOGGER . debug ( str ( err ) ) #NEWLINE# #UNINDENT# except Exception as err : #NEWLINE# #INDENT# error_string = ( 'remote CSW %s returned error: ' % fedcat ) #NEWLINE# dsresults . append ( etree . Comment ( ( ' %s\n\n%s ' % ( error_string , err ) ) ) ) #NEWLINE# LOGGER . debug ( str ( err ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( int ( matched ) == 0 ) : #NEWLINE# #INDENT# returned = nextrecord = '0' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( int ( matched ) < int ( self . parent . kvp [ 'maxrecords' ] ) ) : #NEWLINE# #INDENT# returned = matched #NEWLINE# nextrecord = '0' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# returned = str ( self . parent . kvp [ 'maxrecords' ] ) #NEWLINE# if ( ( int ( self . parent . kvp [ 'startposition' ] ) + int ( self . parent . kvp [ 'maxrecords' ] ) ) >= int ( matched ) ) : #NEWLINE# #INDENT# nextrecord = '0' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# nextrecord = str ( ( int ( self . parent . kvp [ 'startposition' ] ) + int ( self . parent . kvp [ 'maxrecords' ] ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# LOGGER . debug ( ( 'Results: matched: %s, returned: %s, next: %s.' % ( matched , returned , nextrecord ) ) ) #NEWLINE# node = etree . Element ( util . nspath_eval ( 'csw:GetRecordsResponse' , self . parent . context . namespaces ) , nsmap = self . parent . context . namespaces , version = '2.0.2' ) #NEWLINE# node . attrib [ util . nspath_eval ( 'xsi:schemaLocation' , self . parent . context . namespaces ) ] = ( '%s %s/csw/2.0.2/CSW-discovery.xsd' % ( self . parent . context . namespaces [ 'csw' ] , self . parent . config . get ( 'server' , 'ogc_schemas_base' ) ) ) #NEWLINE# if ( ( 'requestid' in self . parent . kvp ) and ( self . parent . kvp [ 'requestid' ] is not None ) ) : #NEWLINE# #INDENT# etree . SubElement ( node , util . nspath_eval ( 'csw:RequestId' , self . parent . context . namespaces ) ) . text = self . parent . kvp [ 'requestid' ] #NEWLINE# #UNINDENT# etree . SubElement ( node , util . nspath_eval ( 'csw:SearchStatus' , self . parent . context . namespaces ) , timestamp = timestamp ) #NEWLINE# if ( ( 'where' not in self . parent . kvp [ 'constraint' ] ) and ( self . parent . kvp [ 'resulttype' ] is None ) ) : #NEWLINE# #INDENT# returned = '0' #NEWLINE# #UNINDENT# searchresults = etree . SubElement ( node , util . nspath_eval ( 'csw:SearchResults' , self . parent . context . namespaces ) , numberOfRecordsMatched = matched , numberOfRecordsReturned = returned , nextRecord = nextrecord , recordSchema = self . parent . kvp [ 'outputschema' ] ) #NEWLINE# if ( self . parent . kvp [ 'elementsetname' ] is not None ) : #NEWLINE# #INDENT# searchresults . attrib [ 'elementSet' ] = self . parent . kvp [ 'elementsetname' ] #NEWLINE# #UNINDENT# if ( ( 'where' not in self . parent . kvp [ 'constraint' ] ) and ( self . parent . kvp [ 'resulttype' ] is None ) ) : #NEWLINE# #INDENT# LOGGER . debug ( 'Empty result set returned.' ) #NEWLINE# return node #NEWLINE# #UNINDENT# if ( self . parent . kvp [ 'resulttype' ] == 'hits' ) : #NEWLINE# #INDENT# return node #NEWLINE# #UNINDENT# if ( results is not None ) : #NEWLINE# #INDENT# if ( len ( results ) < int ( self . parent . kvp [ 'maxrecords' ] ) ) : #NEWLINE# #INDENT# max1 = len ( results ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# max1 = ( int ( self . parent . kvp [ 'startposition' ] ) + ( int ( self . parent . kvp [ 'maxrecords' ] ) - 1 ) ) #NEWLINE# #UNINDENT# LOGGER . debug ( ( 'Presenting records %s - %s.' % ( self . parent . kvp [ 'startposition' ] , max1 ) ) ) #NEWLINE# for res in results : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( ( self . parent . kvp [ 'outputschema' ] == 'http://www.opengis.net/cat/csw/2.0.2' ) and ( 'csw:Record' in self . parent . kvp [ 'typenames' ] ) ) : #NEWLINE# #INDENT# searchresults . append ( self . _write_record ( res , self . parent . repository . queryables [ '_all' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( self . parent . kvp [ 'outputschema' ] == 'http://www.opengis.net/cat/csw/2.0.2' ) and ( 'csw:Record' not in self . parent . kvp [ 'typenames' ] ) ) : #NEWLINE# #INDENT# for prof in self . parent . profiles [ 'loaded' ] : #NEWLINE# #INDENT# if ( self . parent . profiles [ 'loaded' ] [ prof ] . typename in self . parent . kvp [ 'typenames' ] ) : #NEWLINE# #INDENT# typename = self . parent . profiles [ 'loaded' ] [ prof ] . typename #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# util . transform_mappings ( self . parent . repository . queryables [ '_all' ] , self . parent . context . model [ 'typenames' ] [ typename ] [ 'mappings' ] [ 'csw:Record' ] , reverse = True ) #NEWLINE# searchresults . append ( self . _write_record ( res , self . parent . repository . queryables [ '_all' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . parent . kvp [ 'outputschema' ] in self . parent . outputschemas . keys ( ) ) : #NEWLINE# #INDENT# searchresults . append ( self . parent . outputschemas [ self . parent . kvp [ 'outputschema' ] ] . write_record ( res , self . parent . kvp [ 'elementsetname' ] , self . parent . context , self . parent . config . get ( 'server' , 'url' ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# searchresults . append ( self . parent . profiles [ 'loaded' ] [ self . parent . kvp [ 'outputschema' ] ] . write_record ( res , self . parent . kvp [ 'elementsetname' ] , self . parent . kvp [ 'outputschema' ] , self . parent . repository . queryables [ '_all' ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except Exception as err : #NEWLINE# #INDENT# self . parent . response = self . exceptionreport ( 'NoApplicableCode' , 'service' , ( 'Record serialization failed: %s' % str ( err ) ) ) #NEWLINE# return self . parent . response #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( len ( dsresults ) > 0 ) : #NEWLINE# #INDENT# for resultset in dsresults : #NEWLINE# #INDENT# if isinstance ( resultset , etree . _Comment ) : #NEWLINE# #INDENT# searchresults . append ( resultset ) #NEWLINE# #UNINDENT# for rec in resultset : #NEWLINE# #INDENT# searchresults . append ( etree . fromstring ( resultset [ rec ] . xml , self . parent . context . parser ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( 'responsehandler' in self . parent . kvp ) : #NEWLINE# #INDENT# self . parent . _process_responsehandler ( etree . tostring ( node , pretty_print = self . parent . pretty_print ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return node