Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void UnserpentProxy()
        {
            byte[] data = Encoding.UTF8.GetBytes("# serpent utf-8 python3.2\n" +
                                                 "{'state':('PYRO:Pyro.NameServer@localhost:9090',(),('count','lookup','register','ping','list','remove'),(),0.0,'b64:c2VjcmV0','hello',0),'__class__':'Pyro4.core.Proxy'}");

            SerpentSerializer ser = new SerpentSerializer();
            PyroProxy         p   = (PyroProxy)ser.deserializeData(data);

            Assert.IsNull(p.correlation_id);
            Assert.AreEqual("Pyro.NameServer", p.objectid);
            Assert.AreEqual("localhost", p.hostname);
            Assert.AreEqual(9090, p.port);
            Assert.AreEqual("hello", p.pyroHandshake);
            Assert.AreEqual(Encoding.UTF8.GetBytes("secret"), p.pyroHmacKey);
            Assert.AreEqual(0, p.pyroAttrs.Count);
            Assert.AreEqual(0, p.pyroOneway.Count);
            Assert.AreEqual(6, p.pyroMethods.Count);
            ISet <string> methods = new HashSet <string>();

            methods.Add("ping");
            methods.Add("count");
            methods.Add("lookup");
            methods.Add("list");
            methods.Add("register");
            methods.Add("remove");
            CollectionAssert.AreEquivalent(methods, p.pyroMethods);
        }
Ejemplo n.º 3
0
        public void TestSerpentDictType()
        {
            Hashtable ht = new Hashtable {
                ["key"] = "value"
            };
            var ser    = new SerpentSerializer();
            var data   = ser.serializeData(ht);
            var result = ser.deserializeData(data);

            Assert.IsAssignableFrom <Dictionary <object, object> >(result);         // "in recent serpent versions, hashtables/dicts must be deserialized as IDictionary<object,object> rather than Hashtable"
            var dict = (IDictionary <object, object>)result;

            Assert.Equal("value", dict["key"]);
        }
Ejemplo n.º 4
0
        public void TestUnserpentProxy()
        {
            var data = Encoding.UTF8.GetBytes("# serpent utf-8 python3.2\n" +
                                              "{'state':('PYRO:Pyro.NameServer@localhost:9090',(),('count','lookup','register','ping','list','remove'),(),0.0,'hello',0),'__class__':'Pyro5.client.Proxy'}");

            SerpentSerializer ser = new SerpentSerializer();
            PyroProxy         p   = (PyroProxy)ser.deserializeData(data);

            Assert.Null(p.correlation_id);
            Assert.Equal("Pyro.NameServer", p.objectid);
            Assert.Equal("localhost", p.hostname);
            Assert.Equal(9090, p.port);
            Assert.Equal("hello", p.pyroHandshake);
            Assert.Equal(0, p.pyroAttrs.Count);
            Assert.Equal(0, p.pyroOneway.Count);
            Assert.Equal(6, p.pyroMethods.Count);
            var methods = new List <string> {
                "count", "list", "lookup", "ping", "register", "remove"
            };

            Assert.Equal(methods, p.pyroMethods.OrderBy(m => m).ToList());
        }