Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/docutils/parsers/rst/languages/__init__.py: 64%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

28 statements  

1# $Id$ 

2# Author: David Goodger <goodger@python.org> 

3# Copyright: This module has been placed in the public domain. 

4 

5# Internationalization details are documented in 

6# <https://docutils.sourceforge.io/docs/howto/i18n.html>. 

7 

8""" 

9This package contains modules for language-dependent features of 

10reStructuredText. 

11""" 

12 

13from __future__ import annotations 

14 

15__docformat__ = 'reStructuredText' 

16 

17from docutils.languages import LanguageImporter 

18 

19TYPE_CHECKING = False 

20if 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] 

29else: 

30 from docutils.utils._typing import overload 

31 

32 

33class 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 

63get_language: LanguageImporter[RSTLanguageModule] = RstLanguageImporter()