From 71e64bd2b250ce646c53d6179dd21ed49de14e6a Mon Sep 17 00:00:00 2001 From: Paul van Genuchten Date: Thu, 4 Apr 2024 22:33:22 +0200 Subject: [PATCH] use flag instead of for-else in csw:retrecords (#919) * for-else works on inner loop only * rename found_xml param fix flake8 error --- owslib/catalogue/csw2.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/owslib/catalogue/csw2.py b/owslib/catalogue/csw2.py index 9567c60a..94133c1c 100644 --- a/owslib/catalogue/csw2.py +++ b/owslib/catalogue/csw2.py @@ -187,10 +187,10 @@ def getdomain(self, dname, dtype='parameter'): # get the list of values associated with the Domain self.results['values'] = [] - for f in self._exml.findall(util.nspath_eval('csw:DomainValues/csw:ListOfValues/csw:Value', namespaces)): + for f in self._exml.findall(util.nspath_eval('csw:DomainValues/csw:ListOfValues/csw:Value', namespaces)): # noqa self.results['values'].append(util.testXMLValue(f)) except Exception: - self.results['values'] = [] + self.results = {'values': []} def getrecords(self, qtype=None, keywords=[], typenames='csw:Record', propertyname='csw:AnyText', bbox=None, esn='summary', sortby=None, outputschema=namespaces['csw'], format=outputformat, startposition=0, @@ -664,15 +664,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')