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