Exemple #1
0
        public void PyroClasses()
        {
            var uri = new PyroURI("PYRO:object@host:4444");

            byte[] s = this.ser.serializeData(uri);
            object x = this.ser.deserializeData(s);

            Assert.AreEqual(uri, x);

            var proxy = new PyroProxy(uri);

            s = this.ser.serializeData(proxy);
            x = this.ser.deserializeData(s);
            PyroProxy proxy2 = (PyroProxy)x;

            Assert.AreEqual(uri.host, proxy2.hostname);
            Assert.AreEqual(uri.objectid, proxy2.objectid);
            Assert.AreEqual(uri.port, proxy2.port);

            var ex = new PyroException("error");

            ex._pyroTraceback = "traceback";
            s = this.ser.serializeData(ex);
            x = this.ser.deserializeData(s);
            PyroException ex2 = (PyroException)x;

            Assert.AreEqual(ex.Message, ex2.Message);
            Assert.AreEqual("traceback", ex2._pyroTraceback);
        }
        public static IDictionary ToSerpentDict(object obj)
        {
            PyroException ex   = (PyroException)obj;
            IDictionary   dict = new Hashtable();

            // {'attributes':{},'__exception__':True,'args':('hello',),'__class__':'PyroError'}
            dict["__class__"]     = "PyroError";
            dict["__exception__"] = true;
            if (ex.Message != null)
            {
                dict["args"] = new object[] { ex.Message }
            }
            ;
            else
            {
                dict["args"] = new object[0];
            }
            if (!string.IsNullOrEmpty(ex._pyroTraceback))
            {
                ex.Data["_pyroTraceback"] = new [] { ex._pyroTraceback }
            }
            ;                                                                   // transform single string back into list
            dict["attributes"] = ex.Data;
            return(dict);
        }
        public void TestPyroExceptionType()
        {
            var ex   = new PyroException("hello");
            var type = ex.GetType();
            var prop = type.GetProperty("PythonExceptionType");

            Assert.NotNull(prop);             // "pyro exception class has to have a property PythonExceptionType, it is used in constructor classes"
            prop = type.GetProperty("_pyroTraceback");
            Assert.NotNull(prop);             // "pyro exception class has to have a property _pyroTraceback, it is used in constructor classes"
        }
        public void PyroClassesSerpent()
        {
            var ser = new SerpentSerializer();
            var uri = new PyroURI("PYRO:something@localhost:4444");

            byte[] s = ser.serializeData(uri);
            object x = ser.deserializeData(s);

            Assert.Equal(uri, x);

            var proxy = new PyroProxy(uri)
            {
                correlation_id = Guid.NewGuid(),
                pyroHandshake  = "apples",
                pyroHmacKey    = Encoding.UTF8.GetBytes("secret"),
                pyroAttrs      = new HashSet <string> {
                    "attr1", "attr2"
                }
            };

            s = ser.serializeData(proxy);
            x = ser.deserializeData(s);
            PyroProxy proxy2 = (PyroProxy)x;

            Assert.Equal(uri.host, proxy2.hostname);
            Assert.Equal(uri.objectid, proxy2.objectid);
            Assert.Equal(uri.port, proxy2.port);
            Assert.Null(proxy2.correlation_id);             // "correlation_id is not serialized on the proxy object"
            Assert.Equal(proxy.pyroHandshake, proxy2.pyroHandshake);
            Assert.Equal(proxy.pyroHmacKey, proxy2.pyroHmacKey);
            Assert.Equal(2, proxy2.pyroAttrs.Count);
            Assert.Equal(proxy.pyroAttrs, proxy2.pyroAttrs);

            PyroException ex = new PyroException("error");

            s = ser.serializeData(ex);
            x = ser.deserializeData(s);
            PyroException ex2 = (PyroException)x;

            Assert.Equal("[PyroError] error", ex2.Message);
            Assert.Null(ex._pyroTraceback);

            // try another kind of pyro exception
            s   = Encoding.UTF8.GetBytes("{'attributes':{'tb': 'traceback', '_pyroTraceback': ['line1', 'line2']},'__exception__':True,'args':('hello',42),'__class__':'CommunicationError'}");
            x   = ser.deserializeData(s);
            ex2 = (PyroException)x;
            Assert.Equal("[CommunicationError] hello", ex2.Message);
            Assert.Equal("traceback", ex2.Data["tb"]);
            Assert.Equal("line1line2", ex2._pyroTraceback);
            Assert.Equal("CommunicationError", ex2.PythonExceptionType);
        }
        public void PyroClassesPickle()
        {
            var pickler = new PickleSerializer();
            var uri     = new PyroURI("PYRO:something@localhost:4444");

            byte[] s = pickler.serializeData(uri);
            object x = pickler.deserializeData(s);

            Assert.Equal(uri, x);

            var proxy = new PyroProxy(uri)
            {
                correlation_id = Guid.NewGuid(),
                pyroHandshake  = "apples",
                pyroHmacKey    = Encoding.UTF8.GetBytes("secret"),
                pyroAttrs      = new HashSet <string> {
                    "attr1", "attr2"
                }
            };

            s = pickler.serializeData(proxy);
            x = pickler.deserializeData(s);
            PyroProxy proxy2 = (PyroProxy)x;

            Assert.Equal(uri.host, proxy2.hostname);
            Assert.Equal(uri.objectid, proxy2.objectid);
            Assert.Equal(uri.port, proxy2.port);
            Assert.Null(proxy2.correlation_id);             // "correlation_id is not serialized on the proxy object"
            Assert.Equal(proxy.pyroHandshake, proxy2.pyroHandshake);
            Assert.Equal(proxy.pyroHmacKey, proxy2.pyroHmacKey);
            Assert.Equal(2, proxy2.pyroAttrs.Count);
            Assert.Equal(proxy.pyroAttrs, proxy2.pyroAttrs);

            PyroException ex = new PyroException("error");

            s = pickler.serializeData(ex);
            x = pickler.deserializeData(s);
            PyroException ex2 = (PyroException)x;

            Assert.Equal("[Pyro4.errors.PyroError] error", ex2.Message);
            Assert.Null(ex._pyroTraceback);
        }
Exemple #6
0
        public void PyroClasses()
        {
            var uri = new PyroURI("PYRO:something@localhost:4444");

            byte[] s = this.ser.serializeData(uri);
            object x = this.ser.deserializeData(s);

            Assert.AreEqual(uri, x);

            var proxy = new PyroProxy(uri);

            s = this.ser.serializeData(proxy);
            x = this.ser.deserializeData(s);
            PyroProxy proxy2 = (PyroProxy)x;

            Assert.AreEqual(uri.host, proxy2.hostname);
            Assert.AreEqual(uri.objectid, proxy2.objectid);
            Assert.AreEqual(uri.port, proxy2.port);

            PyroException ex = new PyroException("error");

            s = this.ser.serializeData(ex);
            x = this.ser.deserializeData(s);
            PyroException ex2 = (PyroException)x;

            Assert.AreEqual(ex.Message, ex2.Message);
            Assert.IsNull(ex._pyroTraceback);

            // try another kind of pyro exception
            s   = Encoding.UTF8.GetBytes("{'attributes':{'tb': 'traceback', '_pyroTraceback': ['line1', 'line2']},'__exception__':True,'args':('hello',42),'__class__':'CommunicationError'}");
            x   = this.ser.deserializeData(s);
            ex2 = (PyroException)x;
            Assert.AreEqual("hello", ex2.Message);
            Assert.AreEqual("traceback", ex2.Data["tb"]);
            Assert.AreEqual("line1line2", ex2._pyroTraceback);
        }