diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-01-07 22:38:48 +0900 |
|---|---|---|
| committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-02-11 16:41:19 +0900 |
| commit | d40ce68c7b2b02603725cf3072262ebcc82b40fe (patch) | |
| tree | 793ff2f6590cce1c1346eb7f08f7d3073ac3d76c /sphinx/util | |
| parent | 644d5558373d71268d0d8d3af760782a188e1e4c (diff) | |
| download | sphinx-git-d40ce68c7b2b02603725cf3072262ebcc82b40fe.tar.gz | |
refactor: Move terminal_safe() to sphinx.util.console
Diffstat (limited to 'sphinx/util')
| -rw-r--r-- | sphinx/util/console.py | 6 | ||||
| -rw-r--r-- | sphinx/util/pycompat.py | 9 |
2 files changed, 9 insertions, 6 deletions
diff --git a/sphinx/util/console.py b/sphinx/util/console.py index b419e1284..c207d32ac 100644 --- a/sphinx/util/console.py +++ b/sphinx/util/console.py @@ -27,6 +27,12 @@ _ansi_re = re.compile('\x1b\\[(\\d\\d;){0,2}\\d\\dm') codes = {} # type: Dict[str, str] +def terminal_safe(s): + # type: (str) -> str + """safely encode a string for printing to the terminal.""" + return s.encode('ascii', 'backslashreplace').decode('ascii') + + def get_terminal_width(): # type: () -> int """Borrowed from the py lib.""" diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 5f02bd979..51697432e 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -17,6 +17,8 @@ import warnings from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias from sphinx.locale import __ from sphinx.util import logging +from sphinx.util.console import terminal_safe + if False: # For type annotation @@ -36,12 +38,6 @@ NoneType = type(None) sys_encoding = sys.getdefaultencoding() -# terminal_safe(): safely encode a string for printing to the terminal -def terminal_safe(s): - # type: (str) -> str - return s.encode('ascii', 'backslashreplace').decode('ascii') - - # convert_with_2to3(): # support for running 2to3 over config files def convert_with_2to3(filepath): @@ -102,6 +98,7 @@ deprecated_alias('sphinx.util.pycompat', 'TextIOWrapper': io.TextIOWrapper, 'htmlescape': html.escape, 'indent': textwrap.indent, + 'terminal_safe': terminal_safe, 'u': '', }, RemovedInSphinx40Warning) |
