mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
refactor: Move terminal_safe() to sphinx.util.console
This commit is contained in:
parent
644d555837
commit
d40ce68c7b
1
CHANGES
1
CHANGES
@ -124,6 +124,7 @@ Deprecated
|
|||||||
* ``sphinx.util.pycompat.UnicodeMixin``
|
* ``sphinx.util.pycompat.UnicodeMixin``
|
||||||
* ``sphinx.util.pycompat.htmlescape``
|
* ``sphinx.util.pycompat.htmlescape``
|
||||||
* ``sphinx.util.pycompat.indent``
|
* ``sphinx.util.pycompat.indent``
|
||||||
|
* ``sphinx.util.pycompat.terminal_safe()``
|
||||||
* ``sphinx.util.pycompat.u``
|
* ``sphinx.util.pycompat.u``
|
||||||
* ``sphinx.writers.latex.ExtBabel``
|
* ``sphinx.writers.latex.ExtBabel``
|
||||||
* ``sphinx.writers.latex.LaTeXTranslator._make_visit_admonition()``
|
* ``sphinx.writers.latex.LaTeXTranslator._make_visit_admonition()``
|
||||||
|
@ -440,6 +440,11 @@ The following is a list of deprecated interfaces.
|
|||||||
- 4.0
|
- 4.0
|
||||||
- ``textwrap.indent()``
|
- ``textwrap.indent()``
|
||||||
|
|
||||||
|
* - ``sphinx.util.pycompat.terminal_safe()``
|
||||||
|
- 2.0
|
||||||
|
- 4.0
|
||||||
|
- ``sphinx.util.console.terminal_safe()``
|
||||||
|
|
||||||
* - ``sphinx.util.pycompat.u``
|
* - ``sphinx.util.pycompat.u``
|
||||||
- 2.0
|
- 2.0
|
||||||
- 4.0
|
- 4.0
|
||||||
|
@ -23,9 +23,8 @@ from sphinx.application import Sphinx
|
|||||||
from sphinx.errors import SphinxError
|
from sphinx.errors import SphinxError
|
||||||
from sphinx.locale import __
|
from sphinx.locale import __
|
||||||
from sphinx.util import Tee, format_exception_cut_frames, save_traceback
|
from sphinx.util import Tee, format_exception_cut_frames, save_traceback
|
||||||
from sphinx.util.console import red, nocolor, color_terminal # type: ignore
|
from sphinx.util.console import red, nocolor, color_terminal, terminal_safe # type: ignore
|
||||||
from sphinx.util.docutils import docutils_namespace, patch_docutils
|
from sphinx.util.docutils import docutils_namespace, patch_docutils
|
||||||
from sphinx.util.pycompat import terminal_safe
|
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# For type annotation
|
||||||
|
@ -27,6 +27,12 @@ _ansi_re = re.compile('\x1b\\[(\\d\\d;){0,2}\\d\\dm')
|
|||||||
codes = {} # type: Dict[str, str]
|
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():
|
def get_terminal_width():
|
||||||
# type: () -> int
|
# type: () -> int
|
||||||
"""Borrowed from the py lib."""
|
"""Borrowed from the py lib."""
|
||||||
|
@ -17,6 +17,8 @@ import warnings
|
|||||||
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
|
from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias
|
||||||
from sphinx.locale import __
|
from sphinx.locale import __
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
|
from sphinx.util.console import terminal_safe
|
||||||
|
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
# For type annotation
|
# For type annotation
|
||||||
@ -36,12 +38,6 @@ NoneType = type(None)
|
|||||||
sys_encoding = sys.getdefaultencoding()
|
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():
|
# convert_with_2to3():
|
||||||
# support for running 2to3 over config files
|
# support for running 2to3 over config files
|
||||||
def convert_with_2to3(filepath):
|
def convert_with_2to3(filepath):
|
||||||
@ -102,6 +98,7 @@ deprecated_alias('sphinx.util.pycompat',
|
|||||||
'TextIOWrapper': io.TextIOWrapper,
|
'TextIOWrapper': io.TextIOWrapper,
|
||||||
'htmlescape': html.escape,
|
'htmlescape': html.escape,
|
||||||
'indent': textwrap.indent,
|
'indent': textwrap.indent,
|
||||||
|
'terminal_safe': terminal_safe,
|
||||||
'u': '',
|
'u': '',
|
||||||
},
|
},
|
||||||
RemovedInSphinx40Warning)
|
RemovedInSphinx40Warning)
|
||||||
|
Loading…
Reference in New Issue
Block a user