@@ -58,6 +58,7 @@ def __call__():
5858 if init :
5959 init .apply (None , arguments )
6060 return object
61+ __call__ .pythonscript_function = True
6162 klass .__call__ = __call__
6263 return klass
6364
@@ -89,7 +90,6 @@ def get_attribute(object, attribute):
8990 if cached :
9091 return cached
9192 else :
92- #print 'generating new wrapper'
9393 def wrapper (args ,kwargs ): return object .apply (None , args )
9494 wrapper .is_wrapper = True
9595 object .cached_wrapper = wrapper
@@ -116,7 +116,16 @@ def wrapper(args,kwargs): return attr.apply(object, args)
116116 return attr
117117
118118 if attr : ## what about cases where attr is zero?
119- return attr
119+ if JS ("typeof(attr) === 'function' && attr.pythonscript_function === undefined && attr.is_wrapper === undefined" ):
120+ ## to avoid problems with other generated wrapper funcs not marked with:
121+ ## F.pythonscript_function or F.is_wrapper, we could check if object has these props:
122+ ## bases, __name__, __dict__, __call__
123+ #print 'wrapping something external', object, attribute
124+ def wrapper (args ,kwargs ): return attr .apply (object , args )
125+ wrapper .is_wrapper = True
126+ return wrapper
127+ else :
128+ return attr
120129
121130 var (__class__ , __dict__ , __get__ , bases )
122131
@@ -199,6 +208,26 @@ def method():
199208 return method
200209 else :
201210 return attr
211+
212+ if JS ('object instanceof Array' ):
213+ if attribute == '__getitem__' :
214+ def wrapper (args ,kwargs ): return object [ args [0 ] ]
215+ wrapper .is_wrapper = True
216+ return wrapper
217+ elif attribute == '__setitem__' :
218+ def wrapper (args ,kwargs ): object [ args [0 ] ] = args [1 ]
219+ wrapper .is_wrapper = True
220+ return wrapper
221+
222+ elif attribute == '__getitem__' : ## this should be a JSObject - or anything else - is this always safe?
223+ def wrapper (args ,kwargs ): return object [ args [0 ] ]
224+ wrapper .is_wrapper = True
225+ return wrapper
226+ elif attribute == '__setitem__' :
227+ def wrapper (args ,kwargs ): object [ args [0 ] ] = args [1 ]
228+ wrapper .is_wrapper = True
229+ return wrapper
230+
202231 return None # XXX: raise AttributeError instead
203232
204233
@@ -230,6 +259,7 @@ def set_attribute(object, attribute, value):
230259 __dict__ [attribute ] = value
231260 else :
232261 object [attribute ] = value
262+ set_attribute .pythonscript_function = True
233263
234264
235265def get_arguments (signature , args , kwargs ):
@@ -281,15 +311,15 @@ def get_arguments(signature, args, kwargs):
281311 if signature .varkwarg :
282312 out [signature .varkwarg ] = kwargs
283313 return out
284-
314+ get_arguments . pythonscript_function = True
285315
286316def type (args , kwargs ):
287317 var (class_name , parents , attrs )
288318 class_name = args [0 ]
289319 parents = args [1 ]
290320 attrs = args [2 ]
291321 return create_class (class_name , parents , attrs )
292-
322+ type . pythonscript_function = True
293323
294324def getattr (args , kwargs ):
295325 var (object , attribute )
0 commit comments