| 1 | from rpython.rlib.objectmodel import specialize |
| 2 | |
| 3 | |
| 4 | class AppBridgeCache(object): |
| 5 | w__mean = None |
| 6 | w__var = None |
| 7 | w__std = None |
| 8 | w__commastring = None |
| 9 | w_array_repr = None |
| 10 | w_array_str = None |
| 11 | w__usefields = None |
| 12 | w_partition = None |
| 13 | |
| 14 | def __init__(self, space): |
| 15 | pass |
| 16 | |
| 17 | @specialize.arg(3) |
| 18 | def call_method(self, space, path, name, args): |
| 19 | w_method = getattr(self, 'w_' + name) |
| 20 | if w_method is None: |
| 21 | w_method = space.appexec([space.newtext(path), space.newtext(name)], |
| 22 | "(path, name): return getattr(__import__(path, fromlist=[name]), name)") |
| 23 | setattr(self, 'w_' + name, w_method) |
| 24 | return space.call_args(w_method, args) |
| 25 | |
| 26 | |
| 27 | def set_string_function(space, w_f, w_repr): |
| 28 | cache = get_appbridge_cache(space) |
| 29 | if space.is_true(w_repr): |
| 30 | cache.w_array_repr = w_f |
| 31 | else: |
| 32 | cache.w_array_str = w_f |
| 33 | |
| 34 | |
| 35 | def get_appbridge_cache(space): |
| 36 | return space.fromcache(AppBridgeCache) |