Restore pycompat API. Fixes #1726.

All compatibility helpers which have been in this module should be
resurrected -- and, at the same time, deprecated -- to grant
backwards-compatibility with older Sphinx versions to third-party
extensions.

This does NOT restore compatibility with any older Python versions.
This commit is contained in:
Robert Lehmann 2015-02-14 10:17:04 +01:00
parent 193aadb140
commit b61640959d

View File

@ -76,7 +76,7 @@ else:
return self.__unicode__().encode('utf8')
def execfile_(filepath, _globals):
def execfile_(filepath, _globals, open=open):
from sphinx.util.osutil import fs_encoding
# get config source -- 'b' is a no-op under 2.x, while 'U' is
# ignored under 3.x (but 3.x compile() accepts \r\n newlines)
@ -103,3 +103,33 @@ def execfile_(filepath, _globals):
else:
raise
exec_(code, _globals)
# ------------------------------------------------------------------------------
# Internal module backwards-compatibility
import functools
import warnings
def _deprecated(func):
@functools.wraps(func)
def wrapped(*args, **kwargs):
warnings.warn("sphinx.util.pycompat.{0.__name__} is deprecated, "
"please use the standard library version.".format(func),
DeprecationWarning, stacklevel=2)
func(*args, **kwargs)
return wrapped
from six import class_types
from six.moves import zip_longest
from itertools import product
zip_longest = _deprecated(zip_longest)
product = _deprecated(product)
all = _deprecated(all)
any = _deprecated(any)
next = _deprecated(next)
open = _deprecated(open)
base_exception = BaseException
relpath = _deprecated(__import__('os').path.relpath)