示例#1
0
 def _get_callback_from_class(self, clsname, methname):
     interp = self.ec.interpreter
     klass = interp.lookup_class_or_intf(clsname)
     if klass is None:
         raise InvalidCallback("class '%s' not found" % (clsname))
     contextclass = interp.get_contextclass()
     w_this = interp.get_frame().w_this
     try:
         meth = klass.getstaticmeth(methname, contextclass, w_this, interp)
     except VisibilityError as e:
         raise InvalidCallback(e.msg_callback(static=True))
     return meth.bind(w_this, klass)
示例#2
0
 def _get_callback_from_instance(self, w_instance, methname):
     contextclass = self.ec.interpreter.get_contextclass()
     try:
         meth = w_instance.getmeth(self, methname, contextclass)
     except VisibilityError as e:
         raise InvalidCallback(e.msg_callback(static=False))
     return meth
示例#3
0
 def _get_callback_from_string(self, name):
     pos = name.find('::')
     if pos >= 0:
         clsname = name[:pos]
         methname = name[pos + 2:]
         return self._get_callback_from_class(clsname, methname)
     try:
         return self.ec.interpreter.lookup_function(name)
     except KeyError:
         raise InvalidCallback("function '%s' not found or invalid "
                               "function name" % (name))
示例#4
0
 def _get_callback(self, w_obj):
     from hippy.objects.closureobject import W_ClosureObject
     if w_obj.tp == self.tp_str:
         name = self.str_w(w_obj)
         return self._get_callback_from_string(name)
     elif w_obj.tp == self.tp_array:
         if w_obj.arraylen() != 2:
             raise InvalidCallback("array must have exactly two members")
         w_instance = self.getitem(w_obj, self.wrap(0)).deref()
         if isinstance(w_instance, W_InstanceObject):
             methname = self.str_w(self.getitem(w_obj, self.wrap(1)))
             return self._get_callback_from_instance(w_instance, methname)
         clsname = self.str_w(w_instance)
         if not self.is_valid_varname(clsname):
             raise InvalidCallback("first array member is not a valid "
                                   "class name or object")
         methname = self.str_w(self.getitem(w_obj, self.wrap(1)))
         return self._get_callback_from_class(clsname, methname)
     elif isinstance(w_obj, W_InstanceObject):
         callable = w_obj.get_callable()
         if callable is not None:
             return callable
     raise InvalidCallback("no array or string given")