Debian Codegraph @

os_service_types/exc.py

raw
1 # Copyright 2017 Red Hat, Inc
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import textwrap
17 import warnings
18
19 __all__ = ['warn', 'AliasUsageWarning']
20
21
22 class _BaseWarning(Warning):
23 details: str
24
25
26 class AliasUsageWarning(_BaseWarning):
27 """Use of historical service-type aliases is discouraged."""
28
29 details = """
30 Requested service_type {given} is an old alias. Please update your
31 code to reference the official service_type {official}.
32 """
33
34
35 class UnofficialUsageWarning(_BaseWarning):
36 """Use of unofficial service-types is discouraged."""
37
38 details = """
39 Requested service_type {given} is not a known official OpenStack project.
40 """
41
42
43 def warn(warning: type[_BaseWarning], **kwargs: str | None) -> None:
44 """Emit a warning that has builtin message text."""
45 message = textwrap.fill(textwrap.dedent(warning.details.format(**kwargs)))
46 warnings.warn(message, category=warning)