add BabelTowerError

This commit is contained in:
Yusur 2025-07-30 13:00:41 +02:00
parent 73d3088d86
commit d30e1086f3
3 changed files with 13 additions and 2 deletions

View file

@ -8,7 +8,7 @@
+ Add module `calendar` with `want_*` date type conversion utilities and `age_and_days()` + Add module `calendar` with `want_*` date type conversion utilities and `age_and_days()`
+ Move obsolete stuff to `obsolete` package (includes configparse 0.3 as of now) + Move obsolete stuff to `obsolete` package (includes configparse 0.3 as of now)
+ Add `redact` module with `redact_url_password()` + Add `redact` module with `redact_url_password()`
+ Add more exceptions: `NotFoundError()` + Add more exceptions: `NotFoundError()`, `BabelTowerError()`
## 0.4.0 ## 0.4.0

View file

@ -45,6 +45,13 @@ class NotFoundError(LookupError):
""" """
The requested item was not found. The requested item was not found.
""" """
# Werkzeug et al.
code = 404
class BabelTowerError(NotFoundError):
"""
The user requested a language that cannot be understood.
"""
__all__ = ( __all__ = (
'MissingConfigError', 'MissingConfigWarning', 'LexError', 'InconsistencyError', 'NotFoundError' 'MissingConfigError', 'MissingConfigWarning', 'LexError', 'InconsistencyError', 'NotFoundError'

View file

@ -23,6 +23,7 @@ import os
import toml import toml
from typing import Mapping from typing import Mapping
from .exceptions import BabelTowerError
class IdentityLang: class IdentityLang:
''' '''
@ -81,7 +82,10 @@ class I18n(metaclass=ABCMeta):
def load_lang(self, name: str, filename: str | None = None) -> I18nLang: def load_lang(self, name: str, filename: str | None = None) -> I18nLang:
if not filename: if not filename:
filename = self.filename_tmpl.format(lang=name, ext=self.EXT) filename = self.filename_tmpl.format(lang=name, ext=self.EXT)
data = self.load_file(filename) try:
data = self.load_file(filename)
except OSError as e:
raise BabelTowerError(f'unknown language: {name}') from e
l = self.langs.setdefault(name, I18nLang()) l = self.langs.setdefault(name, I18nLang())
l.update(data[name] if name in data else data) l.update(data[name] if name in data else data)
if name != self.default_lang: if name != self.default_lang: