Skip to content

Commit

Permalink
Merge pull request #820 from tomkralidis/ogcapi-f-strings
Browse files Browse the repository at this point in the history
update new OGC API code with f-strings
  • Loading branch information
tomkralidis authored Apr 28, 2022
2 parents 41216fb + df97f05 commit b4dca5c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions owslib/ogcapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
LOGGER = logging.getLogger(__name__)

REQUEST_HEADERS = {
'User-Agent': 'OWSLib {} (https://geopython.github.io/OWSLib)'.format(__version__)
'User-Agent': f'OWSLib {__version__} (https://geopython.github.io/OWSLib)'
}


Expand Down Expand Up @@ -94,7 +94,7 @@ def api(self) -> dict:
break

if url is not None:
LOGGER.debug('Request: {}'.format(url))
LOGGER.debug(f'Request: {url}')
response = http_get(url, headers=REQUEST_HEADERS, auth=self.auth)
if openapi_format == openapi_json_mimetype:
content = response.json()
Expand Down Expand Up @@ -137,7 +137,7 @@ def _build_url(self, path: str = None, params: dict = {}) -> str:
if params:
url = '?'.join([url, urlencode(params)])

LOGGER.debug('URL: {}'.format(url))
LOGGER.debug(f'URL: {url}')

return url

Expand All @@ -159,8 +159,8 @@ def _request(self, path: str = None, as_dict: bool = True,
url = self._build_url(path)
self.request = url

LOGGER.debug('Request: {}'.format(url))
LOGGER.debug('Params: {}'.format(kwargs))
LOGGER.debug(f'Request: {url}')
LOGGER.debug(f'Params: {kwargs}')

if 'cql' not in kwargs:
response = http_get(url, headers=self.headers, auth=self.auth,
Expand All @@ -172,7 +172,7 @@ def _request(self, path: str = None, as_dict: bool = True,
url2 = self._build_url(path, kwargs2)
response = http_post(url2, request=cql, auth=self.auth)

LOGGER.debug('URL: {}'.format(response.url))
LOGGER.debug(f'URL: {response.url}')

if response.status_code != requests.codes.ok:
raise RuntimeError(response.text)
Expand Down Expand Up @@ -211,7 +211,7 @@ def collection(self, collection_id: str) -> dict:
@returns: `dict` of feature collection metadata
"""

path = 'collections/{}'.format(collection_id)
path = f'collections/{collection_id}'
return self._request(path)

def collection_queryables(self, collection_id: str) -> dict:
Expand All @@ -224,5 +224,5 @@ def collection_queryables(self, collection_id: str) -> dict:
@returns: `dict` of feature collection queryables
"""

path = 'collections/{}/queryables'.format(collection_id)
path = f'collections/{collection_id}/queryables'
return self._request(path)
10 changes: 5 additions & 5 deletions owslib/ogcapi/coverages.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def coverage_domainset(self, collection_id: str, **kwargs: dict) -> dict:
@returns: coverage domainset results
"""

path = 'collections/{}/coverage/domainset'.format(collection_id)
path = f'collections/{collection_id}/coverage/domainset'
return self._request(path=path, kwargs=kwargs)

def coverage_rangetype(self, collection_id: str, **kwargs: dict) -> dict:
Expand All @@ -64,7 +64,7 @@ def coverage_rangetype(self, collection_id: str, **kwargs: dict) -> dict:
@returns: coverage rangetype results
"""

path = 'collections/{}/coverage/rangetype'.format(collection_id)
path = f'collections/{collection_id}/coverage/rangetype'
return self._request(path=path, kwargs=kwargs)

def coverage(self, collection_id: str, **kwargs: dict) -> dict:
Expand Down Expand Up @@ -98,18 +98,18 @@ def coverage(self, collection_id: str, **kwargs: dict) -> dict:
p2 = p.replace('_', '-')
kwargs_[p2] = []
for s in kwargs[p2]:
val = '{}({},{})'.format(s[0], s[1], s[2])
val = f'{s[0]}({s[1]},{s[2]})'
kwargs_[p2].append(val)

if 'subset' in kwargs:
subsets_list = []
for s in kwargs['subset']:
subsets_list.append('{}({}:{})'.format(s[0], s[1], s[2]))
subsets_list.append(f'{s[0]}({s[1]}:{s[2]})')
kwargs['subset'] = ','.join(subsets_list)

if 'scale_factor' in kwargs:
kwargs_['scale-factor'] = int(kwargs['scale_factor'])

path = 'collections/{}/coverage'.format(collection_id)
path = f'collections/{collection_id}/coverage'

return BytesIO(self._request(path=path, as_dict=False, kwargs=kwargs_))
4 changes: 2 additions & 2 deletions owslib/ogcapi/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def collection_items(self, collection_id: str, **kwargs: dict) -> dict:
if 'bbox' in kwargs:
kwargs['bbox'] = ','.join(list(map(str, kwargs['bbox'])))

path = 'collections/{}/items'.format(collection_id)
path = f'collections/{collection_id}/items'
return self._request(path=path, kwargs=kwargs)

def collection_item(self, collection_id: str, identifier: str) -> dict:
Expand All @@ -80,5 +80,5 @@ def collection_item(self, collection_id: str, identifier: str) -> dict:
@returns: single feature result
"""

path = 'collections/{}/items/{}'.format(collection_id, identifier)
path = f'collections/{collection_id}/items/{identifier}'
return self._request(path=path)
2 changes: 1 addition & 1 deletion tests/test_ogcapi_records_pycsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_ogcapi_records_pycsw():
assert pycsw_cite_demo_query['numberReturned'] == 2
assert len(pycsw_cite_demo_query['features']) == 2

cql_json = {'eq': [{'property': 'title'}, 'Lorem ipsum']}
cql_json = {'op': '=', 'args': [{'property': 'title'}, 'Lorem ipsum']}
pycsw_cite_demo_query = w.collection_items('metadata:main', cql=cql_json)
assert pycsw_cite_demo_query['numberMatched'] == 1
assert pycsw_cite_demo_query['numberReturned'] == 1
Expand Down

0 comments on commit b4dca5c

Please sign in to comment.