From 79909b497cdcc691899246368b622bc7fec15c4f Mon Sep 17 00:00:00 2001 From: Paul van Genuchten Date: Thu, 4 Apr 2024 22:54:29 +0200 Subject: [PATCH] same fixes as #919 #918, but to csw3 (#920) --- owslib/catalogue/csw3.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/owslib/catalogue/csw3.py b/owslib/catalogue/csw3.py index 64e9ea58..9d9a842e 100644 --- a/owslib/catalogue/csw3.py +++ b/owslib/catalogue/csw3.py @@ -145,23 +145,25 @@ def getdomain(self, dname, dtype='parameter'): etree.SubElement(node0, util.nspath_eval('csw30:%s' % dtypename, namespaces)).text = dname self.request = node0 + try: # getdomain operation is optional on CSW3, return empty if failing + self._invoke() - self._invoke() - - if self.exceptionreport is None: - self.results = {} + if self.exceptionreport is None: + self.results = {} - val = self._exml.find(util.nspath_eval('csw30:DomainValues', namespaces)).attrib.get('type') - self.results['type'] = util.testXMLValue(val, True) + val = self._exml.find(util.nspath_eval('csw30:DomainValues', namespaces)).attrib.get('type') + self.results['type'] = util.testXMLValue(val, True) - val = self._exml.find(util.nspath_eval('csw30:DomainValues/csw30:%s' % dtypename, namespaces)) - self.results[dtype] = util.testXMLValue(val) + val = self._exml.find(util.nspath_eval('csw30:DomainValues/csw30:%s' % dtypename, namespaces)) + self.results[dtype] = util.testXMLValue(val) - # get the list of values associated with the Domain - self.results['values'] = [] + # get the list of values associated with the Domain + self.results['values'] = [] - for f in self._exml.findall(util.nspath_eval('csw30:DomainValues/csw30:ListOfValues/csw30:Value', namespaces)): # noqa - self.results['values'].append(util.testXMLValue(f)) + for f in self._exml.findall(util.nspath_eval('csw30:DomainValues/csw30:ListOfValues/csw30:Value', namespaces)): # noqa + self.results['values'].append(util.testXMLValue(f)) + except Exception: + self.results = {'values': []} def getrecordbyid(self, id=[], esn='full', outputschema=namespaces['csw30'], format=outputformat): """ @@ -557,15 +559,16 @@ def _invoke(self): post_verbs = [x for x in op.methods if x.get('type').lower() == 'post'] if len(post_verbs) > 1: # Filter by constraints. We must match a PostEncoding of "XML" + found_xml = False for pv in post_verbs: for const in pv.get('constraints'): if const.name.lower() == 'postencoding': values = [v.lower() for v in const.values] if 'xml' in values: request_url = pv.get('url') + found_xml = True break - else: - # Well, just use the first one. + if not found_xml: # Well, just use the first one. request_url = post_verbs[0].get('url') elif len(post_verbs) == 1: request_url = post_verbs[0].get('url')