/** * Returns either <code>object.__findattr__("keys").__call__()</code> * or <code>object.__findattr__("keySet").__call__()</code>. */ public TemplateCollectionModel keys() throws TemplateModelException { try { PyObject method = object.__findattr__(KEYS); if (method == null) { method = object.__findattr__(KEYSET); } if (method != null) { return (TemplateCollectionModel) wrapper.wrap(method.__call__()); } } catch (PyException e) { throw new TemplateModelException(e); } throw new TemplateModelException( "'?keys' is not supported as there is no 'keys' nor 'keySet' attribute on an instance of " + JythonVersionAdapterHolder.INSTANCE.getPythonClassName(object)); }
obj = object.__findattr__(key); if (obj == null) { obj = object.__finditem__(key); obj = object.__finditem__(key); if (obj == null) { obj = object.__findattr__(key);
/** * Returns <code>object.__findattr__("values").__call__()</code>. */ public TemplateCollectionModel values() throws TemplateModelException { try { PyObject method = object.__findattr__(VALUES); if (method != null) { return (TemplateCollectionModel) wrapper.wrap(method.__call__()); } } catch (PyException e) { throw new TemplateModelException(e); } throw new TemplateModelException( "'?values' is not supported as there is no 'values' attribute on an instance of " + JythonVersionAdapterHolder.INSTANCE.getPythonClassName(object)); } }
private static String warn_hcategory(PyObject category) { PyObject name = category.__findattr__("__name__"); if (name != null) { return "[" + name + "]"; } return "[warning]"; }
ObjectIOFile(PyObject file) { // this.file = file; write = file.__findattr__("write"); read = file.__findattr__("read"); readline = file.__findattr__("readline"); }
/** * Return the __bases__ of cls. Returns null if no valid __bases__ are found. */ private static PyTuple abstractGetBases(PyObject cls) { PyObject bases = cls.__findattr__("__bases__"); return bases instanceof PyTuple ? (PyTuple) bases : null; }
public class PeanutWrapper{ private PyObject pyObj; public String getKind(){ return pyObj.__findattr__("kind"); } ... }
private static synchronized PyObject get_errmsg_fn() { if (errmsg_fn == null) { PyObject json = org.python.core.__builtin__.__import__("json"); if (json != null) { PyObject decoder = json.__findattr__("decoder"); if (decoder != null) { errmsg_fn = decoder.__findattr__("errmsg"); } } } return errmsg_fn; }
public static PyObject reversed(PyObject seq) { PyObject reversed = seq.__findattr__("__reversed__"); if (reversed != null) { return reversed.__call__(); } else if (seq.__findattr__("__getitem__") != null && seq.__findattr__("__len__") != null && seq.__findattr__("keys") == null) { reversed = new PyReversedIterator(seq); } else { throw Py.TypeError("argument to reversed() must be a sequence"); } return reversed; }
private String getFuncName() { PyObject funcName = null; try { funcName = __func__.__findattr__("__name__"); } catch (PyException pye) { // continue } if (funcName == null) { return "?"; } return funcName.toString(); }
protected void mergeDictAttr(PyDictionary accum, String attr) { PyObject obj = __findattr__(attr); if (obj == null) { return; } if (obj instanceof PyDictionary || obj instanceof PyStringMap || obj instanceof PyDictProxy) { accum.update(obj); } }
private String getInstClassName(PyObject inst) { if (inst == null) { return "nothing"; } PyObject classObj = inst.__findattr__("__class__"); if (classObj == null) { classObj = inst.getType(); } return getClassName(classObj); }
protected void mergeListAttr(PyDictionary accum, String attr) { PyObject obj = __findattr__(attr); if (obj == null) { return; } if (obj instanceof PyList) { for (PyObject name : obj.asIterable()) { accum.__setitem__(name, Py.None); } } }
public static boolean hasattr(PyObject obj, PyObject nameObj) { String name = asName(nameObj, "hasattr"); try { return obj.__findattr__(name) != null; } catch (PyException pye) { if (pye.match(Py.KeyboardInterrupt) || pye.match(Py.SystemExit)) { throw pye; } //Otherwise swallow exception. } return false; }
protected void __rawdir__(PyDictionary accum) { mergeDictAttr(accum, "__dict__"); mergeListAttr(accum, "__methods__"); mergeListAttr(accum, "__members__"); // Class dict is a slower, more manual merge to match CPython PyObject itsClass = __findattr__("__class__"); if (itsClass != null) { mergeClassDict(accum, itsClass); } }
private static void runModule(InteractiveConsole interp, String moduleName, boolean set_argv0) { // PEP 338 - Execute module as a script try { PyObject runpy = imp.importName("runpy", true); PyObject runmodule = runpy.__findattr__("_run_module_as_main"); runmodule.__call__(Py.newStringOrUnicode(moduleName), Py.newBoolean(set_argv0)); } catch (Throwable t) { Py.printException(t); interp.cleanup(); System.exit(-1); } }
protected void mergeClassDict(PyDictionary accum, PyObject aClass) { // Merge in the type's dict (if any) aClass.mergeDictAttr(accum, "__dict__"); // Recursively merge in the base types' (if any) dicts PyObject bases = aClass.__findattr__("__bases__"); if (bases == null) { return; } // We have no guarantee that bases is a real tuple int len = bases.__len__(); for (int i = 0; i < len; i++) { mergeClassDict(accum, bases.__getitem__(i)); } }
private static PyObject slotnames(PyObject cls) { PyObject slotnames; slotnames = cls.fastGetDict().__finditem__("__slotnames__"); if (null != slotnames) { return slotnames; } PyObject copyreg = __builtin__.__import__("copy_reg", null, null, Py.EmptyTuple); PyObject copyreg_slotnames = copyreg.__findattr__("_slotnames"); slotnames = copyreg_slotnames.__call__(cls); if (null != slotnames && Py.None != slotnames && (!(slotnames instanceof PyList))) { throw Py.TypeError("copy_reg._slotnames didn't return a list or None"); } return slotnames; }
final private void load_reduce() { PyObject arg_tup = pop(); PyObject callable = pop(); 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); }
public static PyObject writer(PyObject[] args, String[] keywords) { ArgParser ap = parseArgs("writer", args, keywords); PyObject outputFile = ap.getPyObject(0); PyObject dialect = ap.getPyObject(1, null); PyObject writeline = outputFile.__findattr__("write"); if (writeline == null || !writeline.isCallable()) { throw Py.TypeError("argument 1 must have a \"write\" method"); } return new PyWriter(writeline, dialectFromKwargs(dialect, args, keywords)); }