equal
deleted
inserted
replaced
21 defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', |
21 defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M', |
22 '%a %b %d %H:%M:%S %Y') |
22 '%a %b %d %H:%M:%S %Y') |
23 |
23 |
24 class SignalInterrupt(Exception): |
24 class SignalInterrupt(Exception): |
25 """Exception raised on SIGTERM and SIGHUP.""" |
25 """Exception raised on SIGTERM and SIGHUP.""" |
|
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 |
26 |
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') |
30 def writer(): |
46 def writer(): |