コード例 #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);
        }
コード例 #2
0
        public static object FromSerpentDict(IDictionary dict)
        {
            // note: the state array received in the dict conforms to the list produced by Pyro's Proxy.__getstate_for_dict__
            // that means, we must get an array of length 8:  (the same as with ToSerpentDict above!)
            // uri, oneway set, methods set, attrs set, timeout, handshake, maxretries  (in this order)
            var     state = (object[])dict["state"];
            PyroURI uri   = new PyroURI((string)state[0]);
            var     proxy = new PyroProxy(uri);

            // the following nasty piece of code is similar to _processMetaData from the PyroProxy
            // this is because the three collections can either be an array or a set
            var onewayArray  = state[1] as object[];
            var methodsArray = state[2] as object[];
            var attrsArray   = state[3] as object[];

            if (onewayArray != null)
            {
                proxy.pyroOneway = new HashSet <string>(onewayArray.Select(o => o as string));
            }
            else if (state[1] is HashSet <string> )
            {
                proxy.pyroOneway = (HashSet <string>)state[1];
            }
            else
            {
                proxy.pyroOneway = new HashSet <string> ((state[1] as HashSet <object>).Select(o => o.ToString()));
            }

            if (methodsArray != null)
            {
                proxy.pyroMethods = new HashSet <string>(methodsArray.Select(o => o as string));
            }
            else if (state[2] is HashSet <string> )
            {
                proxy.pyroMethods = (HashSet <string>)state[2];
            }
            else
            {
                proxy.pyroMethods = new HashSet <string>((state[2] as HashSet <object>).Select(o => o.ToString()));
            }

            if (attrsArray != null)
            {
                proxy.pyroAttrs = new HashSet <string>(attrsArray.Select(o => o as string));
            }
            else if (state[3] is HashSet <string> )
            {
                proxy.pyroAttrs = (HashSet <string>)state[3];
            }
            else
            {
                proxy.pyroAttrs = new HashSet <string>((state[3] as HashSet <object>).Select(o => o.ToString()));
            }

            proxy.pyroHandshake = state[5];
            // maxretries is not used/supported in pyrolite, so simply ignore it

            return(proxy);
        }
コード例 #3
0
        public static IDictionary ToSerpentDict(object obj)
        {
            PyroURI uri  = (PyroURI)obj;
            var     dict = new Hashtable
            {
                ["state"]     = new object[] { uri.protocol, uri.objectid, null, uri.host, uri.port },
                ["__class__"] = "Pyro5.core.URI"
            };

            return(dict);
        }
コード例 #4
0
	public void testPickleUnpickleURI() {
		PyroURI uri=new PyroURI("PYRO:test@localhost:9999");
		Pickler p=new Pickler();
		byte[] pickled_uri=p.dumps(uri);
		PyroURI uri2=(PyroURI) U(pickled_uri);
		Assert.AreEqual(uri,uri2);

		uri=new PyroURI();
		pickled_uri=p.dumps(uri);
		uri2=(PyroURI) U(pickled_uri);
		Assert.AreEqual(uri,uri2);
	}
コード例 #5
0
ファイル: SerializePyroTests.cs プロジェクト: sjl421/Pyrolite
        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);
        }
コード例 #6
0
        public void TestPickleUnpickleUri()
        {
            PyroURI        uri        = new PyroURI("PYRO:test@localhost:9999");
            PyroSerializer ser        = new PickleSerializer();
            var            pickledUri = ser.serializeData(uri);
            PyroURI        uri2       = (PyroURI)ser.deserializeData(pickledUri);

            Assert.Equal(uri, uri2);

            uri        = new PyroURI();
            pickledUri = ser.serializeData(uri);
            uri2       = (PyroURI)ser.deserializeData(pickledUri);
            Assert.Equal(uri, uri2);
        }
コード例 #7
0
        public void testPickleUnpickleURI()
        {
            PyroURI        uri = new PyroURI("PYRO:test@localhost:9999");
            PyroSerializer ser = new PickleSerializer();

            byte[]  pickled_uri = ser.serializeData(uri);
            PyroURI uri2        = (PyroURI)ser.deserializeData(pickled_uri);

            Assert.AreEqual(uri, uri2);

            uri         = new PyroURI();
            pickled_uri = ser.serializeData(uri);
            uri2        = (PyroURI)ser.deserializeData(pickled_uri);
            Assert.AreEqual(uri, uri2);
        }
コード例 #8
0
ファイル: SerializePyroTests.cs プロジェクト: sjl421/Pyrolite
        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);
        }
コード例 #9
0
        public void PyroProxySerpent()
        {
            PyroURI   uri   = new PyroURI("PYRO:something@localhost:4444");
            PyroProxy proxy = new PyroProxy(uri);

            proxy.correlation_id = Guid.NewGuid();
            proxy.pyroHandshake  = "apples";
            proxy.pyroHmacKey    = Encoding.UTF8.GetBytes("secret");
            proxy.pyroAttrs      = new HashSet <string>();
            proxy.pyroAttrs.Add("attr1");
            proxy.pyroAttrs.Add("attr2");
            var data = PyroProxyPickler.ToSerpentDict(proxy);

            Assert.AreEqual(2, data.Count);
            Assert.AreEqual("Pyro4.core.Proxy", data["__class__"]);
            Assert.AreEqual(8, ((object[])data["state"]).Length);

            PyroProxy proxy2 = (PyroProxy)PyroProxyPickler.FromSerpentDict(data);

            Assert.AreEqual(proxy.objectid, proxy2.objectid);
            Assert.AreEqual("apples", proxy2.pyroHandshake);
        }
コード例 #10
0
        public void TestPyroProxySerpent()
        {
            PyroURI   uri   = new PyroURI("PYRO:something@localhost:4444");
            PyroProxy proxy = new PyroProxy(uri)
            {
                correlation_id = Guid.NewGuid(),
                pyroHandshake  = "apples",
                pyroAttrs      = new HashSet <string> {
                    "attr1", "attr2"
                }
            };
            var data = PyroProxySerpent.ToSerpentDict(proxy);

            Assert.Equal(2, data.Count);
            Assert.Equal("Pyro5.client.Proxy", (string)data["__class__"]);
            Assert.Equal(7, ((object[])data["state"]).Length);

            PyroProxy proxy2 = (PyroProxy)PyroProxySerpent.FromSerpentDict(data);

            Assert.Equal(proxy.objectid, proxy2.objectid);
            Assert.Equal("apples", proxy2.pyroHandshake);
        }
コード例 #11
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);
        }
コード例 #12
0
ファイル: TestEcho.cs プロジェクト: torokati44/Pyrolite
 public CustomProxy(PyroURI uri) : base(uri)
 {
 }
コード例 #13
0
ファイル: TestNaming.cs プロジェクト: zivillian/Pyrolite
        private static void Test()
        {
            Console.WriteLine("Testing Pyro nameserver connection (make sure it's running with a broadcast server)...");
            Console.WriteLine("Pyrolite version: " + Config.PYROLITE_VERSION);

            SetConfig();
            // Config.SERIALIZER = Config.SerializerType.pickle;

            Console.WriteLine("serializer used: {0}", Config.SERIALIZER);
            if (Config.SERIALIZER == Config.SerializerType.serpent)
            {
                Console.WriteLine("note that for the serpent serializer, you need to have the Razorvine.Serpent assembly available.");
            }

            using (NameServerProxy ns = NameServerProxy.locateNS(null, hmacKey: HmacKey))
            {
                Console.WriteLine("discovered ns at " + ns.hostname + ":" + ns.port);
                ns.ping();

                Console.WriteLine("lookup of name server object:");
                PyroURI uri = ns.lookup("Pyro.NameServer");
                Console.WriteLine("   " + uri);
                Console.WriteLine("lookup of name server object, with metadata:");
                var tmeta = ns.lookup("Pyro.NameServer", true);
                Console.WriteLine("   uri:  " + tmeta.Item1);
                Console.WriteLine("   meta: " + string.Join(", ", tmeta.Item2));
                var metadata = tmeta.Item2;
                metadata.Add("updated-by-dotnet-pyrolite");
                ns.set_metadata("Pyro.NameServer", metadata);


                Console.WriteLine("\nobjects registered in the name server:");
                var objects = ns.list(null, null);
                foreach (string key in objects.Keys)
                {
                    Console.WriteLine(key + " --> " + objects[key]);
                }

                Console.WriteLine("\nobjects registered in the name server, with metadata:");
                var objectsm = ns.list_with_meta(null, null);
                foreach (string key in objectsm.Keys)
                {
                    var registration = objectsm[key];
                    Console.WriteLine(key + " --> " + registration.Item1);
                    Console.WriteLine("      metadata: " + string.Join(", ", registration.Item2));
                }

                Console.WriteLine("\nobjects registered having all metadata:");
                objects = ns.list(null, null, new [] { "blahblah", "class:Pyro4.naming.NameServer" }, null);
                foreach (string name in objects.Keys)
                {
                    Console.WriteLine(name + " --> " + objects[name]);
                }
                Console.WriteLine("\nobjects registered having any metadata:");
                objects = ns.list(null, null, null, new [] { "blahblah", "class:Pyro4.naming.NameServer" });
                foreach (string name in objects.Keys)
                {
                    Console.WriteLine(name + " --> " + objects[name]);
                }
                Console.WriteLine("\nobjects registered having any metadata (showing it too):");
                objectsm = ns.list_with_meta(null, null, null, new [] { "blahblah", "class:Pyro4.naming.NameServer" });
                foreach (string name in objectsm.Keys)
                {
                    var entry = objectsm[name];
                    Console.WriteLine(name + " --> " + entry.Item1);
                    Console.WriteLine("      metadata: " + string.Join(", ", entry.Item2));
                }

                Console.WriteLine("");
                ns.register("dotnet.test", new PyroURI("PYRO:DotnetTest@localhost:9999"), false);
                ns.register("dotnet.testmeta", new PyroURI("PYRO:DotnetTest@localhost:9999"), false, new [] { "example", "from-dotnet-pyrolite" });

                Console.WriteLine("uri=" + ns.lookup("dotnet.test"));
                Console.WriteLine("using a new proxy to call the nameserver.");

                using (PyroProxy p = new PyroProxy(ns.lookup("Pyro.NameServer")))
                {
                    p.pyroHmacKey = HmacKey;
                    p.call("ping");
                }

                int numRemoved = ns.remove(null, "dotnet.", null);
                Console.WriteLine("number of removed entries: {0}", numRemoved);

                try {
                    Console.WriteLine("uri=" + ns.lookup("dotnet.test"));                // should fail....
                } catch (PyroException x) {
                    // ok
                    Console.WriteLine("got a PyroException (expected): {0}", x.Message);
                }
            }
        }
コード例 #14
0
 public CustomAnnotationsProxy(PyroURI uri) : base(uri)
 {
 }