5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | |
def patch(namespace, name, value): |
""" rebind the 'name' on the 'namespace' to the 'value', |
possibly and remember the original value. Multiple |
invocations to the same namespace/name pair will |
remember a list of old values. |
""" |
nref = (namespace, name) |
orig = getattr(namespace, name) |
patched.setdefault(nref, []).append(orig) |
setattr(namespace, name, value) |
return orig | |