📄 cpickle.java
字号:
case BININT: load_binint(); break; case BININT1: load_binint1(); break; case BININT2: load_binint2(); break; case LONG: load_long(); break; case FLOAT: load_float(); break; case BINFLOAT: load_binfloat(); break; case STRING: load_string(); break; case BINSTRING: load_binstring(); break; case SHORT_BINSTRING: load_short_binstring(); break; case UNICODE: load_unicode(); break; case BINUNICODE: load_binunicode(); break; case TUPLE: load_tuple(); break; case EMPTY_TUPLE: load_empty_tuple(); break; case EMPTY_LIST: load_empty_list(); break; case EMPTY_DICT: load_empty_dictionary(); break; case LIST: load_list(); break; case DICT: load_dict(); break; case INST: load_inst(); break; case OBJ: load_obj(); break; case GLOBAL: load_global(); break; case REDUCE: load_reduce(); break; case POP: load_pop(); break; case POP_MARK: load_pop_mark(); break; case DUP: load_dup(); break; case GET: load_get(); break; case BINGET: load_binget(); break; case LONG_BINGET: load_long_binget(); break; case PUT: load_put(); break; case BINPUT: load_binput(); break; case LONG_BINPUT: load_long_binput(); break; case APPEND: load_append(); break; case APPENDS: load_appends(); break; case SETITEM: load_setitem(); break; case SETITEMS: load_setitems(); break; case BUILD: load_build(); break; case MARK: load_mark(); break; case STOP: return load_stop(); } } } final private int marker() { for (int k = stackTop-1; k >= 0; k--) if (stack[k] == mark) return stackTop-k-1; throw new PyException(UnpicklingError, "Inputstream corrupt, marker not found"); } final private void load_eof() { throw new PyException(Py.EOFError); } final private void load_persid() { String pid = file.readlineNoNl(); push(persistent_load.__call__(new PyString(pid))); } final private void load_binpersid() { PyObject pid = pop(); push(persistent_load.__call__(pid)); } final private void load_none() { push(Py.None); } final private void load_int() { String line = file.readlineNoNl(); // XXX: use strop instead? push(new PyInteger(Integer.parseInt(line))); } final private void load_binint() { String s = file.read(4); int x = s.charAt(0) | (s.charAt(1)<<8) | (s.charAt(2)<<16) | (s.charAt(3)<<24); push(new PyInteger(x)); } final private void load_binint1() { int val = (int)file.read(1).charAt(0); push(new PyInteger(val)); } final private void load_binint2() { String s = file.read(2); int val = ((int)s.charAt(1)) << 8 | ((int)s.charAt(0)); push(new PyInteger(val)); } final private void load_long() { String line = file.readlineNoNl(); push(new PyLong(line.substring(0, line.length()-1))); } final private void load_float() { String line = file.readlineNoNl(); push(new PyFloat(Double.valueOf(line).doubleValue())); } final private void load_binfloat() { String s = file.read(8); long bits = (long)s.charAt(7) | ((long)s.charAt(6) << 8) | ((long)s.charAt(5) << 16) | ((long)s.charAt(4) << 24) | ((long)s.charAt(3) << 32) | ((long)s.charAt(2) << 40) | ((long)s.charAt(1) << 48) | ((long)s.charAt(0) << 56); push(new PyFloat(Double.longBitsToDouble(bits))); } final private void load_string() { String line = file.readlineNoNl(); String value; char quote = line.charAt(0); if (quote != '"' && quote != '\'') throw Py.ValueError("insecure string pickle"); int nslash = 0; int i; char ch = '\0'; int n = line.length(); for (i = 1; i < n; i++) { ch = line.charAt(i); if (ch == quote && nslash % 2 == 0) break; if (ch == '\\') nslash++; else nslash = 0; } if (ch != quote) throw Py.ValueError("insecure string pickle"); for (i++ ; i < line.length(); i++) { if (line.charAt(i) > ' ') throw Py.ValueError("insecure string pickle " + i); } value = PyString.decode_UnicodeEscape(line, 1, n-1, "strict", false); push(new PyString(value)); } final private void load_binstring() { String d = file.read(4); int len = d.charAt(0) | (d.charAt(1)<<8) | (d.charAt(2)<<16) | (d.charAt(3)<<24); push(new PyString(file.read(len))); } final private void load_short_binstring() { int len = (int)file.read(1).charAt(0); push(new PyString(file.read(len))); } final private void load_unicode() { String line = file.readlineNoNl(); int n = line.length(); String value = codecs.PyUnicode_DecodeRawUnicodeEscape(line, "strict"); push(new PyString(value)); } final private void load_binunicode() { String d = file.read(4); int len = d.charAt(0) | (d.charAt(1)<<8) | (d.charAt(2)<<16) | (d.charAt(3)<<24); String line = file.read(len); push(new PyString(codecs.PyUnicode_DecodeUTF8(line, "strict"))); } final private void load_tuple() { PyObject[] arr = new PyObject[marker()]; pop(arr); pop(); push(new PyTuple(arr)); } final private void load_empty_tuple() { push(new PyTuple(Py.EmptyObjects)); } final private void load_empty_list() { push(new PyList(Py.EmptyObjects)); } final private void load_empty_dictionary() { push(new PyDictionary()); } final private void load_list() { PyObject[] arr = new PyObject[marker()]; pop(arr); pop(); push(new PyList(arr)); } final private void load_dict() { int k = marker(); PyDictionary d = new PyDictionary(); for (int i = 0; i < k; i += 2) { PyObject value = pop(); PyObject key = pop(); d.__setitem__(key, value); } pop(); push(d); } final private void load_inst() { PyObject[] args = new PyObject[marker()]; pop(args); pop(); String module = file.readlineNoNl(); String name = file.readlineNoNl(); PyObject klass = find_class(module, name); PyObject value = null; if (args.length == 0 && klass instanceof PyClass && klass.__findattr__("__getinitargs__") == null) { value = new PyInstance((PyClass)klass); } else { value = klass.__call__(args); } push(value); } final private void load_obj() { PyObject[] args = new PyObject[marker()-1]; pop(args); PyObject klass = pop(); pop(); PyObject value = null; if (args.length == 0 && klass instanceof PyClass && klass.__findattr__("__getinitargs__") == null) { value = new PyInstance((PyClass)klass); } else { value = klass.__call__(args); } push(value); } final private void load_global() { String module = file.readlineNoNl(); String name = file.readlineNoNl(); PyObject klass = find_class(module, name); push(klass); } final private PyObject find_class(String module, String name) { PyObject fc = dict.__finditem__("find_global"); if (fc != null) { if (fc == Py.None) throw new PyException(UnpicklingError, "Global and instance pickles are not supported."); return fc.__call__(new PyString(module), new PyString(name)); } PyObject modules = Py.getSystemState().modules; PyObject mod = modules.__finditem__(module.intern()); if (mod == null) { mod = importModule(module); } PyObject global = mod.__findattr__(name.intern()); if (global == null) { throw new PyException(Py.SystemError, "Failed to import class " + name + " from module " + module); } return global; } final private void load_reduce() { PyObject arg_tup = pop(); PyObject callable = pop(); if (!(callable instanceof PyClass)) { if (safe_constructors.__finditem__(callable) == null) { if (callable.__findattr__("__safe_for_unpickling__") == null) throw new PyException(UnpicklingError, callable + " is not safe for unpickling"); } } PyObject value = null; if (arg_tup == Py.None) { // XXX __basicnew__ ? value = callable.__findattr__("__basicnew__").__call__(); } else { value = callable.__call__(make_array(arg_tup)); } push(value); } final private PyObject[] make_array(PyObject seq) { int n = seq.__len__(); PyObject[] objs= new PyObject[n]; for(int i=0; i<n; i++) objs[i] = seq.__finditem__(i); return objs; } final private void load_pop() { pop(); } final private void load_pop_mark() { pop(marker()); } final private void load_dup() { push(peek()); } final private void load_get() { String py_str = file.readlineNoNl(); PyObject value = (PyObject)memo.get(py_str); if (value == null) throw new PyException(BadPickleGet, py_str); push(value); } final private void load_binget() { String py_key = String.valueOf((int)file.read(1).charAt(0)); PyObject value = (PyObject)memo.get(py_key); if (value == null) throw new PyException(BadPickleGet, py_key); push(value); } final private void load_long_binget() { String d = file.read(4); int i = d.charAt(0) | (d.charAt(1)<<8) | (d.charAt(2)<<16) | (d.charAt(3)<<24); String py_key = String.valueOf(i); PyObject value = (PyObject)memo.get(py_key); if (value == null) throw new PyException(BadPickleGet, py_key); push(value); } final private void load_put() { memo.put(file.readlineNoNl(), peek()); } final private void load_binput() { int i = (int)file.read(1).charAt(0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -