# took codes from the following:##- [Python Wiki - Smart deprecation warnings ](http://wiki.python.org/moin/PythonDecoratorLibrary#Smart_deprecation_warnings_.28with_valid_filenames.2C_line_numbers.2C_etc..29)# - [Active Code Stack - deprecated ](http://code.activestate.com/recipes/391367-deprecated/)importosimportwarningsimportfunctools# enable to show warringwarnings.simplefilter('default')defdeprecated(replacement=None):"""This is a decorator which can be used to mark functions as deprecated. It will result in a warning being emitted when the function is used. ref: - recipe-391367-1 on active stack code - recipe-577819-1 on active stack code @replacement function replacement function """defwrapper(old_func):wrapped_func=replacementandreplacementorold_func@functools.wraps(wrapped_func)defnew_func(*args,**kwargs):msg="Call to deprecated function %(funcname)s."%{'funcname':old_func.__name__}ifreplacement:msg+="; use {} instead".format(replacement.__name__)warnings.warn_explicit(msg,category=DeprecationWarning,filename=old_func.func_code.co_filename,lineno=old_func.func_code.co_firstlineno+1)returnwrapped_func(*args,**kwargs)returnnew_funcreturnwrapperdefnew1():print'called new1'@deprecated()defold1():print'called old1'@deprecated(new1)defold2():print'called old1'if__name__=='__main__':printold1old1()printold2old2()