コード例 #1
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)
コード例 #2
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)
コード例 #3
0
ファイル: moves.py プロジェクト: dx-entity/env_controller
 def wrapper(wrapped, instance, args, kwargs):
     base_name = _utils.get_class_name(wrapped, fully_qualified=False)
     if fully_qualified:
         old_name = old_attribute_name
     else:
         old_name = ".".join((base_name, old_attribute_name))
     new_name = ".".join((base_name, new_attribute_name))
     prefix = _KIND_MOVED_PREFIX_TPL % (kind, old_name, new_name)
     out_message = _utils.generate_message(
         prefix, message=message,
         version=version, removal_version=removal_version)
     _utils.deprecation(out_message, stacklevel=stacklevel,
                        category=category)
     return wrapped(*args, **kwargs)
コード例 #4
0
ファイル: moves.py プロジェクト: root79-glit/BlueWhale
 def wrapper(self, *args, **kwargs):
     base_name = _utils.get_class_name(self, fully_qualified=False)
     if fully_qualified:
         old_name = old_attribute_name
     else:
         old_name = ".".join((base_name, old_attribute_name))
     new_name = ".".join((base_name, new_attribute_name))
     prefix = _KIND_MOVED_PREFIX_TPL % (kind, old_name, new_name)
     out_message = _utils.generate_message(
         prefix,
         message=message,
         version=version,
         removal_version=removal_version)
     _utils.deprecation(out_message,
                        stacklevel=stacklevel,
                        category=category)
     return f(self, *args, **kwargs)
コード例 #5
0
ファイル: moves.py プロジェクト: root79-glit/BlueWhale
def moved_class(new_class,
                old_class_name,
                old_module_name,
                message=None,
                version=None,
                removal_version=None,
                stacklevel=3,
                category=None):
    """Deprecates a class that was moved to another location.

    This creates a 'new-old' type that can be used for a
    deprecation period that can be inherited from. This will emit warnings
    when the old locations class is initialized, telling where the new and
    improved location for the old class now is.
    """

    if not inspect.isclass(new_class):
        _qual, type_name = _utils.get_qualified_name(type(new_class))
        raise TypeError("Unexpected class type '%s' (expected"
                        " class type only)" % type_name)

    old_name = ".".join((old_module_name, old_class_name))
    new_name = _utils.get_class_name(new_class)
    prefix = _CLASS_MOVED_PREFIX_TPL % (old_name, new_name)
    out_message = _utils.generate_message(prefix,
                                          message=message,
                                          version=version,
                                          removal_version=removal_version)

    def decorator(f):
        @six.wraps(f, assigned=("__name__", "__doc__"))
        def wrapper(self, *args, **kwargs):
            _utils.deprecation(out_message,
                               stacklevel=stacklevel,
                               category=category)
            return f(self, *args, **kwargs)

        return wrapper

    old_class = type(old_class_name, (new_class, ), {})
    old_class.__module__ = old_module_name
    old_class.__init__ = decorator(old_class.__init__)
    return old_class
コード例 #6
0
ファイル: moves.py プロジェクト: dx-entity/env_controller
def moved_class(new_class, old_class_name, old_module_name,
                message=None, version=None, removal_version=None,
                stacklevel=3, category=None):
    """Deprecates a class that was moved to another location.

    This creates a 'new-old' type that can be used for a
    deprecation period that can be inherited from. This will emit warnings
    when the old locations class is initialized, telling where the new and
    improved location for the old class now is.
    """

    if not inspect.isclass(new_class):
        _qual, type_name = _utils.get_qualified_name(type(new_class))
        raise TypeError("Unexpected class type '%s' (expected"
                        " class type only)" % type_name)

    old_name = ".".join((old_module_name, old_class_name))
    new_name = _utils.get_class_name(new_class)
    prefix = _CLASS_MOVED_PREFIX_TPL % (old_name, new_name)
    out_message = _utils.generate_message(
        prefix, message=message, version=version,
        removal_version=removal_version)

    def decorator(f):

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

        return wrapper

    old_class = type(old_class_name, (new_class,), {})
    old_class.__module__ = old_module_name
    old_class.__init__ = decorator(old_class.__init__)
    return old_class