Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/wcwidth/__init__.py: 78%
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
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
1"""
2Python 'wcwidth' module.
4https://github.com/jquast/wcwidth
5"""
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]
27# std imports
28import os
29from functools import lru_cache
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 .grapheme import iter_graphemes_reverse, grapheme_boundary_before
37from .textwrap import SequenceTextWrapper, wrap
38from .hyperlink import Hyperlink, HyperlinkParams
39from ._constants import list_term_programs
40from .table_vs16 import VS16_NARROW_TO_WIDE
41from .table_wide import WIDE_EASTASIAN
42from .table_zero import ZERO_WIDTH
43from .text_sizing import TextSizing, TextSizingParams
44from .table_ambiguous import AMBIGUOUS_EASTASIAN
45from .escape_sequences import iter_sequences
46from .unicode_versions import list_versions
48# Optional C extension 'wcwidth._wcwidth_c', wrapping the C11 libwcwidth
49# library; the Python implementations below are used when it is unavailable.
50HAS_C_EXTENSION = False
51if not os.environ.get('WCWIDTH_PYTHON', ''):
52 try:
53 # local
54 import wcwidth._wcwidth_c as _wcwidth_c # noqa: F401 pylint:disable=unused-import,consider-using-from-import
55 except ImportError:
56 pass
57 else:
58 HAS_C_EXTENSION = True
60# Import order matters for legacy API compatibility (releases before 0.7.0).
61#
62# The first release (0.1) put _bisearch, wcwidth, and wcswidth in a single 'wcwidth.py' file, and
63# while the top-level function importing, 'from wcwidth import wcwidth' was always preferred, the
64# deeper 'from wcwidth.wcwidth import wcwidth' was always possible.
65#
66# Pre-import the legacy submodule so sys.modules['wcwidth.wcwidth'] is populated during package
67# initialization: without it, a later ``import wcwidth.wcwidth`` discovers the file on disk and
68# rebinds that name from the function to the module object. It must run before the 'wcwidth'
69# binding below, because 'from . import wcwidth' loads the submodule while the package attribute
70# is still unset. The shim's own __lazy_modules__ defers its imports, so this costs one module.
71from . import wcwidth as _wcwidth_module # isort:skip pylint: disable=wrong-import-position
73if HAS_C_EXTENSION:
74 # local
75 from ._wcwidth_c import ljust, rjust, width, center
76 from ._wcwidth_c import wcwidth as _c_wcwidth
77 from ._wcwidth_c import wcswidth, wcstwidth, propagate_sgr, iter_graphemes, strip_sequences
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 ._wcswidth import wcswidth, wcstwidth
86 from .sgr_state import propagate_sgr
87 from .escape_sequences import strip_sequences
89from ._wcwidth import _wcmatch_version, _wcversion_value # isort:skip # pylint: disable=wrong-import-position
92# The __all__ attribute defines the items exported from statement,
93# 'from wcwidth import *', but also to say, "This is the public API".
94__all__ = ('wcwidth', 'wcswidth', 'wcstwidth', 'width', 'iter_sequences', 'iter_graphemes',
95 'iter_graphemes_reverse', 'grapheme_boundary_before',
96 'ljust', 'rjust', 'center', 'wrap', 'clip', 'strip_sequences',
97 'list_versions', 'list_term_programs', 'propagate_sgr',
98 'Hyperlink', 'HyperlinkParams', 'TextSizing', 'TextSizingParams')
100# Version is stamped by code generation (bin/update-tables.py) from pyproject.toml.
101__version__ = '0.9.2'