Esempio n. 1
0
	public void testAddPop() {
		UnpickleStack s=new UnpickleStack();
		Assert.AreEqual(0, s.size());
		s.add("x");
		Assert.AreEqual(1, s.size());
		s.add("y");
		Assert.AreEqual(2, s.size());
		Assert.AreEqual("y", s.peek());
		Assert.AreEqual("y", s.pop());
		Assert.AreEqual("x", s.peek());
		Assert.AreEqual("x", s.pop());
		Assert.AreEqual(0, s.size());
	}
Esempio n. 2
0
        public object Load()
        {
            byte key = 0;

            while ((key = input.ReadByte()) != Opcodes.STOP)
            {
                Dispatch(key);
            }

            object value = stack.pop();

            stack.clear();
            unpickler.memo.Clear();
            return(value); // final result value
        }
Esempio n. 3
0
	public void testPopSinceMarker() {
		UnpickleStack s=new UnpickleStack();
		s.add("a");
		s.add("b");
		s.add_mark();
		s.add("c");
		s.add("d");
		s.add_mark();
		s.add("e");
		s.add("f");
		ArrayList top=s.pop_all_since_marker();
		ArrayList expected=new ArrayList();
		expected.Add("e");
		expected.Add("f");
		Assert.AreEqual(expected, top);
		Assert.AreEqual("d",s.pop());
		Assert.AreEqual("c",s.pop());
	}
Esempio n. 4
0
        /**
         * Process a single pickle stream opcode.
         */
        protected object dispatch(short key)
        {
            switch (key)
            {
            case Opcodes.MARK:
                load_mark();
                break;

            case Opcodes.STOP:
                object value = stack.pop();
                stack.clear();
                return(value);                  // final result value

            case Opcodes.POP:
                load_pop();
                break;

            case Opcodes.POP_MARK:
                load_pop_mark();
                break;

            case Opcodes.DUP:
                load_dup();
                break;

            case Opcodes.FLOAT:
                load_float();
                break;

            case Opcodes.INT:
                load_int();
                break;

            case Opcodes.BININT:
                load_binint();
                break;

            case Opcodes.BININT1:
                load_binint1();
                break;

            case Opcodes.LONG:
                load_long();
                break;

            case Opcodes.BININT2:
                load_binint2();
                break;

            case Opcodes.NONE:
                load_none();
                break;

            case Opcodes.PERSID:
                load_persid();
                break;

            case Opcodes.BINPERSID:
                load_binpersid();
                break;

            case Opcodes.REDUCE:
                load_reduce();
                break;

            case Opcodes.STRING:
                load_string();
                break;

            case Opcodes.BINSTRING:
                load_binstring();
                break;

            case Opcodes.SHORT_BINSTRING:
                load_short_binstring();
                break;

            case Opcodes.UNICODE:
                load_unicode();
                break;

            case Opcodes.BINUNICODE:
                load_binunicode();
                break;

            case Opcodes.APPEND:
                load_append();
                break;

            case Opcodes.BUILD:
                load_build();
                break;

            case Opcodes.GLOBAL:
                load_global();
                break;

            case Opcodes.DICT:
                load_dict();
                break;

            case Opcodes.EMPTY_DICT:
                load_empty_dictionary();
                break;

            case Opcodes.APPENDS:
                load_appends();
                break;

            case Opcodes.GET:
                load_get();
                break;

            case Opcodes.BINGET:
                load_binget();
                break;

            case Opcodes.INST:
                load_inst();
                break;

            case Opcodes.LONG_BINGET:
                load_long_binget();
                break;

            case Opcodes.LIST:
                load_list();
                break;

            case Opcodes.EMPTY_LIST:
                load_empty_list();
                break;

            case Opcodes.OBJ:
                load_obj();
                break;

            case Opcodes.PUT:
                load_put();
                break;

            case Opcodes.BINPUT:
                load_binput();
                break;

            case Opcodes.LONG_BINPUT:
                load_long_binput();
                break;

            case Opcodes.SETITEM:
                load_setitem();
                break;

            case Opcodes.TUPLE:
                load_tuple();
                break;

            case Opcodes.EMPTY_TUPLE:
                load_empty_tuple();
                break;

            case Opcodes.SETITEMS:
                load_setitems();
                break;

            case Opcodes.BINFLOAT:
                load_binfloat();
                break;

            // protocol 2
            case Opcodes.PROTO:
                load_proto();
                break;

            case Opcodes.NEWOBJ:
                load_newobj();
                break;

            case Opcodes.EXT1:
            case Opcodes.EXT2:
            case Opcodes.EXT4:
                throw new PickleException("Unimplemented opcode EXT1/EXT2/EXT4 encountered. Don't use extension codes when pickling via copyreg.add_extension() to avoid this error.");

            case Opcodes.TUPLE1:
                load_tuple1();
                break;

            case Opcodes.TUPLE2:
                load_tuple2();
                break;

            case Opcodes.TUPLE3:
                load_tuple3();
                break;

            case Opcodes.NEWTRUE:
                load_true();
                break;

            case Opcodes.NEWFALSE:
                load_false();
                break;

            case Opcodes.LONG1:
                load_long1();
                break;

            case Opcodes.LONG4:
                load_long4();
                break;

            // Protocol 3 (Python 3.x)
            case Opcodes.BINBYTES:
                load_binbytes();
                break;

            case Opcodes.SHORT_BINBYTES:
                load_short_binbytes();
                break;

            // Protocol 4 (Python 3.4+)
            case Opcodes.BINUNICODE8:
                load_binunicode8();
                break;

            case Opcodes.SHORT_BINUNICODE:
                load_short_binunicode();
                break;

            case Opcodes.BINBYTES8:
                load_binbytes8();
                break;

            case Opcodes.EMPTY_SET:
                load_empty_set();
                break;

            case Opcodes.ADDITEMS:
                load_additems();
                break;

            case Opcodes.FROZENSET:
                load_frozenset();
                break;

            case Opcodes.MEMOIZE:
                load_memoize();
                break;

            case Opcodes.FRAME:
                load_frame();
                break;

            case Opcodes.NEWOBJ_EX:
                load_newobj_ex();
                break;

            case Opcodes.STACK_GLOBAL:
                load_stack_global();
                break;

            default:
                throw new InvalidOpcodeException("invalid pickle opcode: " + key);
            }

            return(NO_RETURN_VALUE);
        }
Esempio n. 5
0
        /**
         * Process a single pickle stream opcode.
         */
        protected void dispatch(short key)
        {
            switch (key)
            {
            case Opcodes.MARK:
                load_mark();
                break;

            case Opcodes.STOP:
                object value = stack.pop();
                stack.clear();
                throw new StopException(value);

            case Opcodes.POP:
                load_pop();
                break;

            case Opcodes.POP_MARK:
                load_pop_mark();
                break;

            case Opcodes.DUP:
                load_dup();
                break;

            case Opcodes.FLOAT:
                load_float();
                break;

            case Opcodes.INT:
                load_int();
                break;

            case Opcodes.BININT:
                load_binint();
                break;

            case Opcodes.BININT1:
                load_binint1();
                break;

            case Opcodes.LONG:
                load_long();
                break;

            case Opcodes.BININT2:
                load_binint2();
                break;

            case Opcodes.NONE:
                load_none();
                break;

            case Opcodes.PERSID:
                throw new InvalidOpcodeException("opcode not implemented: PERSID");

            case Opcodes.BINPERSID:
                throw new InvalidOpcodeException("opcode not implemented: BINPERSID");

            case Opcodes.REDUCE:
                load_reduce();
                break;

            case Opcodes.STRING:
                load_string();
                break;

            case Opcodes.BINSTRING:
                load_binstring();
                break;

            case Opcodes.SHORT_BINSTRING:
                load_short_binstring();
                break;

            case Opcodes.UNICODE:
                load_unicode();
                break;

            case Opcodes.BINUNICODE:
                load_binunicode();
                break;

            case Opcodes.APPEND:
                load_append();
                break;

            case Opcodes.BUILD:
                load_build();
                break;

            case Opcodes.GLOBAL:
                load_global();
                break;

            case Opcodes.DICT:
                load_dict();
                break;

            case Opcodes.EMPTY_DICT:
                load_empty_dictionary();
                break;

            case Opcodes.APPENDS:
                load_appends();
                break;

            case Opcodes.GET:
                load_get();
                break;

            case Opcodes.BINGET:
                load_binget();
                break;

            case Opcodes.INST:
                throw new InvalidOpcodeException("opcode not implemented: INST");

            case Opcodes.LONG_BINGET:
                load_long_binget();
                break;

            case Opcodes.LIST:
                load_list();
                break;

            case Opcodes.EMPTY_LIST:
                load_empty_list();
                break;

            case Opcodes.OBJ:
                throw new InvalidOpcodeException("opcode not implemented: OBJ");

            case Opcodes.PUT:
                load_put();
                break;

            case Opcodes.BINPUT:
                load_binput();
                break;

            case Opcodes.LONG_BINPUT:
                load_long_binput();
                break;

            case Opcodes.SETITEM:
                load_setitem();
                break;

            case Opcodes.TUPLE:
                load_tuple();
                break;

            case Opcodes.EMPTY_TUPLE:
                load_empty_tuple();
                break;

            case Opcodes.SETITEMS:
                load_setitems();
                break;

            case Opcodes.BINFLOAT:
                load_binfloat();
                break;

            // protocol 2
            case Opcodes.PROTO:
                load_proto();
                break;

            case Opcodes.NEWOBJ:
                load_newobj();
                break;

            case Opcodes.EXT1:
                throw new InvalidOpcodeException("opcode not implemented: EXT1");

            case Opcodes.EXT2:
                throw new InvalidOpcodeException("opcode not implemented: EXT2");

            case Opcodes.EXT4:
                throw new InvalidOpcodeException("opcode not implemented: EXT4");

            case Opcodes.TUPLE1:
                load_tuple1();
                break;

            case Opcodes.TUPLE2:
                load_tuple2();
                break;

            case Opcodes.TUPLE3:
                load_tuple3();
                break;

            case Opcodes.NEWTRUE:
                load_true();
                break;

            case Opcodes.NEWFALSE:
                load_false();
                break;

            case Opcodes.LONG1:
                load_long1();
                break;

            case Opcodes.LONG4:
                load_long4();
                break;

            // Protocol 3 (Python 3.x)
            case Opcodes.BINBYTES:
                load_binbytes();
                break;

            case Opcodes.SHORT_BINBYTES:
                load_short_binbytes();
                break;

            default:
                throw new InvalidOpcodeException("invalid pickle opcode: " + key);
            }
        }