def __init__(self, md): val = md.find(util.nspath('File', namespaces['dif'])) self.file = util.testXMLValue(val) val = md.find(util.nspath('URL', namespaces['dif'])) self.url = util.testXMLValue(val) val = md.find(util.nspath('Format', namespaces['dif'])) self.format = util.testXMLValue(val) val = md.find(util.nspath('Caption', namespaces['dif'])) self.caption = util.testXMLValue(val) val = md.find(util.nspath('Description', namespaces['dif'])) self.description = util.testXMLValue(val) val = md.find(util.nspath('Visualization_URL', namespaces['dif'])) self.vis_url = util.testXMLValue(val) val = md.find(util.nspath('Visualization_Type', namespaces['dif'])) self.vis_type = util.testXMLValue(val) val = md.find(util.nspath('Visualization_Subtype', namespaces['dif'])) self.vis_subtype = util.testXMLValue(val) val = md.find(util.nspath('Visualization_Duration', namespaces['dif'])) self.vis_duration = util.testXMLValue(val) val = md.find(util.nspath('Visualization_File_Size', namespaces['dif'])) self.file_size = util.testXMLValue(val)
def __init__(self, elem, namespace=DEFAULT_OWS_NAMESPACE): self.minx = None self.miny = None self.maxx = None self.maxy = None val = elem.attrib.get('crs') self.crs = util.testXMLValue(val, True) val = elem.attrib.get('dimensions') self.dimensions = util.testXMLValue(val, True) val = elem.find(util.nspath('LowerCorner', namespace)) tmp = util.testXMLValue(val) if tmp is not None: xy = tmp.split() if len(xy) > 1: self.minx, self.miny = xy[0], xy[1] val = elem.find(util.nspath('UpperCorner', namespace)) tmp = util.testXMLValue(val) if tmp is not None: xy = tmp.split() if len(xy) > 1: self.maxx, self.maxy = xy[0], xy[1]
def _setconstraint(self, parent, qtype=None, propertyname='AnyText', keywords=[], bbox=None, cql=None): #if keywords or bbox is not None or qtype is not None or cql is not None: if keywords or bbox is not None or qtype is not None or cql is not None: node0 = etree.SubElement( parent, util.nspath('Constraint', namespaces['csw'])) node0.set('version', '1.1.0') if cql is not None: # send raw CQL query import warnings warnings.warn('CQL passed (overrides all other parameters', UserWarning) node1 = etree.SubElement( node0, util.nspath('CqlText', namespaces['csw'])) node1.text = cql else: # construct a Filter request flt = FilterRequest() node0.append( flt.set(qtype=qtype, keywords=keywords, propertyname=propertyname, bbox=bbox))
def describerecord(self, typename='csw:Record', format=outputformat): """ Construct and process DescribeRecord request Parameters ---------- - typename: the typename to describe (default is 'csw:Record') - format: the outputFormat (default is 'application/xml') """ # construct request node0 = etree.Element(util.nspath('DescribeRecord', namespaces['csw'])) node0.set('service', self.service) node0.set('version', self.version) node0.set('outputFormat', format) node0.set('schemaLanguage', namespaces['xs2']) node0.set(util.nspath('schemaLocation', namespaces['xsi']), schema_location) etree.SubElement(node0, util.nspath('TypeName', namespaces['csw'])).text = typename self.request = util.xml2string(etree.tostring(node0)) self._invoke()
def getrecordbyid(self, id=[], esn="full", outputschema=namespaces["csw"], format=outputformat): """ Construct and process a GetRecordById request Parameters ---------- - id: the list of Ids - esn: the ElementSetName 'full', 'brief' or 'summary' (default is 'full') - outputschema: the outputSchema (default is 'http://www.opengis.net/cat/csw/2.0.2') - format: the outputFormat (default is 'application/xml') """ # construct request node0 = etree.Element(util.nspath("GetRecordById", namespaces["csw"])) node0.set("outputSchema", outputschema) node0.set("outputFormat", format) node0.set("version", self.version) node0.set("service", self.service) node0.set(util.nspath("schemaLocation", namespaces["xsi"]), schema_location) for i in id: etree.SubElement(node0, util.nspath("Id", namespaces["csw"])).text = i etree.SubElement(node0, util.nspath("ElementSetName", namespaces["csw"])).text = esn self.request = util.xml2string(etree.tostring(node0)) self._invoke() if self.exceptionreport is None: self.results = {} self.records = {} self._parserecords(outputschema, esn)
def describerecord(self, typename='csw:Record', format=outputformat): """ Construct and process DescribeRecord request Parameters ---------- - typename: the typename to describe (default is 'csw:Record') - format: the outputFormat (default is 'application/xml') """ # construct request node0 = etree.Element(util.nspath('DescribeRecord', namespaces['csw'])) node0.set('service', self.service) node0.set('version', self.version) node0.set('outputFormat', format) node0.set('schemaLanguage', namespaces['xs2']) node0.set(util.nspath('schemaLocation', namespaces['xsi']), schema_location) etree.SubElement(node0, util.nspath('TypeName', namespaces['csw'])).text = typename self.request = util.xml2string(etree.tostring(node0)) # invoke self.response = util.http_post(self.url, self.request, self.lang)
def setfilter(self, parent=None): if parent is None: tmp = etree.Element(util.nspath('Filter', namespaces['ogc'])) tmp.set(util.nspath('schemaLocation', namespaces['xsi']), schema_location) return tmp else: etree.SubElement(parent, util.nspath('Filter', namespaces['ogc']))
def _parseinsertresult(self): self.results["inserted"] = [] for i in self._exml.findall(util.nspath("InsertResult", namespaces["csw"])): for j in i.findall( util.nspath("BriefRecord", namespaces["csw"]) + "/" + util.nspath("identifier", namespaces["dc"]) ): self.results["inserted"].append(util.testXMLValue(j))
def __init__(self,elem,namespace=DEFAULT_OWS_NAMESPACE): self.name = elem.attrib['name'] self.formatOptions = ['text/xml'] methods = [] for verb in elem.findall(util.nspath('DCP/HTTP/*', namespace)): methods.append((verb.tag, {'url': verb.attrib[util.nspath('href', XLINK_NAMESPACE)]})) self.methods = dict(methods)
def _getStoredQueries(self, timeout=None): ''' gets descriptions of the stored queries available on the server ''' if timeout: to = timeout else: to = self.timeout sqs=[] #This method makes two calls to the WFS - one ListStoredQueries, and one DescribeStoredQueries. The information is then #aggregated in 'StoredQuery' objects method=nspath('Get') #first make the ListStoredQueries response and save the results in a dictionary if form {storedqueryid:(title, returnfeaturetype)} try: base_url = next((m.get('url') for m in self.getOperationByName('ListStoredQueries').methods if m.get('type').lower() == method.lower())) except StopIteration: base_url = self.url request = {'service': 'WFS', 'version': self.version, 'request': 'ListStoredQueries'} encoded_request = urlencode(request) u = urlopen(base_url, data=encoded_request, timeout=to) tree=etree.fromstring(u.read()) tempdict={} for sqelem in tree[:]: title=rft=id=None id=sqelem.get('id') for elem in sqelem[:]: if elem.tag==nspath('Title', WFS_NAMESPACE): title=elem.text elif elem.tag==nspath('ReturnFeatureType', WFS_NAMESPACE): rft=elem.text tempdict[id]=(title,rft) #store in temporary dictionary #then make the DescribeStoredQueries request and get the rest of the information about the stored queries try: base_url = next((m.get('url') for m in self.getOperationByName('DescribeStoredQueries').methods if m.get('type').lower() == method.lower())) except StopIteration: base_url = self.url request = {'service': 'WFS', 'version': self.version, 'request': 'DescribeStoredQueries'} encoded_request = urlencode(request) u = urlopen(base_url, data=encoded_request, timeout=to) tree=etree.fromstring(u.read()) tempdict2={} for sqelem in tree[:]: params=[] #list to store parameters for the stored query description id =sqelem.get('id') for elem in sqelem[:]: if elem.tag==nspath('Abstract', WFS_NAMESPACE): abstract=elem.text elif elem.tag==nspath('Parameter', WFS_NAMESPACE): newparam=Parameter(elem.get('name'), elem.get('type')) params.append(newparam) tempdict2[id]=(abstract, params) #store in another temporary dictionary #now group the results into StoredQuery objects: for key in tempdict.keys(): abstract='blah' parameters=[] sqs.append(StoredQuery(key, tempdict[key][0], tempdict[key][1], tempdict2[key][0], tempdict2[key][1])) return sqs
def __init__(self, elem): self.name = elem.get('name') self.formatOptions = [f.text for f in elem.findall(nspath('Parameter/AllowedValues/Value'))] methods = [] for verb in elem.findall(nspath('DCP/HTTP/*')): url = verb.attrib['{http://www.w3.org/1999/xlink}href'] methods.append((verb.tag, {'url': url})) self.methods = dict(methods)
def _parseinsertresult(self): self.results['inserted'] = [] for i in self._exml.findall( util.nspath('InsertResult', namespaces['csw'])): for j in i.findall( util.nspath('BriefRecord', namespaces['csw']) + '/' + util.nspath('identifier', namespaces['dc'])): self.results['inserted'].append(util.testXMLValue(j))
def __init__(self, elem): """.""" self.name = xmltag_split(elem.tag) # formatOptions self.formatOptions = [f.text for f in elem.findall(nspath('Format', WMS_NAMESPACE))] self.methods = [] for verb in elem.findall(nspath('DCPType/HTTP/*', WMS_NAMESPACE)): url = verb.find(nspath('OnlineResource', WMS_NAMESPACE)).attrib['{http://www.w3.org/1999/xlink}href'] self.methods.append({'type': xmltag_split(verb.tag), 'url': url})
def __init__(self, md): val = md.find(util.nspath('geographicElement/EX_GeographicBoundingBox/westBoundLongitude', namespaces['gmd']) + '/' + util.nspath('Decimal', namespaces['gco'])) self.minx = util.testXMLValue(val) val = md.find(util.nspath('geographicElement/EX_GeographicBoundingBox/eastBoundLongitude', namespaces['gmd']) + '/' + util.nspath('Decimal', namespaces['gco'])) self.maxx = util.testXMLValue(val) val = md.find(util.nspath('geographicElement/EX_GeographicBoundingBox/southBoundLatitude', namespaces['gmd']) + '/' + util.nspath('Decimal', namespaces['gco'])) self.miny = util.testXMLValue(val) val = md.find(util.nspath('geographicElement/EX_GeographicBoundingBox/northBoundLatitude', namespaces['gmd']) + '/' + util.nspath('Decimal', namespaces['gco'])) self.maxy = util.testXMLValue(val)
def __init__(self, md): val = md.find(util.nspath('Discipline_Name', namespaces['dif'])) self.name = util.testXMLValue(val) val = md.find(util.nspath('Subdiscipline', namespaces['dif'])) self.subdiscipline = util.testXMLValue(val) val = md.find(util.nspath('Detailed_Subdiscipline', namespaces['dif'])) self.detailed_subdiscipline = util.testXMLValue(val)
def __init__(self, elem, namespace=DEFAULT_OWS_NAMESPACE): self.name = elem.attrib.get('name') self.values = [ i.text for i in elem.findall(util.nspath('Value', namespace)) ] self.values += [ i.text for i in elem.findall( util.nspath('AllowedValues/Value', namespace)) ]
def _getStoredQueries(self): ''' gets descriptions of the stored queries available on the server ''' sqs=[] #This method makes two calls to the WFS - one ListStoredQueries, and one DescribeStoredQueries. The information is then #aggregated in 'StoredQuery' objects method=nspath('Get') #first make the ListStoredQueries response and save the results in a dictionary if form {storedqueryid:(title, returnfeaturetype)} try: base_url = next((m.get('url') for m in self.getOperationByName('ListStoredQueries').methods if m.get('type').lower() == method.lower())) except StopIteration: base_url = self.url request = {'service': 'WFS', 'version': self.version, 'request': 'ListStoredQueries'} encoded_request = urlencode(request) u = openURL(base_url, data=encoded_request, timeout=self.timeout, username=self.username, password=self.password) tree=etree.fromstring(u.read()) tempdict={} for sqelem in tree[:]: title=rft=id=None id=sqelem.get('id') for elem in sqelem[:]: if elem.tag==nspath('Title', WFS_NAMESPACE): title=elem.text elif elem.tag==nspath('ReturnFeatureType', WFS_NAMESPACE): rft=elem.text tempdict[id]=(title,rft) #store in temporary dictionary #then make the DescribeStoredQueries request and get the rest of the information about the stored queries try: base_url = next((m.get('url') for m in self.getOperationByName('DescribeStoredQueries').methods if m.get('type').lower() == method.lower())) except StopIteration: base_url = self.url request = {'service': 'WFS', 'version': self.version, 'request': 'DescribeStoredQueries'} encoded_request = urlencode(request) u = openURL(base_url, data=encoded_request, timeout=self.timeout, username=self.username, password=self.password) tree=etree.fromstring(u.read()) tempdict2={} for sqelem in tree[:]: params=[] #list to store parameters for the stored query description id =sqelem.get('id') for elem in sqelem[:]: abstract = '' if elem.tag==nspath('Abstract', WFS_NAMESPACE): abstract=elem.text elif elem.tag==nspath('Parameter', WFS_NAMESPACE): newparam=Parameter(elem.get('name'), elem.get('type')) params.append(newparam) tempdict2[id]=(abstract, params) #store in another temporary dictionary #now group the results into StoredQuery objects: for key in tempdict.keys(): sqs.append(StoredQuery(key, tempdict[key][0], tempdict[key][1], tempdict2[key][0], tempdict2[key][1])) return sqs
def create_storedquery(self, stored_id, parameters): """Create the storedQuery tag and configure it's sub elements and attributes.""" storedquery = etree.SubElement( self._root, util.nspath('StoredQuery', self._wfsnamespace)) storedquery.set("id", str(stored_id)) for param in parameters: p = etree.SubElement(storedquery, util.nspath('Parameter', self._wfsnamespace)) p.set("name", param) p.text = parameters[param]
def __init__(self, md): self.content_type = [] for el in md.findall(util.nspath('URL_Content_Type', namespaces['dif'])): self.content_type.append(URL_Content_Type(el)) val = md.find(util.nspath('URL', namespaces['dif'])) self.url = util.testXMLValue(val) val = md.find(util.nspath('Description', namespaces['dif'])) self.description = util.testXMLValue(val)
def set_sortby(self, sortby): """Set the properties by which the response will be sorted.""" sort_tree = etree.SubElement(self._query, util.nspath("SortBy", FES_NAMESPACE)) for s in sortby: prop_elem = etree.SubElement( sort_tree, util.nspath("SortProperty", FES_NAMESPACE)) value = etree.SubElement( prop_elem, util.nspath('ValueReference', FES_NAMESPACE)) value.text = s
def test_featureid_query_single(self, requestv200): requestv200.set_featureid(["1"]) filter_elem = requestv200._query.find( util.nspath("Filter", FES_NAMESPACE)) resource_elem = filter_elem.find( util.nspath("ResourceId", FES_NAMESPACE)) assert filter_elem is not None assert resource_elem.get("rid") == "1"
def __init__(self, md): val = md.find(util.nspath('Paleo_Start_Date', namespaces['dif'])) self.paleo_start_date = util.testXMLValue(val) val = md.find(util.nspath('Paleo_End_Date', namespaces['dif'])) self.paleo_end_date = util.testXMLValue(val) self.chronostratigraphic_unit = [] for el in md.findall(util.nspath('Chronostratigraphic_Unit', namespaces['dif'])): self.chronostratigraphic_unit.append(Chronostratigraphic_Unit(el))
def __init__(self, elem, namespace=DEFAULT_OWS_NAMESPACE): self.name = elem.attrib['name'] self.formatOptions = ['text/xml'] methods = [] for verb in elem.findall(util.nspath('DCP/HTTP/*', namespace)): methods.append((verb.tag, { 'url': verb.attrib[util.nspath('href', XLINK_NAMESPACE)] })) self.methods = dict(methods)
def test_featureid_query_single(self, requestv110): requestv110.set_featureid(["1"]) filter_elem = requestv110._query.find( util.nspath("Filter", OGC_NAMESPACE)) resource_elem = filter_elem.find( util.nspath("GmlObjectId", OGC_NAMESPACE)) assert filter_elem is not None assert resource_elem.get(util.nspath('id', GML_NAMESPACE)) == '1'
def set_sortby(self, sortby): """Set the properties by which the response will be sorted.""" sort_tree = etree.SubElement(self._query, util.nspath("SortBy", OGC_NAMESPACE)) for s in sortby: prop_elem = etree.SubElement( sort_tree, util.nspath("SortProperty", OGC_NAMESPACE)) prop_name = etree.SubElement( prop_elem, util.nspath('PropertyName', OGC_NAMESPACE)) prop_name.text = s
def __init__(self, infoset, namespace=DEFAULT_OWS_NAMESPACE): self._root = infoset val = self._root.find(util.nspath("Title", namespace)) self.title = util.testXMLValue(val) val = self._root.find(util.nspath("Abstract", namespace)) self.abstract = util.testXMLValue(val) self.keywords = [] for f in self._root.findall(util.nspath("Keywords/Keyword", namespace)): if f.text is not None: self.keywords.append(f.text) val = self._root.find(util.nspath("AccessConstraints", namespace)) self.accessconstraints = util.testXMLValue(val) val = self._root.find(util.nspath("Fees", namespace)) self.fees = util.testXMLValue(val) val = self._root.find(util.nspath("ServiceType", namespace)) self.type = util.testXMLValue(val) self.service = self.type # alternative? keep both?discuss val = self._root.find(util.nspath("ServiceTypeVersion", namespace)) self.version = util.testXMLValue(val) self.versions = [] for v in self._root.findall(util.nspath("ServiceTypeVersion", namespace)): self.versions.append(util.testXMLValue(v)) self.profiles = [] for p in self._root.findall(util.nspath("Profile", namespace)): self.profiles.append(util.testXMLValue(p))
def _invoke(self): # do HTTP request self.response = util.http_post(self.url, self.request, self.lang, self.timeout) # parse result see if it's XML self._exml = etree.parse(StringIO.StringIO(self.response)) # it's XML. Attempt to decipher whether the XML response is CSW-ish """ valid_xpaths = [ util.nspath('ExceptionReport', namespaces['ows']), util.nspath('Capabilities', namespaces['csw']), util.nspath('DescribeRecordResponse', namespaces['csw']), util.nspath('GetDomainResponse', namespaces['csw']), util.nspath('GetRecordsResponse', namespaces['csw']), util.nspath('GetRecordByIdResponse', namespaces['csw']), util.nspath('HarvestResponse', namespaces['csw']), util.nspath('TransactionResponse', namespaces['csw']) ] if self._exml.getroot().tag not in valid_xpaths: raise RuntimeError, 'Document is XML, but not CSW-ish' # check if it's an OGC Exception val = self._exml.find(util.nspath('Exception', namespaces['ows'])) if val is not None: self.exceptionreport = ExceptionReport(self._exml, self.owscommon.namespace) else: self.exceptionreport = None
def _invoke(self): # do HTTP request self.response = util.http_post(self.url, self.request, self.lang, self.timeout) # parse result see if it's XML self._exml = etree.parse(StringIO.StringIO(self.response)) # it's XML. Attempt to decipher whether the XML response is CSW-ish """ valid_xpaths = [ util.nspath("ExceptionReport", namespaces["ows"]), util.nspath("Capabilities", namespaces["csw"]), util.nspath("DescribeRecordResponse", namespaces["csw"]), util.nspath("GetDomainResponse", namespaces["csw"]), util.nspath("GetRecordsResponse", namespaces["csw"]), util.nspath("GetRecordByIdResponse", namespaces["csw"]), util.nspath("HarvestResponse", namespaces["csw"]), util.nspath("TransactionResponse", namespaces["csw"]), ] if self._exml.getroot().tag not in valid_xpaths: raise RuntimeError, "Document is XML, but not CSW-ish" # check if it's an OGC Exception val = self._exml.find(util.nspath("Exception", namespaces["ows"])) if val is not None: self.exceptionreport = ExceptionReport(self._exml, self.owscommon.namespace) else: self.exceptionreport = None
def __init__(self, infoset, namespace=DEFAULT_OWS_NAMESPACE): self._root = infoset val = self._root.find(util.nspath('Title', namespace)) self.title = util.testXMLValue(val) val = self._root.find(util.nspath('Abstract', namespace)) self.abstract = util.testXMLValue(val) self.keywords = [] for f in self._root.findall(util.nspath('Keywords/Keyword', namespace)): if f.text is not None: self.keywords.append(f.text) val = self._root.find(util.nspath('AccessConstraints', namespace)) self.accessconstraints = util.testXMLValue(val) val = self._root.find(util.nspath('Fees', namespace)) self.fees = util.testXMLValue(val) val = self._root.find(util.nspath('ServiceType', namespace)) self.type = util.testXMLValue(val) self.service = self.type # alternative? keep both?discuss val = self._root.find(util.nspath('ServiceTypeVersion', namespace)) self.version = util.testXMLValue(val) self.versions = [] for v in self._root.findall(util.nspath('ServiceTypeVersion', namespace)): self.versions.append(util.testXMLValue(v)) self.profiles = [] for p in self._root.findall(util.nspath('Profile', namespace)): self.profiles.append(util.testXMLValue(p))
def __init__(self, url, lang='en-US', version='2.0.2'): """ Construct and process a GetCapabilities request Parameters ---------- - url: the URL of the CSW - lang: the language (default is 'en-US') - version: version (default is '2.0.2') """ self.url = url self.lang = lang self.version = version self.service = 'CSW' self.exceptionreport = None self.owscommon = OwsCommon('1.0.0') # construct request node0 = etree.Element(util.nspath('GetCapabilities', namespaces['csw'])) node0.set('service', self.service) node0.set(util.nspath('schemaLocation', namespaces['xsi']), schema_location) tmp = etree.SubElement(node0, util.nspath('AcceptVersions', namespaces['ows'])) etree.SubElement(tmp, util.nspath('Version', namespaces['ows'])).text = self.version tmp2 = etree.SubElement(node0, util.nspath('AcceptFormats', namespaces['ows'])) etree.SubElement(tmp2, util.nspath('OutputFormat', namespaces['ows'])).text = outputformat self.request = util.xml2string(etree.tostring(node0)) # invoke self.response = util.http_post(self.url, self.request, self.lang) # parse result self._capabilities = etree.parse(StringIO.StringIO(self.response)) # check for exceptions self._isexception(self._capabilities, self.owscommon.namespace) if self.exceptionreport is None: # ServiceIdentification val = self._capabilities.find(util.nspath('ServiceIdentification', namespaces['ows'])) self.identification=ServiceIdentification(val,self.owscommon.namespace) # ServiceProvider val = self._capabilities.find(util.nspath('ServiceProvider', namespaces['ows'])) self.provider=ServiceProvider(val,self.owscommon.namespace) # ServiceOperations metadata self.operations=[] for elem in self._capabilities.findall(util.nspath('OperationsMetadata/Operation', namespaces['ows'])): self.operations.append(OperationsMetadata(elem, self.owscommon.namespace)) # FilterCapabilities val = self._capabilities.find(util.nspath('Filter_Capabilities', namespaces['ogc'])) self.filters=FilterCapabilities(val)
def _parsetransactionsummary(self): val = self._response.find(util.nspath('TransactionResponse/TransactionSummary', namespaces['csw'])) if val is not None: id = val.attrib.get('requestId') self.results['requestid'] = util.testXMLValue(id, True) ts = val.find(util.nspath('totalInserted', namespaces['csw'])) self.results['inserted'] = util.testXMLValue(ts) ts = val.find(util.nspath('totalUpdated', namespaces['csw'])) self.results['updated'] = util.testXMLValue(ts) ts = val.find(util.nspath('totalDeleted', namespaces['csw'])) self.results['deleted'] = util.testXMLValue(ts)
def __init__(self, md): val = md.find(util.nspath('Paleo_Start_Date', namespaces['dif'])) self.paleo_start_date = util.testXMLValue(val) val = md.find(util.nspath('Paleo_End_Date', namespaces['dif'])) self.paleo_end_date = util.testXMLValue(val) self.chronostratigraphic_unit = [] for el in md.findall( util.nspath('Chronostratigraphic_Unit', namespaces['dif'])): self.chronostratigraphic_unit.append(Chronostratigraphic_Unit(el))
def __init__(self, elem, namespace=DEFAULT_OWS_NAMESPACE): self.exceptions = [] for i in elem.findall(util.nspath('Exception', namespace)): tmp = {} val = i.attrib.get('exceptionCode') tmp['exceptionCode'] = util.testXMLValue(val, True) val = i.attrib.get('locator') tmp['locator'] = util.testXMLValue(val, True) val = i.find(util.nspath('ExceptionText', namespace)) tmp['ExceptionText'] = util.testXMLValue(val) self.exceptions.append(tmp)
def _parserecords(self, outputschema, esn): if outputschema == namespaces['che']: for i in self._exml.findall('//'+util.nspath('CHE_MD_Metadata', namespaces['che'])): # noqa val = i.find(util.nspath('fileIdentifier', namespaces['gmd']) + '/' + util.nspath('CharacterString', namespaces['gco'])) # noqa identifier = self._setidentifierkey(util.testXMLValue(val)) self.records[identifier] = iso.MD_Metadata(i) self.xml_elem[identifier] = i else: super( GeocatCatalogueServiceWeb, self )._parserecords(outputschema, esn)
def _parsetransactionsummary(self): val = self._exml.find(util.nspath("TransactionSummary", namespaces["csw"])) if val is not None: id = val.attrib.get("requestId") self.results["requestid"] = util.testXMLValue(id, True) ts = val.find(util.nspath("totalInserted", namespaces["csw"])) self.results["inserted"] = util.testXMLValue(ts) ts = val.find(util.nspath("totalUpdated", namespaces["csw"])) self.results["updated"] = util.testXMLValue(ts) ts = val.find(util.nspath("totalDeleted", namespaces["csw"])) self.results["deleted"] = util.testXMLValue(ts)
def __init__(self, infoset, namespace=DEFAULT_OWS_NAMESPACE): self._root = infoset val = self._root.find(util.nspath('ProviderName', namespace)) self.name = util.testXMLValue(val) self.contact = ServiceContact(infoset, namespace) val = self._root.find(util.nspath('ProviderSite', namespace)) if val is not None: urlattrib = val.attrib[util.nspath('href', XLINK_NAMESPACE)] self.url = util.testXMLValue(urlattrib, True) else: self.url = None
def __init__(self, md): val = md.find(util.nspath('distributionFormat/MD_Format/name', namespaces['gmd']) + '/' + util.nspath('CharacterString', namespaces['gco'])) self.format = util.testXMLValue(val) val = md.find(util.nspath('distributionFormat/MD_Format/version', namespaces['gmd']) + '/' + util.nspath('CharacterString', namespaces['gco'])) self.version = util.testXMLValue(val) self.online = [] for ol in md.findall(util.nspath('transferOptions/MD_DigitalTransferOptions/onLine/CI_OnlineResource', namespaces['gmd'])): self.online.append(CI_OnlineResource(ol))
def __init__(self, infoset, namespace=DEFAULT_OWS_NAMESPACE): self._root = infoset val = self._root.find(util.nspath("ProviderName", namespace)) self.name = util.testXMLValue(val) self.contact = ServiceContact(infoset, namespace) val = self._root.find(util.nspath("ProviderSite", namespace)) if val is not None: urlattrib = val.attrib[util.nspath("href", XLINK_NAMESPACE)] self.url = util.testXMLValue(urlattrib, True) else: self.url = None
def set_featureid(self, featureid): """Set filter by feature id. Cannot be used with set_bbox() or set_filter(). """ feature_tree = etree.SubElement(self._query, util.nspath('Filter', FES_NAMESPACE)) for ft in featureid: prop_id = etree.Element(util.nspath('ResourceId', FES_NAMESPACE)) prop_id.set('rid', ft) feature_tree.append(prop_id)
def __init__(self, md): val = md.find(util.nspath('Data_Center_Name', namespaces['dif'])) self.name = util.testXMLValue(val) val = md.find(util.nspath('Data_Center_URL', namespaces['dif'])) self.url = util.testXMLValue(val) val = md.find(util.nspath('Data_Set_ID', namespaces['dif'])) self.data_set_id = util.testXMLValue(val) val = md.find(util.nspath('Personnel', namespaces['dif'])) self.personnel = util.testXMLValue(val)
def set_featureid(self, featureid): """Set filter by feature id. Cannot be used with set_bbox() or set_filter(). """ feature_tree = etree.SubElement(self._query, util.nspath('Filter', OGC_NAMESPACE)) for ft in featureid: prop_id = etree.Element(util.nspath('GmlObjectId', OGC_NAMESPACE)) prop_id.set(util.nspath('id', GML_NAMESPACE), ft) feature_tree.append(prop_id)
def __init__(self, md): val = md.find(util.nspath('Distribution_Media', namespaces['dif'])) self.media = util.testXMLValue(val) val = md.find(util.nspath('Distribution_Size', namespaces['dif'])) self.size = util.testXMLValue(val) val = md.find(util.nspath('Distribution_Format', namespaces['dif'])) self.format = util.testXMLValue(val) val = md.find(util.nspath('Fees', namespaces['dif'])) self.fees = util.testXMLValue(val)
def _parsetransactionsummary(self): val = self._exml.find( util.nspath('TransactionSummary', namespaces['csw'])) if val is not None: id = val.attrib.get('requestId') self.results['requestid'] = util.testXMLValue(id, True) ts = val.find(util.nspath('totalInserted', namespaces['csw'])) self.results['inserted'] = util.testXMLValue(ts) ts = val.find(util.nspath('totalUpdated', namespaces['csw'])) self.results['updated'] = util.testXMLValue(ts) ts = val.find(util.nspath('totalDeleted', namespaces['csw'])) self.results['deleted'] = util.testXMLValue(ts)
def _buildMetadata(self, parse_remote_metadata=False): '''set up capabilities metadata objects:''' self.updateSequence = self._capabilities.attrib.get('updateSequence') # serviceIdentification metadata serviceelem = self._capabilities.find( nspath('Service', ns=WMS_NAMESPACE)) self.identification = ServiceIdentification(serviceelem, self.version) # serviceProvider metadata self.provider = ServiceProvider(serviceelem) # serviceOperations metadata self.operations = [] for elem in self._capabilities.find( nspath('Capability/Request', ns=WMS_NAMESPACE))[:]: self.operations.append(OperationMetadata(elem)) # serviceContents metadata: our assumption is that services use a top-level # layer as a metadata organizer, nothing more. self.contents = OrderedDict() caps = self._capabilities.find(nspath('Capability', WMS_NAMESPACE)) # recursively gather content metadata for all layer elements. # To the WebMapService.contents store only metadata of named layers. def gather_layers(parent_elem, parent_metadata): layers = [] for index, elem in enumerate( parent_elem.findall(nspath('Layer', WMS_NAMESPACE))): cm = ContentMetadata( elem, parent=parent_metadata, index=index + 1, parse_remote_metadata=parse_remote_metadata) if cm.id: if cm.id in self.contents: warnings.warn( 'Content metadata for layer "%s" already exists. Using child layer' % cm.id) layers.append(cm) self.contents[cm.id] = cm cm.children = gather_layers(elem, cm) return layers gather_layers(caps, None) # exceptions self.exceptions = [ f.text for f in self._capabilities.findall( nspath('Capability/Exception/Format', WMS_NAMESPACE)) ]
def test_sortby_query_single(self, requestv110): requestv110.set_sortby(["id"]) sort_elem = requestv110._query.find( util.nspath("SortBy", OGC_NAMESPACE)) sortprop_elem = sort_elem.find( util.nspath("SortProperty", OGC_NAMESPACE)) propertyname = sortprop_elem.findtext( util.nspath("PropertyName", OGC_NAMESPACE)) assert sort_elem is not None assert sortprop_elem is not None assert propertyname == "id"
def test_sortby_query_single(self, requestv200): requestv200.set_sortby(["id"]) sort_elem = requestv200._query.find( util.nspath("SortBy", FES_NAMESPACE)) sortprop_elem = sort_elem.find( util.nspath("SortProperty", FES_NAMESPACE)) propertyname = sortprop_elem.findtext( util.nspath("ValueReference", FES_NAMESPACE)) assert sort_elem is not None assert sortprop_elem is not None assert propertyname == "id"
def __init__(self, md): val = md.find(util.nspath('distributionFormat/MD_Format/name', namespaces['gmd']) + '/' + util.nspath('CharacterString', namespaces['gco'])) self.format = util.testXMLValue(val) val = md.find(util.nspath('distributionFormat/MD_Format/version', namespaces['gmd']) + '/' + util.nspath('CharacterString', namespaces['gco'])) self.version = util.testXMLValue(val) val = md.find(util.nspath('transferOptions/MD_DigitalTransferOptions/onLine/CI_OnlineResource', namespaces['gmd'])) if val is not None: self.onlineresource = CI_OnlineResource(val) else: self.onlineresource = None
def __init__(self, url, lang="en-US", version="2.0.2", timeout=10): """ Construct and process a GetCapabilities request Parameters ---------- - url: the URL of the CSW - lang: the language (default is 'en-US') - version: version (default is '2.0.2') - timeout: timeout in seconds """ self.url = url self.lang = lang self.version = version self.timeout = timeout self.service = "CSW" self.exceptionreport = None self.owscommon = OwsCommon("1.0.0") # construct request node0 = etree.Element(util.nspath("GetCapabilities", namespaces["csw"])) node0.set("service", self.service) node0.set(util.nspath("schemaLocation", namespaces["xsi"]), schema_location) tmp = etree.SubElement(node0, util.nspath("AcceptVersions", namespaces["ows"])) etree.SubElement(tmp, util.nspath("Version", namespaces["ows"])).text = self.version tmp2 = etree.SubElement(node0, util.nspath("AcceptFormats", namespaces["ows"])) etree.SubElement(tmp2, util.nspath("OutputFormat", namespaces["ows"])).text = outputformat self.request = util.xml2string(etree.tostring(node0)) self._invoke() if self.exceptionreport is None: # ServiceIdentification val = self._exml.find(util.nspath("ServiceIdentification", namespaces["ows"])) self.identification = ServiceIdentification(val, self.owscommon.namespace) # ServiceProvider val = self._exml.find(util.nspath("ServiceProvider", namespaces["ows"])) self.provider = ServiceProvider(val, self.owscommon.namespace) # ServiceOperations metadata self.operations = [] for elem in self._exml.findall(util.nspath("OperationsMetadata/Operation", namespaces["ows"])): self.operations.append(OperationsMetadata(elem, self.owscommon.namespace)) # FilterCapabilities val = self._exml.find(util.nspath("Filter_Capabilities", namespaces["ogc"])) self.filters = FilterCapabilities(val)
def __init__(self, infoset, ows_version='1.0.0'): self._root = infoset val = self._root.find(util.nspath('Title', namespace)) self.title = util.testXMLValue(val) val = self._root.find(util.nspath('Abstract', namespace)) self.abstract = util.testXMLValue(val) self.keywords = [] for f in self._root.findall(util.nspath('Keywords/Keyword', namespace)): if f.text is not None: self.keywords.append(f.text) val = self._root.find(util.nspath('AccessConstraints', namespace)) self.accessconstraints = util.testXMLValue(val) val = self._root.find(util.nspath('Fees', namespace)) self.fees = util.testXMLValue(val) val = self._root.find(util.nspath('ServiceType', namespace)) self.type = util.testXMLValue(val) self.service=self.type #alternative? keep both?discuss val = self._root.find(util.nspath('ServiceTypeVersion', namespace)) self.version = util.testXMLValue(val) self.profiles = [] for p in self._root.findall(util.nspath('Profile', namespace)): self.profiles.append(util.testXMLValue(val))
def _setconstraint(self, parent, qtype=None, propertyname='csw:AnyText', keywords=[], bbox=None, cql=None): #if keywords or bbox is not None or qtype is not None or cql is not None: if keywords or bbox is not None or qtype is not None or cql is not None: node0 = etree.SubElement(parent, util.nspath('Constraint', namespaces['csw'])) node0.set('version', '1.1.0') if cql is not None: # send raw CQL query import warnings warnings.warn('CQL passed (overrides all other parameters', UserWarning) node1 = etree.SubElement(node0, util.nspath('CqlText', namespaces['csw'])) node1.text = cql else: # construct a Filter request flt = FilterRequest() node0.append(flt.set(qtype=qtype, keywords=keywords, propertyname=propertyname,bbox=bbox))
def __init__(self,infoset,namespace=DEFAULT_OWS_NAMESPACE): self._root = infoset val = self._root.find(util.nspath('Title', namespace)) self.title = util.testXMLValue(val) val = self._root.find(util.nspath('Abstract', namespace)) self.abstract = util.testXMLValue(val) self.keywords = [f.text for f in self._root.findall(util.nspath('Keywords/Keyword', namespace))] val = self._root.find(util.nspath('AccessConstraints', namespace)) self.accessconstraints = util.testXMLValue(val) val = self._root.find(util.nspath('Fees', namespace)) self.fees = util.testXMLValue(val) val = self._root.find(util.nspath('ServiceType', namespace)) self.type = util.testXMLValue(val) self.service=self.type #alternative? keep both?discuss val = self._root.find(util.nspath('ServiceTypeVersion', namespace)) self.version = util.testXMLValue(val) val = self._root.find(util.nspath('Profile', namespace)) self.profile = util.testXMLValue(val)
def __init__(self, md): self.role = [] for el in md.findall(util.nspath('Role', namespaces['dif'])): self.role.append(util.testXMLValue(el)) val = md.find(util.nspath('First_Name', namespaces['dif'])) self.first_name = util.testXMLValue(val) val = md.find(util.nspath('Middle_Name', namespaces['dif'])) self.middle_name = util.testXMLValue(val) val = md.find(util.nspath('Last_Name', namespaces['dif'])) self.last_name = util.testXMLValue(val) self.email = [] for el in md.findall(util.nspath('Email', namespaces['dif'])): self.email.append(util.testXMLValue(el)) self.phone = [] for el in md.findall(util.nspath('Phone', namespaces['dif'])): self.phone.append(util.testXMLValue(el)) self.fax = [] for el in md.findall(util.nspath('Fax', namespaces['dif'])): self.fax.append(util.testXMLValue(el)) val = md.find(util.nspath('Contact_Address', namespaces['dif'])) self.contact_address = Contact_Address(val)