Show More
@@ -42,7 +42,24 b' class CannedObject(object):' | |||
|
42 | 42 | setattr(self.obj, key, uncan(getattr(self.obj, key), g)) |
|
43 | 43 | return self.obj |
|
44 | 44 | |
|
45 | ||
|
45 | class Reference(CannedObject): | |
|
46 | """object for wrapping a remote reference by name.""" | |
|
47 | def __init__(self, name): | |
|
48 | if not isinstance(name, basestring): | |
|
49 | raise TypeError("illegal name: %r"%name) | |
|
50 | self.name = name | |
|
51 | ||
|
52 | def __repr__(self): | |
|
53 | return "<Reference: %r>"%self.name | |
|
54 | ||
|
55 | def getObject(self, g=None): | |
|
56 | if g is None: | |
|
57 | g = globals() | |
|
58 | try: | |
|
59 | return g[self.name] | |
|
60 | except KeyError: | |
|
61 | raise NameError("name %r is not defined"%self.name) | |
|
62 | ||
|
46 | 63 | |
|
47 | 64 | class CannedFunction(CannedObject): |
|
48 | 65 | |
@@ -54,7 +71,7 b' class CannedFunction(CannedObject):' | |||
|
54 | 71 | def _checkType(self, obj): |
|
55 | 72 | assert isinstance(obj, FunctionType), "Not a function type" |
|
56 | 73 | |
|
57 |
def get |
|
|
74 | def getObject(self, g=None): | |
|
58 | 75 | if g is None: |
|
59 | 76 | g = globals() |
|
60 | 77 | newFunc = FunctionType(self.code, g) |
@@ -66,11 +83,11 b' class CannedFunction(CannedObject):' | |||
|
66 | 83 | |
|
67 | 84 | |
|
68 | 85 | def can(obj): |
|
69 |
if isinstance(obj, |
|
|
70 | return CannedFunction(obj) | |
|
71 | elif isinstance(obj, dependent): | |
|
86 | if isinstance(obj, dependent): | |
|
72 | 87 | keys = ('f','df') |
|
73 | 88 | return CannedObject(obj, keys=keys) |
|
89 | elif isinstance(obj, FunctionType): | |
|
90 | return CannedFunction(obj) | |
|
74 | 91 | elif isinstance(obj,dict): |
|
75 | 92 | return canDict(obj) |
|
76 | 93 | elif isinstance(obj, (list,tuple)): |
@@ -95,9 +112,7 b' def canSequence(obj):' | |||
|
95 | 112 | return obj |
|
96 | 113 | |
|
97 | 114 | def uncan(obj, g=None): |
|
98 |
if isinstance(obj, Canned |
|
|
99 | return obj.getFunction(g) | |
|
100 | elif isinstance(obj, CannedObject): | |
|
115 | if isinstance(obj, CannedObject): | |
|
101 | 116 | return obj.getObject(g) |
|
102 | 117 | elif isinstance(obj,dict): |
|
103 | 118 | return uncanDict(obj, g) |
@@ -24,6 +24,7 b' import zmq' | |||
|
24 | 24 | # from zmq.eventloop import ioloop, zmqstream |
|
25 | 25 | |
|
26 | 26 | from IPython.utils.path import get_ipython_dir |
|
27 | from IPython.utils.pickleutil import Reference | |
|
27 | 28 | from IPython.utils.traitlets import (HasTraits, Int, Instance, CUnicode, |
|
28 | 29 | Dict, List, Bool, Str, Set) |
|
29 | 30 | from IPython.external.decorator import decorator |
General Comments 0
You need to be logged in to leave comments.
Login now