Java Code Examples for org.python.core.PyObject#__dir__
The following examples show how to use
org.python.core.PyObject#__dir__ .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JIntrospect.java From MeteoInfo with GNU Lesser General Public License v3.0 | 6 votes |
/** * Complete package name * * @param target Target * @return Package names */ public List<String> completePackageName(String target) { String[] targetComponents = target.split("\\."); String base = targetComponents[0]; PySystemState state = interp.getSystemState(); PyObject importer = state.getBuiltins().__getitem__(Py.newString("__import__")); PyObject module = importer.__call__(Py.newString(base)); if (targetComponents.length > 1) { for (int i = 1; i < targetComponents.length; i++) { module = module.__getattr__(targetComponents[i]); } } PyList plist = (PyList) module.__dir__(); List<String> list = new ArrayList<>(); String name; for (int i = 0; i < plist.__len__(); i++) { name = plist.get(i).toString(); if (!name.startsWith("__")) { list.add(name); } } //list.add("*"); return list; }
Example 2
Source File: JIntrospect.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get auto complete list * * @param command The command * @param includeMagic * @param includeSingle * @param includeDouble * @return Auto complete list * @throws java.io.IOException */ public List<String> getAutoCompleteList(String command, boolean includeMagic, boolean includeSingle, boolean includeDouble) throws IOException { // Temp KLUDGE here rather than in console.py //command += "."; if (command.startsWith("import ") || command.startsWith("from ")) { String target = getPackageName(command); if (target == null) { return null; } return completePackageName(target); } String root = this.getRoot(command, "."); if (root.isEmpty()) return null; try { PyObject object = this.interp.eval(root); PyList plist = (PyList) object.__dir__(); List<String> list = new ArrayList<>(); String name; for (int i = 0; i < plist.__len__(); i++) { name = plist.get(i).toString(); if (!name.startsWith("__")) { list.add(name); } } return list; } catch (Exception e){ return null; } }
Example 3
Source File: JIntrospect.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
/** * Get auto complete list * * @param command The command * @param includeMagic * @param includeSingle * @param includeDouble * @return Auto complete list * @throws java.io.IOException */ public List<String> getAutoCompleteList(String command, boolean includeMagic, boolean includeSingle, boolean includeDouble) throws IOException { // Temp KLUDGE here rather than in console.py //command += "."; if (command.startsWith("import ") || command.startsWith("from ")) { String target = getPackageName(command); if (target == null) { return null; } return completePackageName(target); } String root = this.getRoot(command, "."); if (root.isEmpty()) return null; try { PyObject object = this.interp.eval(root); PyList plist = (PyList) object.__dir__(); if (plist.contains("__all__")) { PyList nPlist = (PyList) object.__getattr__("__all__"); for (int i = 0; i < nPlist.__len__(); i++) { if (! plist.__contains__(nPlist.__getitem__(i))) { plist.add(nPlist.__getitem__(i)); } } } List<String> list = new ArrayList<>(); String name; for (int i = 0; i < plist.__len__(); i++) { name = plist.get(i).toString(); if (!name.contains("__")) { list.add(name); } } return list; } catch (Exception e){ return null; } }