public void TestClassDictConstructorSetsClass() { ClassDict cd = new ClassDict("module", "myclass"); Assert.Equal("module.myclass", cd["__class__"]); ClassDictConstructor cdc = new ClassDictConstructor("module", "myclass"); cd = (ClassDict)cdc.construct(new object[] {}); Assert.Equal("module.myclass", cd["__class__"]); Assert.Equal("module.myclass", cd.ClassName); }
private void load_global_sub(string module, string name) { IObjectConstructor constructor; string key = module + "." + name; if (objectConstructors.ContainsKey(key)) { constructor = objectConstructors[module + "." + name]; } else { switch (module) { // check if it is an exception case "exceptions": // python 2.x constructor = new ExceptionConstructor(typeof(PythonException), module, name); break; case "builtins": case "__builtin__": if (name.EndsWith("Error") || name.EndsWith("Warning") || name.EndsWith("Exception") || name == "GeneratorExit" || name == "KeyboardInterrupt" || name == "StopIteration" || name == "SystemExit") { // it's a python 3.x exception constructor = new ExceptionConstructor(typeof(PythonException), module, name); } else { // return a dictionary with the class's properties constructor = new ClassDictConstructor(module, name); } break; default: constructor = new ClassDictConstructor(module, name); break; } } stack.add(constructor); }
void load_global() { IObjectConstructor constructor; string module = pu.readline(); string name = pu.readline(); string key = module + "." + name; if (objectConstructors.ContainsKey(key)) { constructor = objectConstructors[module + "." + name]; } else { // check if it is an exception if (module == "exceptions") { // python 2.x constructor = new AnyClassConstructor(typeof(PythonException)); } else if (module == "builtins" || module == "__builtin__") { if (name.EndsWith("Error") || name.EndsWith("Warning") || name.EndsWith("Exception") || name == "GeneratorExit" || name == "KeyboardInterrupt" || name == "StopIteration" || name == "SystemExit") { // it's a python 3.x exception constructor = new AnyClassConstructor(typeof(PythonException)); } else { // return a dictionary with the class's properties constructor = new ClassDictConstructor(module, name); } } else { // return a dictionary with the class's properties constructor = new ClassDictConstructor(module, name); } } stack.add(constructor); }
void load_inst() { string module = PickleUtils.readline(input); string classname = PickleUtils.readline(input); ArrayList args = stack.pop_all_since_marker(); IObjectConstructor constructor; if (objectConstructors.ContainsKey(module + "." + classname)) { constructor = objectConstructors[module + "." + classname]; } else { constructor = new ClassDictConstructor(module, classname); args.Clear(); // classdict doesn't have constructor args... so we may lose info here, hmm. } object obj = constructor.construct(args.ToArray()); stack.add(obj); }
void load_global_sub(string module, string name) { IObjectConstructor constructor; string key=module+"."+name; if(objectConstructors.ContainsKey(key)) { constructor = objectConstructors[module + "." + name]; } else { // check if it is an exception if(module=="exceptions") { // python 2.x constructor=new AnyClassConstructor(typeof(PythonException)); } else if(module=="builtins" || module=="__builtin__") { if(name.EndsWith("Error") || name.EndsWith("Warning") || name.EndsWith("Exception") || name=="GeneratorExit" || name=="KeyboardInterrupt" || name=="StopIteration" || name=="SystemExit") { // it's a python 3.x exception constructor=new AnyClassConstructor(typeof(PythonException)); } else { // return a dictionary with the class's properties constructor=new ClassDictConstructor(module, name); } } else { // return a dictionary with the class's properties constructor=new ClassDictConstructor(module, name); } } stack.add(constructor); }