diff --git a/CHANGES b/CHANGES index 11f62c501..cb94800ec 100644 --- a/CHANGES +++ b/CHANGES @@ -36,6 +36,7 @@ Deprecated * ``Config.__init__()`` has changed; the *dirname*, *filename* and *tags* argument has been deprecated * ``Config.check_types()`` is deprecated +* ``Config.check_unicode()`` is deprecated For more details, see `deprecation APIs list `_ diff --git a/doc/extdev/index.rst b/doc/extdev/index.rst index bc79394cc..192f6891a 100644 --- a/doc/extdev/index.rst +++ b/doc/extdev/index.rst @@ -113,6 +113,11 @@ The following is a list of deprecated interface. - (will be) Removed - Alternatives + * - ``Config.check_unicode()`` + - 1.8 + - 3.0 + - ``sphinx.config.check_unicode()`` + * - ``Config.check_types()`` - 1.8 - 3.0 diff --git a/sphinx/application.py b/sphinx/application.py index 91302e6e0..eaa5f8ccd 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -26,7 +26,7 @@ from six.moves import cStringIO import sphinx from sphinx import package_dir, locale -from sphinx.config import Config +from sphinx.config import Config, check_unicode from sphinx.deprecation import RemovedInSphinx20Warning, RemovedInSphinx30Warning from sphinx.environment import BuildEnvironment from sphinx.errors import ApplicationError, ConfigError, VersionRequirementError @@ -190,8 +190,7 @@ class Sphinx(object): else: self.config = Config.read(path.join(self.confdir, CONFIG_FILENAME), confoverrides or {}, self.tags) - self.config.check_unicode() - # defer checking types until i18n has been initialized + check_unicode(self.config) # initialize some limited config variables before initialize i18n and loading # extensions diff --git a/sphinx/config.py b/sphinx/config.py index 4e6585334..d1ef82ee4 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -34,7 +34,6 @@ if False: logger = logging.getLogger(__name__) -nonascii_re = re.compile(br'[\x80-\xff]') copyright_year_re = re.compile(r'^((\d{4}-)?)(\d{4})(?=[ ,])') if PY3: @@ -196,13 +195,9 @@ class Config(object): def check_unicode(self): # type: () -> None - # check all string values for non-ASCII characters in bytestrings, - # since that can result in UnicodeErrors all over the place - for name, value in iteritems(self._raw_config): - if isinstance(value, binary_type) and nonascii_re.search(value): - logger.warning(__('the config value %r is set to a string with non-ASCII ' - 'characters; this can lead to Unicode errors occurring. ' - 'Please use Unicode strings, e.g. %r.'), name, u'Content') + warnings.warn('Config.check_unicode() is deprecated. Use check_unicode() instead.', + RemovedInSphinx30Warning) + check_unicode(self) def convert_overrides(self, name, value): # type: (unicode, Any) -> Any @@ -434,6 +429,20 @@ def check_confval_types(app, config): default=type(default))) +def check_unicode(config): + # type: (Config) -> None + """check all string values for non-ASCII characters in bytestrings, + since that can result in UnicodeErrors all over the place + """ + nonascii_re = re.compile(br'[\x80-\xff]') + + for name, value in iteritems(config._raw_config): + if isinstance(value, binary_type) and nonascii_re.search(value): + logger.warning(__('the config value %r is set to a string with non-ASCII ' + 'characters; this can lead to Unicode errors occurring. ' + 'Please use Unicode strings, e.g. %r.'), name, u'Content') + + def setup(app): # type: (Sphinx) -> Dict[unicode, Any] app.connect('config-inited', convert_source_suffix)