diff options
| author | Sergey Shepelev <temotor@gmail.com> | 2016-12-22 04:35:14 +0300 |
|---|---|---|
| committer | Sergey Shepelev <temotor@gmail.com> | 2017-01-04 23:42:32 +0300 |
| commit | e4049a8a0016b28cbbdf3ab01425fc92a623e380 (patch) | |
| tree | 58d140b6e9f784e5b28a0435fb41ae8f238984af /eventlet/support | |
| parent | 461348f9a8459724be87c281eea4e0408138a82c (diff) | |
| download | eventlet-is-timeout.tar.gz | |
WIP https://github.com/eventlet/eventlet/pull/346is-timeout
Diffstat (limited to 'eventlet/support')
| -rw-r--r-- | eventlet/support/__init__.py | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/eventlet/support/__init__.py b/eventlet/support/__init__.py index 4c2b75d..b311c8a 100644 --- a/eventlet/support/__init__.py +++ b/eventlet/support/__init__.py @@ -1,9 +1,15 @@ +import inspect +import functools import sys -from contextlib import contextmanager +import warnings +import contextlib from eventlet.support import greenlets, six +_MISSING = object() + + def get_errno(exc): """ Get the error code out of socket.error objects. socket.error in <2.5 does not have errno attribute @@ -43,7 +49,8 @@ else: PY33 = sys.version_info[:2] == (3, 3) -@contextmanager + +@contextlib.contextmanager def capture_stderr(): stream = six.StringIO() original = sys.stderr @@ -53,3 +60,30 @@ def capture_stderr(): finally: sys.stderr = original stream.seek(0) + + +def wrap_deprecated(old, new): + def _resolve(s): + return 'eventlet.'+s if '.' not in s else s + msg = '''\ +{old} is deprecated and will be removed in next version. Use {new} instead. +Autoupgrade: fgrep -rl '{old}' . |xargs -t sed --in-place='' -e 's/{old}/{new}/' +'''.format(old=_resolve(old), new=_resolve(new)) + + def wrapper(base): + klass = None + if inspect.isclass(base): + klass = base + base = klass.__init__ + + @functools.wraps(base) + def wrapped(*a, **kw): + warnings.warn(msg, DeprecationWarning, stacklevel=5) + return base(*a, **kw) + + if klass is not None: + klass.__init__ = wrapped + return klass + + return wrapped + return wrapper |
