# HG changeset patch # User Edouard Tisserant # Date 1517584945 -3600 # Node ID 65edbc03fdbf118d06fb4ebfcad93d8c04957f73 # Parent 5353f4086a45b6040ce0c584393b7c4c11e58601 ClassImporter now accepts string, callable or class, for compatibility with some old extensions. diff -r 5353f4086a45 -r 65edbc03fdbf util/misc.py --- a/util/misc.py Fri Feb 02 11:12:03 2018 +0100 +++ b/util/misc.py Fri Feb 02 16:22:25 2018 +0100 @@ -46,21 +46,26 @@ return False return True -def GetClassImporter(classpath): +def GetClassImporter(param): """ is used to resolve library class names in features.py - returns a callable that return the class pointed by classpath string - if a class is given instead of string, then returns a callable returning it. + if param is a string, returns a callable that return the class pointed by param + if a class is given, then returns a callable that returns the given class. """ - if isinstance(classpath, str): + if isinstance(param, str): def factory(): # on-demand import, only when using class - mod = __import__(classpath.rsplit('.', 1)[0]) - return reduce(getattr, classpath.split('.')[1:], mod) + mod = __import__(param.rsplit('.', 1)[0]) + return reduce(getattr, param.split('.')[1:], mod) return factory + elif isinstance(param,types.ClassType): + return lambda : param else: - return classpath + # backward compatibility + # for old extensions that pass some callables + # deprecated, should not be used anymore + return param def InstallLocalRessources(CWD):