Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/multidict/__init__.py: 71%

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""" 

2Multidict implementation. 

3 

4HTTP Headers and URL query string require specific data structure: 

5multidict. It behaves mostly like a dict but it can have 

6several values for the same key. 

7""" 

8 

9import warnings 

10from pathlib import Path 

11from typing import TYPE_CHECKING, Any 

12 

13from ._abc import MultiMapping, MutableMultiMapping 

14from ._compat import USE_EXTENSIONS 

15 

16__all__ = ( 

17 "CIMultiDict", 

18 "CIMultiDictProxy", 

19 "MultiDict", 

20 "MultiDictProxy", 

21 "MultiMapping", 

22 "MutableMultiMapping", 

23 "get_include", 

24 "getversion", 

25 "istr", 

26) 

27 

28__version__ = "7.2.0" 

29 

30 

31if TYPE_CHECKING or not USE_EXTENSIONS: 

32 from ._multidict_py import ( 

33 CIMultiDict, 

34 CIMultiDictProxy, 

35 MultiDict, 

36 MultiDictProxy, 

37 getversion, 

38 istr, 

39 ) 

40else: 

41 from collections.abc import ItemsView, KeysView, ValuesView 

42 

43 from ._multidict import ( 

44 CIMultiDict, 

45 CIMultiDictProxy, 

46 MultiDict, 

47 MultiDictProxy, 

48 _ItemsView, 

49 _KeysView, 

50 _ValuesView, 

51 getversion, 

52 istr, 

53 ) 

54 

55 MultiMapping.register(MultiDictProxy) 

56 MutableMultiMapping.register(MultiDict) 

57 KeysView.register(_KeysView) 

58 ItemsView.register(_ItemsView) 

59 ValuesView.register(_ValuesView) 

60 

61 

62if TYPE_CHECKING: 

63 upstr = istr 

64else: 

65 

66 def __getattr__(name: str) -> Any: 

67 if name == "upstr": 

68 warnings.warn( 

69 "upstr is deprecated, use istr instead", 

70 DeprecationWarning, 

71 stacklevel=2, 

72 ) 

73 return istr 

74 raise AttributeError(f"module {__name__!r} has no attribute {name!r}") 

75 

76 

77def __dir__() -> list[str]: 

78 return [*globals(), "upstr"] 

79 

80 

81def get_include() -> str: 

82 """Return the directory containing multidict's C API headers. 

83 

84 Pass it as an ``-I`` include path when building a C extension 

85 against ``multidict_capi.h``. 

86 """ 

87 return str(Path(__file__).absolute().parent)