From: Fredrik Tolf Date: Sun, 13 Apr 2014 14:27:40 +0000 (+0200) Subject: Merge branch 'master' into python3 X-Git-Url: http://www.dolda2000.com/gitweb/?p=pdm.git;a=commitdiff_plain;h=86b3a0acd5fd18f7816ae91e2839ead5dfab0e33 Merge branch 'master' into python3 --- 86b3a0acd5fd18f7816ae91e2839ead5dfab0e33 diff --cc pdm/perf.py index bad3112,f0e6c89..fd4daa6 --- a/pdm/perf.py +++ b/pdm/perf.py @@@ -165,8 -165,32 +165,32 @@@ class staticdir(perfobj) return self.map[name] def pdm_protocols(self): - return super(staticdir, self).pdm_protocols() + ["dir"] + return super().pdm_protocols() + ["dir"] + class simplefunc(perfobj): + """An implementation of the `invoke' interface. Put callables in + it using the normal dict assignment syntax, and it will call them + when invoked with the corresponding method name. Additionally, it + updates itself with any keyword-arguments it is initialized with.""" + def __init__(self, *args, **kwargs): - super(simplefunc, self).__init__(*args) ++ super().__init__(*args) + self.map = {} + self.map.update(kwargs) + + def __setitem__(self, name, func): + self.map[name] = func + + def __delitem__(self, name): + del self.map[name] + + def invoke(self, method, *args, **kwargs): + if method not in self.map: + raise AttributeError(method) + self.map[method](*args, **kwargs) + + def pdm_protocols(self): - return super(simplefunc, self).pdm_protocols() + ["invoke"] ++ return super().pdm_protocols() + ["invoke"] + class event(object): """This class should be subclassed by all event objects sent via the `event' interface. Its main utility is that it keeps track of