mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Remove use of six.binary_type
Remove type checks for cases that don't apply to Python 3. For remaining uses, use bytes instead
This commit is contained in:
parent
7ff3d1875a
commit
27a6787d63
1
CHANGES
1
CHANGES
@ -22,6 +22,7 @@ Deprecated
|
|||||||
* The ``suffix`` argument of ``env.doc2path()`` is deprecated.
|
* The ``suffix`` argument of ``env.doc2path()`` is deprecated.
|
||||||
* The string style ``base`` argument of ``env.doc2path()`` is deprecated.
|
* The string style ``base`` argument of ``env.doc2path()`` is deprecated.
|
||||||
* ``sphinx.application.Sphinx._setting_up_extension``
|
* ``sphinx.application.Sphinx._setting_up_extension``
|
||||||
|
* ``sphinx.ext.config.check_unicode()``
|
||||||
* ``sphinx.ext.doctest.doctest_encode()``
|
* ``sphinx.ext.doctest.doctest_encode()``
|
||||||
* ``sphinx.testing.util.remove_unicode_literal()``
|
* ``sphinx.testing.util.remove_unicode_literal()``
|
||||||
* ``sphinx.util.get_matching_docs()`` is deprecated
|
* ``sphinx.util.get_matching_docs()`` is deprecated
|
||||||
|
@ -133,6 +133,11 @@ The following is a list of deprecated interfaces.
|
|||||||
- 4.0
|
- 4.0
|
||||||
- ``os.path.join()``
|
- ``os.path.join()``
|
||||||
|
|
||||||
|
* - ``sphinx.ext.config.check_unicode()``
|
||||||
|
- 2.0
|
||||||
|
- 4.0
|
||||||
|
- N/A
|
||||||
|
|
||||||
* - ``sphinx.ext.doctest.doctest_encode()``
|
* - ``sphinx.ext.doctest.doctest_encode()``
|
||||||
- 2.0
|
- 2.0
|
||||||
- 4.0
|
- 4.0
|
||||||
|
@ -25,7 +25,7 @@ from docutils.parsers.rst import Directive, directives, roles
|
|||||||
|
|
||||||
import sphinx
|
import sphinx
|
||||||
from sphinx import package_dir, locale
|
from sphinx import package_dir, locale
|
||||||
from sphinx.config import Config, check_unicode
|
from sphinx.config import Config
|
||||||
from sphinx.config import CONFIG_FILENAME # NOQA # for compatibility (RemovedInSphinx30)
|
from sphinx.config import CONFIG_FILENAME # NOQA # for compatibility (RemovedInSphinx30)
|
||||||
from sphinx.deprecation import (
|
from sphinx.deprecation import (
|
||||||
RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
||||||
@ -200,7 +200,6 @@ class Sphinx:
|
|||||||
self.config = Config({}, confoverrides or {})
|
self.config = Config({}, confoverrides or {})
|
||||||
else:
|
else:
|
||||||
self.config = Config.read(self.confdir, confoverrides or {}, self.tags)
|
self.config = Config.read(self.confdir, confoverrides or {}, self.tags)
|
||||||
check_unicode(self.config)
|
|
||||||
|
|
||||||
# initialize some limited config variables before initialize i18n and loading
|
# initialize some limited config variables before initialize i18n and loading
|
||||||
# extensions
|
# extensions
|
||||||
|
@ -18,7 +18,7 @@ import sys
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from docutils.utils import SystemMessage
|
from docutils.utils import SystemMessage
|
||||||
from six import text_type, binary_type
|
from six import text_type
|
||||||
|
|
||||||
import sphinx.locale
|
import sphinx.locale
|
||||||
from sphinx import __display_version__, package_dir
|
from sphinx import __display_version__, package_dir
|
||||||
@ -230,13 +230,6 @@ def build_main(argv=sys.argv[1:]): # type: ignore
|
|||||||
if missing_files:
|
if missing_files:
|
||||||
parser.error(__('cannot find files %r') % missing_files)
|
parser.error(__('cannot find files %r') % missing_files)
|
||||||
|
|
||||||
# likely encoding used for command-line arguments
|
|
||||||
try:
|
|
||||||
locale = __import__('locale') # due to submodule of the same name
|
|
||||||
likely_encoding = locale.getpreferredencoding()
|
|
||||||
except Exception:
|
|
||||||
likely_encoding = None
|
|
||||||
|
|
||||||
if args.force_all and filenames:
|
if args.force_all and filenames:
|
||||||
parser.error(__('cannot combine -a option and filenames'))
|
parser.error(__('cannot combine -a option and filenames'))
|
||||||
|
|
||||||
@ -268,11 +261,6 @@ def build_main(argv=sys.argv[1:]): # type: ignore
|
|||||||
key, val = val.split('=', 1)
|
key, val = val.split('=', 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
parser.error(__('-D option argument must be in the form name=value'))
|
parser.error(__('-D option argument must be in the form name=value'))
|
||||||
if likely_encoding and isinstance(val, binary_type):
|
|
||||||
try:
|
|
||||||
val = val.decode(likely_encoding)
|
|
||||||
except UnicodeError:
|
|
||||||
pass
|
|
||||||
confoverrides[key] = val
|
confoverrides[key] = val
|
||||||
|
|
||||||
for val in args.htmldefine:
|
for val in args.htmldefine:
|
||||||
@ -283,11 +271,7 @@ def build_main(argv=sys.argv[1:]): # type: ignore
|
|||||||
try:
|
try:
|
||||||
val = int(val)
|
val = int(val)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if likely_encoding and isinstance(val, binary_type):
|
pass
|
||||||
try:
|
|
||||||
val = val.decode(likely_encoding)
|
|
||||||
except UnicodeError:
|
|
||||||
pass
|
|
||||||
confoverrides['html_context.%s' % key] = val
|
confoverrides['html_context.%s' % key] = val
|
||||||
|
|
||||||
if args.nitpicky:
|
if args.nitpicky:
|
||||||
|
@ -35,7 +35,7 @@ except ImportError:
|
|||||||
USE_LIBEDIT = False
|
USE_LIBEDIT = False
|
||||||
|
|
||||||
from docutils.utils import column_width
|
from docutils.utils import column_width
|
||||||
from six import text_type, binary_type
|
from six import text_type
|
||||||
|
|
||||||
import sphinx.locale
|
import sphinx.locale
|
||||||
from sphinx import __display_version__, package_dir
|
from sphinx import __display_version__, package_dir
|
||||||
@ -644,11 +644,6 @@ def main(argv=sys.argv[1:]):
|
|||||||
print('[Interrupted.]')
|
print('[Interrupted.]')
|
||||||
return 130 # 128 + SIGINT
|
return 130 # 128 + SIGINT
|
||||||
|
|
||||||
# decode values in d if value is a Python string literal
|
|
||||||
for key, value in d.items():
|
|
||||||
if isinstance(value, binary_type):
|
|
||||||
d[key] = term_decode(value)
|
|
||||||
|
|
||||||
# handle use of CSV-style extension values
|
# handle use of CSV-style extension values
|
||||||
d.setdefault('extensions', [])
|
d.setdefault('extensions', [])
|
||||||
for ext in d['extensions'][:]:
|
for ext in d['extensions'][:]:
|
||||||
|
@ -17,9 +17,9 @@ from collections import OrderedDict
|
|||||||
from os import path, getenv
|
from os import path, getenv
|
||||||
from typing import Any, NamedTuple, Union
|
from typing import Any, NamedTuple, Union
|
||||||
|
|
||||||
from six import string_types, binary_type, text_type, integer_types
|
from six import string_types, text_type, integer_types
|
||||||
|
|
||||||
from sphinx.deprecation import RemovedInSphinx30Warning
|
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
||||||
from sphinx.errors import ConfigError, ExtensionError
|
from sphinx.errors import ConfigError, ExtensionError
|
||||||
from sphinx.locale import _, __
|
from sphinx.locale import _, __
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
@ -488,10 +488,13 @@ def check_unicode(config):
|
|||||||
"""check all string values for non-ASCII characters in bytestrings,
|
"""check all string values for non-ASCII characters in bytestrings,
|
||||||
since that can result in UnicodeErrors all over the place
|
since that can result in UnicodeErrors all over the place
|
||||||
"""
|
"""
|
||||||
|
warnings.warn('sphinx.config.check_unicode() is deprecated.',
|
||||||
|
RemovedInSphinx40Warning)
|
||||||
|
|
||||||
nonascii_re = re.compile(br'[\x80-\xff]')
|
nonascii_re = re.compile(br'[\x80-\xff]')
|
||||||
|
|
||||||
for name, value in config._raw_config.items():
|
for name, value in config._raw_config.items():
|
||||||
if isinstance(value, binary_type) and nonascii_re.search(value):
|
if isinstance(value, bytes) and nonascii_re.search(value):
|
||||||
logger.warning(__('the config value %r is set to a string with non-ASCII '
|
logger.warning(__('the config value %r is set to a string with non-ASCII '
|
||||||
'characters; this can lead to Unicode errors occurring. '
|
'characters; this can lead to Unicode errors occurring. '
|
||||||
'Please use Unicode strings, e.g. %r.'), name, u'Content')
|
'Please use Unicode strings, e.g. %r.'), name, u'Content')
|
||||||
|
@ -25,8 +25,6 @@ import sys
|
|||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
from six import binary_type
|
|
||||||
|
|
||||||
import sphinx.locale
|
import sphinx.locale
|
||||||
from sphinx import __display_version__, package_dir
|
from sphinx import __display_version__, package_dir
|
||||||
from sphinx.cmd.quickstart import EXTENSIONS
|
from sphinx.cmd.quickstart import EXTENSIONS
|
||||||
@ -444,15 +442,6 @@ def main(argv=sys.argv[1:]):
|
|||||||
if args.extensions:
|
if args.extensions:
|
||||||
d['extensions'].extend(args.extensions)
|
d['extensions'].extend(args.extensions)
|
||||||
|
|
||||||
if isinstance(args.header, binary_type):
|
|
||||||
d['project'] = d['project'].decode('utf-8')
|
|
||||||
if isinstance(args.author, binary_type):
|
|
||||||
d['author'] = d['author'].decode('utf-8')
|
|
||||||
if isinstance(args.version, binary_type):
|
|
||||||
d['version'] = d['version'].decode('utf-8')
|
|
||||||
if isinstance(args.release, binary_type):
|
|
||||||
d['release'] = d['release'].decode('utf-8')
|
|
||||||
|
|
||||||
if not args.dryrun:
|
if not args.dryrun:
|
||||||
qs.generate(d, silent=True, overwrite=args.force)
|
qs.generate(d, silent=True, overwrite=args.force)
|
||||||
elif args.tocfile:
|
elif args.tocfile:
|
||||||
|
@ -22,13 +22,13 @@ from docutils import nodes
|
|||||||
from docutils.parsers.rst import directives
|
from docutils.parsers.rst import directives
|
||||||
from packaging.specifiers import SpecifierSet, InvalidSpecifier
|
from packaging.specifiers import SpecifierSet, InvalidSpecifier
|
||||||
from packaging.version import Version
|
from packaging.version import Version
|
||||||
from six import StringIO, binary_type
|
from six import StringIO
|
||||||
|
|
||||||
import sphinx
|
import sphinx
|
||||||
from sphinx.builders import Builder
|
from sphinx.builders import Builder
|
||||||
from sphinx.deprecation import RemovedInSphinx40Warning
|
from sphinx.deprecation import RemovedInSphinx40Warning
|
||||||
from sphinx.locale import __
|
from sphinx.locale import __
|
||||||
from sphinx.util import force_decode, logging
|
from sphinx.util import logging
|
||||||
from sphinx.util.console import bold # type: ignore
|
from sphinx.util.console import bold # type: ignore
|
||||||
from sphinx.util.docutils import SphinxDirective
|
from sphinx.util.docutils import SphinxDirective
|
||||||
from sphinx.util.nodes import set_source_info
|
from sphinx.util.nodes import set_source_info
|
||||||
@ -330,8 +330,6 @@ class DocTestBuilder(Builder):
|
|||||||
logger.warning(text)
|
logger.warning(text)
|
||||||
else:
|
else:
|
||||||
logger.info(text, nonl=True)
|
logger.info(text, nonl=True)
|
||||||
if isinstance(text, binary_type):
|
|
||||||
text = force_decode(text, None)
|
|
||||||
self.outfile.write(text)
|
self.outfile.write(text)
|
||||||
|
|
||||||
def get_target_uri(self, docname, typ=None):
|
def get_target_uri(self, docname, typ=None):
|
||||||
|
@ -28,7 +28,7 @@ from time import mktime, strptime
|
|||||||
from urllib.parse import urlsplit, urlunsplit, quote_plus, parse_qsl, urlencode
|
from urllib.parse import urlsplit, urlunsplit, quote_plus, parse_qsl, urlencode
|
||||||
|
|
||||||
from docutils.utils import relative_path
|
from docutils.utils import relative_path
|
||||||
from six import text_type, binary_type
|
from six import text_type
|
||||||
|
|
||||||
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
|
||||||
from sphinx.errors import PycodeError, SphinxParallelError, ExtensionError
|
from sphinx.errors import PycodeError, SphinxParallelError, ExtensionError
|
||||||
@ -458,7 +458,7 @@ def parselinenos(spec, total):
|
|||||||
def force_decode(string, encoding):
|
def force_decode(string, encoding):
|
||||||
# type: (unicode, unicode) -> unicode
|
# type: (unicode, unicode) -> unicode
|
||||||
"""Forcibly get a unicode string out of a bytestring."""
|
"""Forcibly get a unicode string out of a bytestring."""
|
||||||
if isinstance(string, binary_type):
|
if isinstance(string, bytes):
|
||||||
try:
|
try:
|
||||||
if encoding:
|
if encoding:
|
||||||
string = string.decode(encoding)
|
string = string.decode(encoding)
|
||||||
|
@ -18,9 +18,8 @@ import sys
|
|||||||
import typing
|
import typing
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from six import StringIO, binary_type, string_types
|
from six import StringIO, string_types
|
||||||
|
|
||||||
from sphinx.util import force_decode
|
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
from sphinx.util.pycompat import NoneType
|
from sphinx.util.pycompat import NoneType
|
||||||
|
|
||||||
@ -249,8 +248,6 @@ def object_description(object):
|
|||||||
s = repr(object)
|
s = repr(object)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
if isinstance(s, binary_type):
|
|
||||||
s = force_decode(s, None) # type: ignore
|
|
||||||
# Strip non-deterministic memory addresses such as
|
# Strip non-deterministic memory addresses such as
|
||||||
# ``<__main__.A at 0x7f68cb685710>``
|
# ``<__main__.A at 0x7f68cb685710>``
|
||||||
s = memory_address_re.sub('', s)
|
s = memory_address_re.sub('', s)
|
||||||
|
Loading…
Reference in New Issue
Block a user