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

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

41 statements  

1""" 

2Python 'wcwidth' module. 

3 

4https://github.com/jquast/wcwidth 

5""" 

6 

7__lazy_modules__ = [ 

8 "wcwidth._clip", 

9 "wcwidth._wcswidth", 

10 "wcwidth._wcwidth", 

11 "wcwidth._width", 

12 "wcwidth.align", 

13 "wcwidth.bisearch", 

14 "wcwidth.escape_sequences", 

15 "wcwidth.grapheme", 

16 "wcwidth.hyperlink", 

17 "wcwidth.sgr_state", 

18 "wcwidth.table_ambiguous", 

19 "wcwidth.table_vs16", 

20 "wcwidth.table_wide", 

21 "wcwidth.table_zero", 

22 "wcwidth.text_sizing", 

23 "wcwidth.textwrap", 

24 "wcwidth.unicode_versions", 

25] 

26 

27# std imports 

28import os 

29from functools import lru_cache 

30 

31# local 

32from ._clip import clip 

33# re-export common and outermost functions & definitions, even a few private ones. Some are for 

34# convenience and others for legacy, only the items in '__all__' are documented as public API 

35from .bisearch import bisearch as _bisearch 

36from .textwrap import SequenceTextWrapper, wrap 

37from .hyperlink import Hyperlink, HyperlinkParams 

38from ._constants import list_term_programs 

39from .table_vs16 import VS16_NARROW_TO_WIDE 

40from .table_wide import WIDE_EASTASIAN 

41from .table_zero import ZERO_WIDTH 

42from .text_sizing import TextSizing, TextSizingParams 

43from .table_ambiguous import AMBIGUOUS_EASTASIAN 

44from .escape_sequences import iter_sequences 

45from .unicode_versions import list_versions 

46 

47# Optional C extension 'wcwidth._wcwidth_c', wrapping the C11 libwcwidth 

48# library; the Python implementations below are used when it is unavailable. 

49HAS_C_EXTENSION = False 

50if not os.environ.get('WCWIDTH_PYTHON', ''): 

51 try: 

52 # local 

53 import wcwidth._wcwidth_c as _wcwidth_c # noqa: F401 pylint:disable=unused-import,consider-using-from-import 

54 except ImportError: 

55 pass 

56 else: 

57 HAS_C_EXTENSION = True 

58 

59# Import order matters for legacy API compatibility (releases before 0.7.0). 

60# 

61# The first release (0.1) put _bisearch, wcwidth, and wcswidth in a single 'wcwidth.py' file, and 

62# while the top-level function importing, 'from wcwidth import wcwidth' was always preferred, the 

63# deeper 'from wcwidth.wcwidth import wcwidth' was always possible. 

64# 

65# Pre-import the legacy submodule so sys.modules['wcwidth.wcwidth'] is populated during package 

66# initialization: without it, a later ``import wcwidth.wcwidth`` discovers the file on disk and 

67# rebinds that name from the function to the module object. It must run before the 'wcwidth' 

68# binding below, because 'from . import wcwidth' loads the submodule while the package attribute 

69# is still unset. The shim's own __lazy_modules__ defers its imports, so this costs one module. 

70from . import wcwidth as _wcwidth_module # isort:skip pylint: disable=wrong-import-position 

71 

72if HAS_C_EXTENSION: 

73 # local 

74 from ._wcwidth_c import ljust, rjust, width, center 

75 from ._wcwidth_c import wcwidth as _c_wcwidth 

76 from ._wcwidth_c import wcswidth, wcstwidth, propagate_sgr, iter_graphemes, strip_sequences 

77 from ._wcwidth_c import iter_graphemes_reverse, grapheme_boundary_before 

78 wcwidth = lru_cache(maxsize=1024)(_c_wcwidth) 

79else: 

80 # local 

81 from .align import ljust, rjust, center 

82 from ._width import width 

83 from ._wcwidth import wcwidth 

84 from .grapheme import iter_graphemes 

85 from .grapheme import iter_graphemes_reverse, grapheme_boundary_before 

86 from ._wcswidth import wcswidth, wcstwidth 

87 from .sgr_state import propagate_sgr 

88 from .escape_sequences import strip_sequences 

89 

90from ._wcwidth import _wcmatch_version, _wcversion_value # isort:skip # pylint: disable=wrong-import-position 

91 

92 

93# The __all__ attribute defines the items exported from statement, 

94# 'from wcwidth import *', but also to say, "This is the public API". 

95__all__ = ('wcwidth', 'wcswidth', 'wcstwidth', 'width', 'iter_sequences', 'iter_graphemes', 

96 'iter_graphemes_reverse', 'grapheme_boundary_before', 

97 'ljust', 'rjust', 'center', 'wrap', 'clip', 'strip_sequences', 

98 'list_versions', 'list_term_programs', 'propagate_sgr', 

99 'Hyperlink', 'HyperlinkParams', 'TextSizing', 'TextSizingParams') 

100 

101# Version is stamped by code generation (bin/update-tables.py) from pyproject.toml. 

102__version__ = '0.9.4'