Пример #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);
        }
Пример #2
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"]);
        }
Пример #3
0
        public void TestSerpentBytes()
        {
            byte[]            bytes = Encoding.ASCII.GetBytes("hello");
            SerpentSerializer ser   = new SerpentSerializer();

            byte[] data = ser.serializeData(bytes);

            string str = Encoding.ASCII.GetString(data);

            Assert.IsTrue(str.Contains("base64"));

            Razorvine.Serpent.Parser p = new Razorvine.Serpent.Parser();
            Object data2 = p.Parse(data).GetData();

            byte[] bytes2 = SerpentSerializer.ToBytes(data2);
            Assert.AreEqual(Encoding.ASCII.GetBytes("hello"), bytes2);
        }
Пример #4
0
        public void TestSerpentBytes()
        {
            Config.SERPENT_INDENT = false;

            var bytes             = Encoding.ASCII.GetBytes("hello");
            SerpentSerializer ser = new SerpentSerializer();
            var data = ser.serializeData(bytes);

            string str = Encoding.ASCII.GetString(data);

            Assert.Contains("base64", str);

            Parser p      = new Parser();
            object data2  = p.Parse(data).GetData();
            var    bytes2 = SerpentSerializer.ToBytes(data2);

            Assert.Equal(Encoding.ASCII.GetBytes("hello"), bytes2);
        }