4 Utility functions for extensions
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2008 Anthony Towns <ajt@dbeian.org>
8 @license: GNU General Public License version 2 or later
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 dak_functions_to_replace = {}
26 dak_replaced_functions = {}
28 def replace_dak_function(module, name):
30 Decorator to make a function replace a standard dak function
34 @param module: name of module where replaced function is in
37 @param name: name of the function to replace
43 f(dak_replaced_functions[name], *a, **kw)
44 myfunc.__name__ = f.__name__
45 myfunc.__doc__ = f.__doc__
46 myfunc.__dict__.update(f.__dict__)
48 fnname = "%s:%s" % (module, name)
49 if fnname in dak_functions_to_replace:
51 "%s in %s already marked to be replaced" % (name, module)
52 dak_functions_to_replace["%s:%s" % (module,name)] = myfunc
56 ################################################################################
58 def init(name, module, userext):
59 global dak_replaced_functions
61 # This bit should be done automatically too
62 dak_replaced_functions = {}
63 for f,newfunc in dak_functions_to_replace.iteritems():
65 if len(f) > 0 and m == name:
66 dak_replaced_functions[f] = module.__dict__[f]
67 module.__dict__[f] = newfunc