From b61640959d751d5d124c22f1f08b844e05a88dff Mon Sep 17 00:00:00 2001 From: Robert Lehmann Date: Sat, 14 Feb 2015 10:17:04 +0100 Subject: [PATCH] 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. --- sphinx/util/pycompat.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 28ab1b75c..75ba1c4fc 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -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)