diff options
author | ttt | 2017-05-13 00:29:47 +0530 |
---|---|---|
committer | ttt | 2017-05-13 00:29:47 +0530 |
commit | abf599be33b383a6a5baf9493093b2126a622ac8 (patch) | |
tree | 4c5ab6e0d935d5e65fabcf0258e4a00dd20a5afa /lib/python2.7/site-packages/django/utils/deprecation.py | |
download | SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.gz SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.bz2 SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.zip |
added all server files
Diffstat (limited to 'lib/python2.7/site-packages/django/utils/deprecation.py')
-rw-r--r-- | lib/python2.7/site-packages/django/utils/deprecation.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/python2.7/site-packages/django/utils/deprecation.py b/lib/python2.7/site-packages/django/utils/deprecation.py new file mode 100644 index 0000000..edbb5ca --- /dev/null +++ b/lib/python2.7/site-packages/django/utils/deprecation.py @@ -0,0 +1,62 @@ +import inspect +import warnings + + +class warn_about_renamed_method(object): + def __init__(self, class_name, old_method_name, new_method_name, deprecation_warning): + self.class_name = class_name + self.old_method_name = old_method_name + self.new_method_name = new_method_name + self.deprecation_warning = deprecation_warning + + def __call__(self, f): + def wrapped(*args, **kwargs): + warnings.warn( + "`%s.%s` is deprecated, use `%s` instead." % + (self.class_name, self.old_method_name, self.new_method_name), + self.deprecation_warning, 2) + return f(*args, **kwargs) + return wrapped + + +class RenameMethodsBase(type): + """ + Handles the deprecation paths when renaming a method. + + It does the following: + 1) Define the new method if missing and complain about it. + 2) Define the old method if missing. + 3) Complain whenever an old method is called. + + See #15363 for more details. + """ + + renamed_methods = () + + def __new__(cls, name, bases, attrs): + new_class = super(RenameMethodsBase, cls).__new__(cls, name, bases, attrs) + + for base in inspect.getmro(new_class): + class_name = base.__name__ + for renamed_method in cls.renamed_methods: + old_method_name = renamed_method[0] + old_method = base.__dict__.get(old_method_name) + new_method_name = renamed_method[1] + new_method = base.__dict__.get(new_method_name) + deprecation_warning = renamed_method[2] + wrapper = warn_about_renamed_method(class_name, *renamed_method) + + # Define the new method if missing and complain about it + if not new_method and old_method: + warnings.warn( + "`%s.%s` method should be renamed `%s`." % + (class_name, old_method_name, new_method_name), + deprecation_warning, 2) + setattr(base, new_method_name, old_method) + setattr(base, old_method_name, wrapper(old_method)) + + # Define the old method as a wrapped call to the new method. + if not old_method and new_method: + setattr(base, old_method_name, wrapper(new_method)) + + return new_class |