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.AreEqual(uri, x);

            var 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");
            s = pickler.serializeData(proxy);
            x = pickler.deserializeData(s);
            PyroProxy proxy2 = (PyroProxy) x;
            Assert.AreEqual(uri.host, proxy2.hostname);
            Assert.AreEqual(uri.objectid, proxy2.objectid);
            Assert.AreEqual(uri.port, proxy2.port);
            Assert.IsNull(proxy2.correlation_id, "correlation_id is not serialized on the proxy object");
            Assert.AreEqual(proxy.pyroHandshake, proxy2.pyroHandshake);
            Assert.AreEqual(proxy.pyroHmacKey, proxy2.pyroHmacKey);
            Assert.AreEqual(2, proxy2.pyroAttrs.Count);
            Assert.AreEqual(proxy.pyroAttrs, proxy2.pyroAttrs);

            PyroException ex = new PyroException("error");
            s = pickler.serializeData(ex);
            x = pickler.deserializeData(s);
            PyroException ex2 = (PyroException) x;
            Assert.AreEqual(ex.Message, ex2.Message);
            Assert.IsNull(ex._pyroTraceback);
        }
Example #2
0
 public PyroURI(PyroURI other)
 {
     protocol = other.protocol;
     objectid = other.objectid;
     host     = other.host;
     port     = other.port;
 }
Example #3
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);
		}
Example #4
0
        public static object FromSerpentDict(IDictionary dict)
        {
            object[] state = (object[])dict["state"];      // pyroUri, onway(set), timeout
            PyroURI  uri   = new PyroURI((string)state[0]);

            return(new PyroProxy(uri));
        }
Example #5
0
 public PyroURI(PyroURI other)
 {
     protocol = other.protocol;
     objectid = other.objectid;
     host = other.host;
     port = other.port;
 }
Example #6
0
        public Tuple <PyroURI, ISet <string> > lookup(string name, bool return_metadata)
        {
            object[] result      = (object[])this.call("lookup", name, return_metadata);
            PyroURI  uri         = (PyroURI)result[0];
            var      metastrings = GetStringSet(result[1]);

            return(new Tuple <PyroURI, ISet <string> >(uri, metastrings));
        }
Example #7
0
        public static IDictionary ToSerpentDict(object obj)
        {
            PyroURI uri  = (PyroURI)obj;
            var     dict = new Hashtable();

            dict["state"]     = new object[] { uri.protocol, uri.objectid, null, uri.host, uri.port };
            dict["__class__"] = "Pyro4.core.URI";
            return(dict);
        }
Example #8
0
        public override bool Equals(object obj)
        {
            PyroURI other = obj as PyroURI;

            if (other == null)
            {
                return(false);
            }
            return(other.ToString() == ToString());
        }
Example #9
0
        /**
         * called by the Unpickler to restore state.
         * args: pyroUri, pyroOneway(hashset), pyroTimeout
         */
        public void __setstate__(object[] args)
        {
            PyroURI uri = (PyroURI)args[0];

            // the only thing we need here is the uri.
            this.hostname    = uri.host;
            this.port        = uri.port;
            this.objectid    = uri.objectid;
            this.sock        = null;
            this.sock_stream = null;
        }
Example #10
0
        /**
         * called by the Unpickler to restore state.
         * args: pyroUri, pyroOneway(hashset), pyroSerializer, pyroTimeout
         */
        public void __setstate__(object[] args)
        {
            PyroURI uri = (PyroURI)args[0];

            // ignore the oneway hashset, the serializer object and the timeout
            // the only thing we need here is the uri.
            this.hostname    = uri.host;
            this.port        = uri.port;
            this.objectid    = uri.objectid;
            this.sock        = null;
            this.sock_stream = null;
        }
Example #11
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);
	}
        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);
        }
Example #13
0
        public static object FromSerpentDict(IDictionary dict)
        {
            // note: the state array received in the dict conforms to the list produced by Pyro4'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, hmac_key, handshake, maxretries  (in this order)
            object[] 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
            object[] oneway_array = state[1] as object[];
            object[] methods_array = state[2] as object[];
            object[] attrs_array = state[3] as object[];
            if(oneway_array!=null)
            proxy.pyroOneway = new HashSet<string>(oneway_array.Select(o=>o as string));
            else if((state[1] as HashSet<string>) != null)
            proxy.pyroOneway = state[1] as HashSet<string>;
            else
            proxy.pyroOneway = new HashSet<string> ((state[1] as HashSet<object>).Select(o=>o.ToString()));

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

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

            if(state[5]!=null) {
            string encodedHmac = (string)state[5];
            if(encodedHmac.StartsWith("b64:", StringComparison.InvariantCulture)) {
                proxy.pyroHmacKey = Convert.FromBase64String(encodedHmac.Substring(4));
            } else {
                throw new PyroException("hmac encoding error");
            }
            }
            proxy.pyroHandshake = state[6];
            // maxretries is not used/supported in pyrolite, so simply ignore it

            return proxy;
        }
Example #14
0
        public void pickle(object o, Stream outs, Pickler currentPickler)
        {
            PyroURI uri = (PyroURI)o;

            outs.WriteByte(Opcodes.GLOBAL);
            byte[] output = Encoding.Default.GetBytes("Pyro4.core\nURI\n");
            outs.Write(output, 0, output.Length);
            outs.WriteByte(Opcodes.EMPTY_TUPLE);
            outs.WriteByte(Opcodes.NEWOBJ);
            outs.WriteByte(Opcodes.MARK);
            currentPickler.save(uri.protocol);
            currentPickler.save(uri.objectid);
            currentPickler.save(null);
            currentPickler.save(uri.host);
            currentPickler.save(uri.port);
            outs.WriteByte(Opcodes.TUPLE);
            outs.WriteByte(Opcodes.BUILD);
        }
        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.AreEqual(uri, x);

            var 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");
            s = ser.serializeData(proxy);
            x = 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);
            Assert.IsNull(proxy2.correlation_id, "correlation_id is not serialized on the proxy object");
            Assert.AreEqual(proxy.pyroHandshake, proxy2.pyroHandshake);
            Assert.AreEqual(proxy.pyroHmacKey, proxy2.pyroHmacKey);
            Assert.AreEqual(2, proxy2.pyroAttrs.Count);
            Assert.AreEqual(proxy.pyroAttrs, proxy2.pyroAttrs);

            PyroException ex = new PyroException("error");
            s = ser.serializeData(ex);
            x = 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 = ser.deserializeData(s);
            ex2 = (PyroException) x;
            Assert.AreEqual("hello", ex2.Message);
            Assert.AreEqual("traceback", ex2.Data["tb"]);
            Assert.AreEqual("line1line2", ex2._pyroTraceback);
        }
Example #16
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);
		}
Example #17
0
        /// <summary>
        /// called by the Unpickler to restore state.
        /// </summary>
        /// <param name="args">args(8 or 9): pyroUri, pyroOneway(hashset), pyroMethods(set), pyroAttrs(set), pyroTimeout, pyroHmacKey, pyroHandshake, pyroMaxRetries, [pyroSerializer]</param>
        public void __setstate__(object[] args)
        {
            if (args.Length != 8 && args.Length != 9)
            {
                throw new PyroException("invalid pickled proxy, using wrong pyro version?");
            }
            PyroURI uri = (PyroURI)args[0];

            this.hostname       = uri.host;
            this.port           = uri.port;
            this.objectid       = uri.objectid;
            this.sock           = null;
            this.sock_stream    = null;
            this.correlation_id = null;

            this.pyroOneway.Clear();
            foreach (object o in (HashSet <object>)args[1])
            {
                this.pyroOneway.Add(o as string);
            }
            this.pyroMethods.Clear();
            foreach (object o in (HashSet <object>)args[2])
            {
                this.pyroMethods.Add(o as string);
            }
            this.pyroAttrs.Clear();
            foreach (object o in (HashSet <object>)args[3])
            {
                this.pyroAttrs.Add(o as string);
            }

            this.pyroHmacKey   = (byte[])args[5];
            this.pyroHandshake = args[6];
            // XXX maxretries (args[7]) is not yet supported/used in pyrolite
            // XXX custom serializer (args[8]) is not yet supported in pyrolite
        }
Example #18
0
        public static object FromSerpentDict(IDictionary dict)
        {
            // note: the state array received in the dict conforms to the list produced by Pyro4'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, hmac_key, handshake, maxretries  (in this order)
            object[] 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
            object[] oneway_array  = state[1] as object[];
            object[] methods_array = state[2] as object[];
            object[] attrs_array   = state[3] as object[];
            if (oneway_array != null)
            {
                proxy.pyroOneway = new HashSet <string>(oneway_array.Select(o => o as string));
            }
            else if ((state[1] as HashSet <string>) != null)
            {
                proxy.pyroOneway = state[1] as HashSet <string>;
            }
            else
            {
                proxy.pyroOneway = new HashSet <string> ((state[1] as HashSet <object>).Select(o => o.ToString()));
            }

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

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

            if (state[5] != null)
            {
                string encodedHmac = (string)state[5];
                if (encodedHmac.StartsWith("b64:", StringComparison.InvariantCulture))
                {
                    proxy.pyroHmacKey = Convert.FromBase64String(encodedHmac.Substring(4));
                }
                else
                {
                    throw new PyroException("hmac encoding error");
                }
            }
            proxy.pyroHandshake = state[6];
            // maxretries is not used/supported in pyrolite, so simply ignore it

            return(proxy);
        }
Example #19
0
 /**
  * Create a proxy for the remote Pyro object denoted by the uri
  */
 public PyroProxy(PyroURI uri) : this(uri.host, uri.port, uri.objectid)
 {
 }
Example #20
0
	public static object FromSerpentDict(IDictionary dict)
	{
		object[] state = (object[])dict["state"];  // pyroUri, onway(set), timeout
		PyroURI uri = new PyroURI((string)state[0]);
		return new PyroProxy(uri);
	}
        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);
        }
Example #22
0
 public CustomAnnotationsProxy(PyroURI uri)
     : base(uri)
 {
 }
Example #23
0
 public NameServerProxy(PyroURI uri)
     : this(uri.host, uri.port, uri.objectid)
 {
 }
Example #24
0
 public void register(string name, PyroURI uri, bool safe, IEnumerable <string> metadata)
 {
     this.call("register", name, uri, safe, metadata);
 }
Example #25
0
 public void register(string name, PyroURI uri, bool safe)
 {
     this.call("register", name, uri, safe);
 }
Example #26
0
 /// <summary>
 /// Create a proxy for the remote Pyro object denoted by the uri
 /// </summary>
 public PyroProxy(PyroURI uri)
     : this(uri.host, uri.port, uri.objectid)
 {
 }
Example #27
0
 public CustomProxy(PyroURI uri)
     : base(uri)
 {
 }
Example #28
0
 public NameServerProxy(PyroURI uri) : this(uri.host, uri.port, uri.objectid)
 {
 }
Example #29
0
 public void register(string name, PyroURI uri, bool safe)
 {
     this.call("register", name, uri, safe);
 }
Example #30
0
 public void register(string name, PyroURI uri, bool safe, IEnumerable<string> metadata)
 {
     this.call("register", name, uri, safe, metadata);
 }