Skip to content

Commit

Permalink
Bug fixes and minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSander committed Mar 5, 2021
1 parent 1897675 commit d36895c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
9 changes: 4 additions & 5 deletions pygeoapi/l10n.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ def best_match(accept_languages, available_locales) -> Locale:
property of the returned locale.
.. note:: Any tag in the `accept_languages` string that is an invalid
or unknown locale is ignored. However, all `available_locales`
are validated if `silent` is True (default is False).
In that case, a `LocaleError` is raised.
or unknown locale is ignored. However, if no
`available_locales` are specified, a `LocaleError` is raised.
:param accept_languages: A Locale or string with one or more locale tags.
:param accept_languages: A Locale or string with one or more languages.
This can be as simple as "de" for example,
but it's also possible to include a territory
(e.g. "en-US" or "fr_BE") or even a complex
Expand Down Expand Up @@ -203,7 +202,7 @@ def get_match(locale_, available_locales_):

def translate(value, language):
"""
If the given `value` is a language struct (where its keys are language codes
If `value` is a language struct (where its keys are language codes
and its values are translations for each language), this function tries to
find and return the translation for the given `language`.
Expand Down
6 changes: 2 additions & 4 deletions pygeoapi/provider/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ def __init__(self, provider_def, **kwargs):
# locale support
self.locale = None
locales = provider_def.get('languages', [])
try:
if locales:
self.locale = l10n.best_match(kwargs.get('language'), locales)
LOGGER.info(f'{self.name} provider locale set to {self.locale}')
except l10n.LocaleError as err:
if locales:
LOGGER.error(err)
else:
LOGGER.info(f'{self.name} provider has no locale support')

self.options = provider_def.get('options', None)
Expand Down
4 changes: 2 additions & 2 deletions pygeoapi/provider/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
LOGGER = logging.getLogger(__name__)


class MongoProvider(BaseProvider, **kwargs):
class MongoProvider(BaseProvider):
"""Generic provider for Mongodb.
"""

Expand All @@ -58,7 +58,7 @@ def __init__(self, provider_def, **kwargs):
# Mongo id field is _id
provider_def.setdefault('id_field', '_id')

super().__init__(provider_def)
super().__init__(provider_def, **kwargs)

LOGGER.info('Mongo source config: {}'.format(self.data))

Expand Down
19 changes: 8 additions & 11 deletions pygeoapi/provider/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,22 @@ def __init__(self, provider_def, **kwargs):
:returns: pygeoapi.provider.tile.BaseTileProvider
"""
self.name = provider_def['name']
self.data = provider_def['data']
self.format_type = provider_def['format']['name']
self.mimetype = provider_def['format']['mimetype']
self.options = provider_def.get('options', None)
self.fields = {}

# locale support for providers that need it
self.locale = None
locales = provider_def.get('languages', [])
try:
if locales:
self.locale = l10n.best_match(kwargs.get('language'), locales)
LOGGER.info(f'{self.name} provider locale set to {self.locale}')
except l10n.LocaleError as err:
if locales:
LOGGER.error(err)
else:
LOGGER.info(f'{self.name} provider has no locale support')

self.name = provider_def['name']
self.data = provider_def['data']
self.format_type = provider_def['format']['name']
self.mimetype = provider_def['format']['mimetype']
self.options = provider_def.get('options', None)
self.fields = {}

def get_layer(self):
"""
Get provider layer name
Expand Down
3 changes: 3 additions & 0 deletions pygeoapi/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import yaml

from pygeoapi import __version__
from pygeoapi import l10n
from pygeoapi.provider.base import ProviderTypeError

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -234,6 +235,8 @@ def json_serial(obj):
return base64.b64encode(obj)
elif isinstance(obj, Decimal):
return float(obj)
elif isinstance(obj, l10n.Locale):
return l10n.locale2str(obj)

msg = '{} type {} not serializable'.format(obj, type(obj))
LOGGER.error(msg)
Expand Down

0 comments on commit d36895c

Please sign in to comment.