| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
""" |
| 9 |
This package contains modules for language-dependent features of |
| 10 |
reStructuredText. |
| 11 |
""" |
| 12 |
|
| 13 |
from __future__ import annotations |
| 14 |
|
| 15 |
__docformat__ = 'reStructuredText' |
| 16 |
|
| 17 |
from docutils.languages import LanguageImporter |
| 18 |
|
| 19 |
TYPE_CHECKING = False |
| 20 |
if TYPE_CHECKING: |
| 21 |
import types |
| 22 |
from typing import NoReturn, Protocol, overload |
| 23 |
|
| 24 |
class RSTLanguageModule(Protocol): |
| 25 |
__name__: str |
| 26 |
|
| 27 |
directives: dict[str, str] |
| 28 |
roles: dict[str, str] |
| 29 |
else: |
| 30 |
from docutils.utils._typing import overload |
| 31 |
|
| 32 |
|
| 33 |
class RstLanguageImporter(LanguageImporter): |
| 34 |
"""Import language modules. |
| 35 |
|
| 36 |
When called with a BCP 47 language tag, instances return a module |
| 37 |
with localisations for "directive" and "role" names for from |
| 38 |
`docutils.parsers.rst.languages` or the PYTHONPATH. |
| 39 |
|
| 40 |
If there is no matching module, warn (if a `reporter` is passed) |
| 41 |
and return None. |
| 42 |
""" |
| 43 |
packages = ('docutils.parsers.rst.languages.', '') |
| 44 |
warn_msg = 'rST localisation for language "%s" not found.' |
| 45 |
fallback = None |
| 46 |
|
| 47 |
@overload |
| 48 |
def check_content(self, module: RSTLanguageModule) -> None: |
| 49 |
... |
| 50 |
|
| 51 |
@overload |
| 52 |
def check_content(self, module: types.ModuleType) -> NoReturn: |
| 53 |
... |
| 54 |
|
| 55 |
def check_content(self, module: RSTLanguageModule | types.ModuleType |
| 56 |
) -> None: |
| 57 |
"""Check if we got an rST language module.""" |
| 58 |
if not (isinstance(module.directives, dict) |
| 59 |
and isinstance(module.roles, dict)): |
| 60 |
raise ImportError |
| 61 |
|
| 62 |
|
| 63 |
get_language: LanguageImporter[RSTLanguageModule] = RstLanguageImporter() |