def instance(reply): """ Create an instance of the remote exception. Args: reply (Document): The reply. Returns: Exception: The concrete remote exception. RemoteException: When concrete exception cannot be propagated. """ target = reply.xclass mod = reply.xmodule state = reply.xstate args = reply.xargs try: T = globals().get(target) if not T: T = RemoteException._import(mod, target) try: inst = new(T, state) except Exception: inst = Exception() if isinstance(inst, Exception): inst.args = args except Exception: inst = RemoteException(reply.exval) return inst
def test_new(self): name = 'elmer' age = 30 T = newT('Person', (object,), {'name': name}) inst = new(T, {'age': age}) self.assertTrue(isinstance(inst, T)) self.assertEqual(T.name, name) self.assertEqual(inst.name, name) self.assertEqual(inst.age, age)
def instance(reply): target = reply.xclass mod = reply.xmodule state = reply.xstate args = reply.xargs try: T = globals().get(target) if not T: mod = __import__(mod, fromlist=[target]) T = getattr(mod, target) try: inst = new(T, state) except Exception: inst = Exception() if isinstance(inst, Exception): inst.args = args except: inst = RemoteException(reply.exval) return inst
def test_type(self): thing = new(Thing6, dict(a=1, b=2)) self.assertTrue(isinstance(thing, Thing6)) self.assertEqual(thing.a, 1) self.assertEqual(thing.b, 2)
def test_object(self): thing = new(Thing5, dict(a=1, b=2)) self.assertTrue(isinstance(thing, Thing5)) self.assertEqual(thing.a, 1) self.assertEqual(thing.b, 2)