Show More
@@ -24,6 +24,22 defaultdateformats = ('%Y-%m-%d %H:%M:%S | |||||
24 | class SignalInterrupt(Exception): |
|
24 | class SignalInterrupt(Exception): | |
25 | """Exception raised on SIGTERM and SIGHUP.""" |
|
25 | """Exception raised on SIGTERM and SIGHUP.""" | |
26 |
|
26 | |||
|
27 | def cachefunc(func): | |||
|
28 | '''cache the result of function calls''' | |||
|
29 | cache = {} | |||
|
30 | if func.func_code.co_argcount == 1: | |||
|
31 | def f(arg): | |||
|
32 | if arg not in cache: | |||
|
33 | cache[arg] = func(arg) | |||
|
34 | return cache[arg] | |||
|
35 | else: | |||
|
36 | def f(*args): | |||
|
37 | if args not in cache: | |||
|
38 | cache[args] = func(*args) | |||
|
39 | return cache[args] | |||
|
40 | ||||
|
41 | return f | |||
|
42 | ||||
27 | def pipefilter(s, cmd): |
|
43 | def pipefilter(s, cmd): | |
28 | '''filter string S through command CMD, returning its output''' |
|
44 | '''filter string S through command CMD, returning its output''' | |
29 | (pout, pin) = popen2.popen2(cmd, -1, 'b') |
|
45 | (pout, pin) = popen2.popen2(cmd, -1, 'b') |
General Comments 0
You need to be logged in to leave comments.
Login now