]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | # -*- coding: utf-8 -*- |
2 | from contextlib import contextmanager | |
3 | ||
4 | import cherrypy | |
5 | ||
6 | ||
7 | class SettingsService: | |
8 | @contextmanager | |
9 | # pylint: disable=no-self-argument | |
10 | def attribute_handler(name): | |
11 | """ | |
12 | :type name: str|dict[str, str] | |
13 | :rtype: str|dict[str, str] | |
14 | """ | |
15 | if isinstance(name, dict): | |
16 | result = { | |
17 | _to_native(key): value | |
18 | for key, value in name.items() | |
19 | } | |
20 | else: | |
21 | result = _to_native(name) | |
22 | ||
23 | try: | |
24 | yield result | |
25 | except AttributeError: # pragma: no cover - handling is too obvious | |
26 | raise cherrypy.NotFound(result) # pragma: no cover - handling is too obvious | |
27 | ||
28 | ||
29 | def _to_native(setting): | |
30 | return setting.upper().replace('-', '_') |