コード例 #1
0
ファイル: moves.py プロジェクト: dx-entity/env_controller
def moved_function(new_func, old_func_name, old_module_name,
                   message=None, version=None, removal_version=None,
                   stacklevel=3, category=None):
    """Deprecates a function that was moved to another location.

    This generates a wrapper around ``new_func`` that will emit a deprecation
    warning when called. The warning message will include the new location
    to obtain the function from.
    """
    new_func_full_name = _utils.get_callable_name(new_func)
    new_func_full_name += _MOVED_CALLABLE_POSTFIX
    old_func_full_name = ".".join([old_module_name, old_func_name])
    old_func_full_name += _MOVED_CALLABLE_POSTFIX
    prefix = _FUNC_MOVED_PREFIX_TPL % (old_func_full_name, new_func_full_name)
    out_message = _utils.generate_message(prefix,
                                          message=message, version=version,
                                          removal_version=removal_version)

    @six.wraps(new_func, assigned=_utils.get_assigned(new_func))
    def old_new_func(*args, **kwargs):
        _utils.deprecation(out_message, stacklevel=stacklevel,
                           category=category)
        return new_func(*args, **kwargs)

    old_new_func.__name__ = old_func_name
    old_new_func.__module__ = old_module_name
    return old_new_func
コード例 #2
0
ファイル: moves.py プロジェクト: root79-glit/BlueWhale
def moved_function(new_func,
                   old_func_name,
                   old_module_name,
                   message=None,
                   version=None,
                   removal_version=None,
                   stacklevel=3,
                   category=None):
    """Deprecates a function that was moved to another location.

    This generates a wrapper around ``new_func`` that will emit a deprecation
    warning when called. The warning message will include the new location
    to obtain the function from.
    """
    new_func_full_name = _utils.get_callable_name(new_func)
    new_func_full_name += _MOVED_CALLABLE_POSTFIX
    old_func_full_name = ".".join([old_module_name, old_func_name])
    old_func_full_name += _MOVED_CALLABLE_POSTFIX
    prefix = _FUNC_MOVED_PREFIX_TPL % (old_func_full_name, new_func_full_name)
    out_message = _utils.generate_message(prefix,
                                          message=message,
                                          version=version,
                                          removal_version=removal_version)

    @six.wraps(new_func)
    def old_new_func(*args, **kwargs):
        _utils.deprecation(out_message,
                           stacklevel=stacklevel,
                           category=category)
        return new_func(*args, **kwargs)

    old_new_func.__name__ = old_func_name
    old_new_func.__module__ = old_module_name
    return old_new_func
コード例 #3
0
 def wrapper(f, instance, args, kwargs):
     qualified, f_name = _utils.get_qualified_name(f)
     if qualified:
         if inspect.isclass(f):
             prefix_pre = "Using class"
             thing_post = ''
         else:
             prefix_pre = "Using function/method"
             thing_post = '()'
     if not qualified:
         prefix_pre = "Using function/method"
         base_name = None
         if instance is None:
             # Decorator was used on a class
             if inspect.isclass(f):
                 prefix_pre = "Using class"
                 thing_post = ''
                 module_name = _get_module_name(inspect.getmodule(f))
                 if module_name == '__main__':
                     f_name = _utils.get_class_name(
                         f, fully_qualified=False)
                 else:
                     f_name = _utils.get_class_name(
                         f, fully_qualified=True)
             # Decorator was a used on a function
             else:
                 thing_post = '()'
                 module_name = _get_module_name(inspect.getmodule(f))
                 if module_name != '__main__':
                     f_name = _utils.get_callable_name(f)
         # Decorator was used on a classmethod or instancemethod
         else:
             thing_post = '()'
             base_name = _utils.get_class_name(instance,
                                               fully_qualified=False)
         if base_name:
             thing_name = ".".join([base_name, f_name])
         else:
             thing_name = f_name
     else:
         thing_name = f_name
     if thing_post:
         thing_name += thing_post
     prefix = prefix_pre + " '%s' is deprecated" % (thing_name)
     out_message = _utils.generate_message(
         prefix,
         version=version,
         removal_version=removal_version,
         message=message)
     _utils.deprecation(out_message,
                        stacklevel=stacklevel, category=category)
     return f(*args, **kwargs)
コード例 #4
0
 def wrapper(f, instance, args, kwargs):
     qualified, f_name = _utils.get_qualified_name(f)
     if qualified:
         if inspect.isclass(f):
             prefix_pre = "Using class"
             thing_post = ''
         else:
             prefix_pre = "Using function/method"
             thing_post = '()'
     if not qualified:
         prefix_pre = "Using function/method"
         base_name = None
         if instance is None:
             # Decorator was used on a class
             if inspect.isclass(f):
                 prefix_pre = "Using class"
                 thing_post = ''
                 module_name = _get_qualified_name(inspect.getmodule(f))
                 if module_name == '__main__':
                     f_name = _utils.get_class_name(
                         f, fully_qualified=False)
                 else:
                     f_name = _utils.get_class_name(
                         f, fully_qualified=True)
             # Decorator was a used on a function
             else:
                 thing_post = '()'
                 module_name = _get_qualified_name(inspect.getmodule(f))
                 if module_name != '__main__':
                     f_name = _utils.get_callable_name(f)
         # Decorator was used on a classmethod or instancemethod
         else:
             thing_post = '()'
             base_name = _utils.get_class_name(instance,
                                               fully_qualified=False)
         if base_name:
             thing_name = ".".join([base_name, f_name])
         else:
             thing_name = f_name
     else:
         thing_name = f_name
     if thing_post:
         thing_name += thing_post
     prefix = prefix_pre + " '%s' is deprecated" % (thing_name)
     out_message = _utils.generate_message(
         prefix,
         version=version,
         removal_version=removal_version,
         message=message)
     _utils.deprecation(out_message,
                        stacklevel=stacklevel, category=category)
     return f(*args, **kwargs)