Exemple #1
0
    def test_skip_recoverables(self):
        a = SimpleClass()
        a.l = threading.Lock()

        dto = mapper.dto_generator(a)
        a2 = mapper.load_from_dto(dto, skip_recoverables=True)
        self.assertEquals(None, a2.l)
        a3 = mapper.load_from_dto(dto, skip_recoverables=False)
        self.assertTrue(isinstance(a3.l, thread.LockType))
    def test_skip_recoverables(self):
        a = SimpleClass()
        a.l = threading.Lock()

        dto = mapper.dto_generator(a)
        a2  = mapper.load_from_dto(dto, skip_recoverables = True)
        self.assertEquals(None, a2.l)
        a3  = mapper.load_from_dto(dto, skip_recoverables = False)
        self.assertTrue(isinstance(a3.l, thread.LockType))
Exemple #3
0
 def _stub(self, *parameters, **kparameters):
     """ Dynamically generated method. Protocol: SOAP.
          Method name: METHOD_NAME. Documentation: DOCUMENTATION """
     try:
         if ServerSOAP.SERIALIZE:
             parameters_instance = (parameters, kparameters)
             if ServerSOAP.SERIALIZE_MAPPING:
                 parameters_instance = mapper.dto_generator(parameters_instance)
             dumped_result = getattr(self._server, METHOD_NAME)(pickle.dumps(parameters_instance))
             result = pickle.loads(dumped_result)
             if ServerSOAP.SERIALIZE_MAPPING:
                 result = mapper.load_from_dto(result)
             return result
         else:
             return getattr(self._server, METHOD_NAME)(*parameters, **kparameters)
     except SOAPpy.faultType as ft:
         # TODO: if server receives a control + c, client gets it :-o
         class_type = _retrieve_class(ft.faultcode)
         if class_type is not None:
             try:
                 instance = class_type(ft.faultstring)
             except:
                 pass
             else:
                 raise instance
         raise Exceptions.UnknownFaultType(
             "Unknown fault type: " + str(ft.faultcode) + ": " + str(ft.faultstring) + "; " + str(ft.detail), ft
         )
     except Exception as e:
         raise ProtocolErrors.UnknownRemoteError("Unknown exception: " + str(e.__class__) + "; " + str(e), e)
Exemple #4
0
 def _stub(self, *parameters, **kparameters):
     """ Dynamically generated method. Protocol: SOAP.
          Method name: METHOD_NAME. Documentation: DOCUMENTATION """
     try:
         if ServerSOAP.SERIALIZE:
             parameters_instance = (parameters, kparameters)
             if ServerSOAP.SERIALIZE_MAPPING:
                 parameters_instance = mapper.dto_generator(
                     parameters_instance)
             dumped_result = getattr(self._server, METHOD_NAME)(
                 pickle.dumps(parameters_instance))
             result = pickle.loads(dumped_result)
             if ServerSOAP.SERIALIZE_MAPPING:
                 result = mapper.load_from_dto(result)
             return result
         else:
             return getattr(self._server, METHOD_NAME)(*parameters,
                                                       **kparameters)
     except SOAPpy.faultType as ft:
         #TODO: if server receives a control + c, client gets it :-o
         class_type = _retrieve_class(ft.faultcode)
         if class_type is not None:
             try:
                 instance = class_type(ft.faultstring)
             except:
                 pass
             else:
                 raise instance
         raise Exceptions.UnknownFaultType(
             "Unknown fault type: " + str(ft.faultcode) + ": " +
             str(ft.faultstring) + "; " + str(ft.detail), ft)
     except Exception as e:
         raise ProtocolErrors.UnknownRemoteError(
             "Unknown exception: " + str(e.__class__) + "; " + str(e), e)
 def _skeleton(self,*parameters,**kparameters):
     """ Dynamically generated method. Protocol: SOAP.
          Method name: METHOD_NAME. Documentation: DOCUMENTATION """
     try:
         if SERIALIZE:
             parameters_instance = pickle.loads(parameters[0])
             if SERIALIZE_MAPPING:
                 parameters_instance = mapper.load_from_dto(parameters_instance)
             params, kparams = parameters_instance
             result = getattr(self._parent,'do_'+METHOD_NAME)(
                         *params,
                         **kparams
                     )
             if SERIALIZE_MAPPING:
                 result = mapper.dto_generator(result)
             dumped_result = pickle.dumps(result)
             return dumped_result
         else:
             return getattr(self._parent,'do_'+METHOD_NAME)(*parameters,**kparameters)
     except Exception as e:
         # TODO: watch out, if server gets a Control + C, the exception is going to propagate
         tb = traceback.format_exc()
         if type(e) == types.InstanceType:
             class_name = str(e.__class__)
         else:
             class_name = type(e).__module__ + '.' + type(e).__name__
         log.log(self,log.level.Info,"Exception : " + class_name + "; " + e.args[0] + "; " + tb)
         raise SOAPpy.faultType(
                 faultcode=class_name,
                 faultstring=e.args[0],
                 detail=tb
             )
 def unpack_call(self, data):
     encoded_data = data[10:-1]
     decoded_data = base64.decodestring(encoded_data)
     call_dto = cPickle.loads(decoded_data)
     call = mapper.load_from_dto(call_dto)
     if not isinstance(call, FunctionCall):
         pass  # TODO: raise something
     return call
 def unpack_result(self, data):
     encoded_data = data[10:-1]
     decoded_data = base64.decodestring(encoded_data)
     result_dto = cPickle.loads(decoded_data)
     result = mapper.load_from_dto(result_dto)
     if not isinstance(result, FunctionResult):
         pass  #TODO: raise an exception or something
     return result
Exemple #8
0
 def unpack_result(self, data):
     encoded_data = data[10:-1]
     decoded_data = base64.decodestring(encoded_data)
     result_dto = cPickle.loads(decoded_data)
     result = mapper.load_from_dto(result_dto)
     if not isinstance(result, FunctionResult):
         pass #TODO: raise an exception or something
     return result
Exemple #9
0
 def unpack_call(self, data):
     encoded_data = data[10:-1]
     decoded_data = base64.decodestring(encoded_data)
     call_dto = cPickle.loads(decoded_data)
     call = mapper.load_from_dto(call_dto)
     if not isinstance(call, FunctionCall):
         pass # TODO: raise something
     return call
 def test_dto_not_comparable_instances(self):
     dt = xmlrpclib.DateTime()
     # DateTime throws exception when doing:
     #   dt == {}
     # for instance
     dto = mapper.dto_generator({"foo" : dt})
     dt2 = mapper.load_from_dto(dto)
     self.assertEquals(["foo"], dt2.keys())
     self.assertEquals(dt.value, dt2["foo"].value)
Exemple #11
0
 def test_dto_not_comparable_instances(self):
     dt = xmlrpclib.DateTime()
     # DateTime throws exception when doing:
     #   dt == {}
     # for instance
     dto = mapper.dto_generator({"foo": dt})
     dt2 = mapper.load_from_dto(dto)
     self.assertEquals(["foo"], dt2.keys())
     self.assertEquals(dt.value, dt2["foo"].value)
 def _skeleton(self, *parameters, **kparameters):
     """ Dynamically generated method. Protocol: Direct.
          Method name: METHOD_NAME. Documentation: DOCUMENTATION """
     if DUPLICATE:
         dumped_parameters_instance = parameters[0]
         parameters_instance = pickle.loads(dumped_parameters_instance)
         real_parameters = mapper.load_from_dto(parameters_instance)
         parameters, kparameters = real_parameters
     return getattr(self._parent, 'do_'+METHOD_NAME)(*parameters, **kparameters)
Exemple #13
0
 def test_dto_datetime(self):
     sc = SimpleClass()
     sc.time = datetime.datetime(2007, 12, 31, 23, 55)
     dto = mapper.dto_generator(sc)
     sc2 = mapper.load_from_dto(dto)
     self.assertEquals(2007, sc2.time.year)
     self.assertEquals(12, sc2.time.month)
     self.assertEquals(31, sc2.time.day)
     self.assertEquals(23, sc2.time.hour)
     self.assertEquals(55, sc2.time.minute)
 def _skeleton(self, *parameters, **kparameters):
     """ Dynamically generated method. Protocol: Direct.
          Method name: METHOD_NAME. Documentation: DOCUMENTATION """
     if DUPLICATE:
         dumped_parameters_instance = parameters[0]
         parameters_instance = pickle.loads(dumped_parameters_instance)
         real_parameters = mapper.load_from_dto(parameters_instance)
         parameters, kparameters = real_parameters
     return getattr(self._parent, 'do_' + METHOD_NAME)(*parameters,
                                                       **kparameters)
 def test_dto_datetime(self):
     sc = SimpleClass()
     sc.time = datetime.datetime(2007, 12, 31, 23, 55)
     dto = mapper.dto_generator(sc)
     sc2 = mapper.load_from_dto(dto)
     self.assertEquals(2007, sc2.time.year)
     self.assertEquals(12  , sc2.time.month)
     self.assertEquals(31  , sc2.time.day)
     self.assertEquals(23  , sc2.time.hour)
     self.assertEquals(55  , sc2.time.minute)
Exemple #16
0
    def test_mapping_ignorable(self):
        native_obj = expat_parser.ParserCreate()
        self.assertRaises(pickle.PicklingError, pickle.dumps, native_obj)

        class MyClass(object):
            pass

        my_class = MyClass()
        my_class.native_obj = native_obj

        dto = mapper.dto_generator(my_class)
        my_class2 = mapper.load_from_dto(dto)
        self.assertTrue(isinstance(my_class2.native_obj, str))
Exemple #17
0
def load_from_file(file):
    try:
        dto_object = pickle.load(file)
    except Exception as e:
        raise CoordMapErrors.CoordLoadingError(
            "Exception <%s> caught loading coordmap from file <%s>" %
            (e, file), e)
    try:
        dto_object = mapper.load_from_dto(dto_object)
    except Exception as e:
        raise CoordMapErrors.CoordLoadingError(
            "Exception <%s> caught deserializing dto_object <%s> received from file <%s>"
            % (e, dto_object, file), e)

    return dto_object
    def test_mapping_ignorable(self):
        native_obj = expat_parser.ParserCreate()
        self.assertRaises(
                    pickle.PicklingError,
                    pickle.dumps,
                    native_obj
            )

        class MyClass(object):
            pass

        my_class = MyClass()
        my_class.native_obj = native_obj

        dto = mapper.dto_generator(my_class)
        my_class2 = mapper.load_from_dto(dto)
        self.assertTrue(isinstance(my_class2.native_obj,str))
def load_from_file(file):
    try:
        dto_object = pickle.load(file)
    except Exception as e:
        raise CoordMapErrors.CoordLoadingError(
                "Exception <%s> caught loading coordmap from file <%s>"
                % (e,file),
                e
            )
    try:
        dto_object = mapper.load_from_dto(dto_object)
    except Exception as e:
        raise CoordMapErrors.CoordLoadingError(
                "Exception <%s> caught deserializing dto_object <%s> received from file <%s>"
                % (e,dto_object,file),
                e
            )

    return dto_object
    def test_dto_generator(self):
        mc = MyClass(1,2,(1,2))
        mc.and_another = MyClass(1,3,(1,3))

        moc = MyOtherClass(4+4j)

        # Cyclic references
        jac1 = JetAnotherClass(None)
        jac2 = JetAnotherClass(jac1)
        jac1.otherReference = jac2

        # mc and moc can't be pickled
        # pickle raises pickle.PicklingError in Python < 2.7 but TypeError in Python 2.7; we try both exceptions
        try:
            self.assertRaises(
                   pickle.PicklingError,
                   pickle.dumps,
                   mc
               )
        except:
            first_assertion_failed = True
        else:
            first_assertion_failed = False

        try:
            self.assertRaises(
                   TypeError,
                   pickle.dumps,
                   mc
               )
        except:
            if first_assertion_failed:
               raise

        self.assertRaises(
                TypeError,
                pickle.dumps,
                moc
            )

        my_dto = mapper.dto_generator(mc)

        self.assertEquals(
                my_dto._first_field,
                mc._first_field
            )
        self.assertEquals(
                my_dto._second_field,
                mc._second_field
            )
        self.assertEquals(
                my_dto._third_field,
                mc._third_field
            )
        self.assertEquals(
                my_dto.sum_of_fields,
                mc.sum_of_fields
            )
        self.assertNotEquals( #Lock not allowed
                type(my_dto.another),
                thread.LockType
            )
        self.assertEquals(
                my_dto.yet_another,
                mc.yet_another
            )
        # And inside and_another... so on
        self.assertEquals(
                my_dto.and_another._first_field,
                mc.and_another._first_field
            )

        # What about moc?
        my_other_dto = mapper.dto_generator(moc)
        self.assertEquals(
                my_other_dto.param,
                moc.param
            )
        self.assertEquals(
                hasattr(my_other_dto,'param2'),
                False
            )

        # What about JetAnotherClass?
        my_other_jac1 = mapper.dto_generator(jac1)
        my_other_jac1.otherReference


        # Go ahead! Pickle me! ;-D
        pickled     = pickle.dumps(my_dto)
        my_dto2     = pickle.loads(pickled)

        pickled     = pickle.dumps(my_other_dto)
        my_other_dto2   = pickle.loads(pickled)

        # Let's try to unload them
        my_dto2 = mapper.load_from_dto(my_dto2)

        my_other_dto2 = mapper.load_from_dto(my_other_dto2)

        # Let's check locks work
        my_dto2.my_method() #Nothing happens :-)
 def test_condition(self):
     c1 = threading.Condition()
     dto = mapper.dto_generator(c1)
     c2 = mapper.load_from_dto(dto)
     self.assertTrue(hasattr(c2, 'acquire'))
     self.assertTrue(hasattr(c2, 'release'))
 def test_dto_builtin(self):
     exception = AttributeError("foo")
     dto = mapper.dto_generator(exception)
     generated = mapper.load_from_dto(dto)
     self.assertTrue(isinstance(generated,AttributeError))
     self.assertEquals("foo", generated.args[0] )
Exemple #23
0
 def test_dto_builtin(self):
     exception = AttributeError("foo")
     dto = mapper.dto_generator(exception)
     generated = mapper.load_from_dto(dto)
     self.assertTrue(isinstance(generated, AttributeError))
     self.assertEquals("foo", generated.args[0])
Exemple #24
0
 def test_condition(self):
     c1 = threading.Condition()
     dto = mapper.dto_generator(c1)
     c2 = mapper.load_from_dto(dto)
     self.assertTrue(hasattr(c2, 'acquire'))
     self.assertTrue(hasattr(c2, 'release'))
Exemple #25
0
    def test_dto_generator(self):
        mc = MyClass(1, 2, (1, 2))
        mc.and_another = MyClass(1, 3, (1, 3))

        moc = MyOtherClass(4 + 4j)

        # Cyclic references
        jac1 = JetAnotherClass(None)
        jac2 = JetAnotherClass(jac1)
        jac1.otherReference = jac2

        # mc and moc can't be pickled
        # pickle raises pickle.PicklingError in Python < 2.7 but TypeError in Python 2.7; we try both exceptions
        try:
            self.assertRaises(pickle.PicklingError, pickle.dumps, mc)
        except:
            first_assertion_failed = True
        else:
            first_assertion_failed = False

        try:
            self.assertRaises(TypeError, pickle.dumps, mc)
        except:
            if first_assertion_failed:
                raise

        self.assertRaises(TypeError, pickle.dumps, moc)

        my_dto = mapper.dto_generator(mc)

        self.assertEquals(my_dto._first_field, mc._first_field)
        self.assertEquals(my_dto._second_field, mc._second_field)
        self.assertEquals(my_dto._third_field, mc._third_field)
        self.assertEquals(my_dto.sum_of_fields, mc.sum_of_fields)
        self.assertNotEquals(  #Lock not allowed
            type(my_dto.another), thread.LockType)
        self.assertEquals(my_dto.yet_another, mc.yet_another)
        # And inside and_another... so on
        self.assertEquals(my_dto.and_another._first_field,
                          mc.and_another._first_field)

        # What about moc?
        my_other_dto = mapper.dto_generator(moc)
        self.assertEquals(my_other_dto.param, moc.param)
        self.assertEquals(hasattr(my_other_dto, 'param2'), False)

        # What about JetAnotherClass?
        my_other_jac1 = mapper.dto_generator(jac1)
        my_other_jac1.otherReference

        # Go ahead! Pickle me! ;-D
        pickled = pickle.dumps(my_dto)
        my_dto2 = pickle.loads(pickled)

        pickled = pickle.dumps(my_other_dto)
        my_other_dto2 = pickle.loads(pickled)

        # Let's try to unload them
        my_dto2 = mapper.load_from_dto(my_dto2)

        my_other_dto2 = mapper.load_from_dto(my_other_dto2)

        # Let's check locks work
        my_dto2.my_method()  #Nothing happens :-)