Module EDDecorator
[hide private]
[frames] | no frames]

Source Code for Module EDDecorator

 1  # coding: utf8 
 2  # 
 3  #    Project: The EDNA Kernel 
 4  #             http://www.edna-site.org 
 5  # 
 6  #    File: "$Id$" 
 7  # 
 8  #    Copyright (C) 2012 European Synchrotron Radiation Facility 
 9  #                       Grenoble, France 
10  # 
11  #    Principal authors: Jérome Kieffer (kieffer@esrf.fr) 
12  #                         
13  # 
14  #    This program is free software: you can redistribute it and/or modify 
15  #    it under the terms of the Lesser General Public License as published by 
16  #    the Free Software Foundation, either version 3 of the License, or 
17  #    (at your option) any later version. 
18  # 
19  #    This program is distributed in the hope that it will be useful, 
20  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
21  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
22  #    GNU General Public License for more details. 
23  # 
24  #    You should have received a copy of the GNU General Public License 
25  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
26  # 
27   
28  __authors__ = [ "Jérôme Kieffer" ] 
29  __contact__ = "kieffer@esrf.fr" 
30  __license__ = "LGPLv3+" 
31  __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" 
32  __date__ = "20120213" 
33   
34  import os, traceback, time 
35  from EDVerbose import EDVerbose 
36   
37 -def deprecated(func):
38 def wrapper(*arg, **kw): 39 """ 40 decorator that deprecates the use of a function 41 """ 42 EDVerbose.WARNING("%s is Deprecated !!! %s" % (func.func_name, os.linesep.join([""] + traceback.format_stack()[:-1]))) 43 return func(*arg, **kw)
44 return wrapper 45 46
47 -def timeit(func):
48 def wrapper(*arg, **kw): 49 '''This is the docstring from timeit: 50 a decorator that prints the execution time''' 51 t1 = time.time() 52 res = func(*arg, **kw) 53 EDVerbose.WARNING("%s took %.3fs" % (func.func_name, time.time() - t1)) 54 return res
55 return wrapper 56