public static PyString newStringOrUnicode(String s) { return newStringOrUnicode(Py.EmptyString, s); }
public PyException(PyObject type, String value) { this(type, Py.newStringOrUnicode(value)); }
public void println(String s) { print(Py.newStringOrUnicode(s), false, true); }
public void print(String s) { print(Py.newStringOrUnicode(s), false, false); }
public void error(Errno error, String extraData) { throw Py.OSError(error, Py.newStringOrUnicode(extraData)); }
public void error(Errno error, String methodName, String extraData) { throw Py.OSError(error, Py.newStringOrUnicode(extraData)); }
/** * Initialize the environ dict from System.getenv. environ may be empty when the * security policy doesn't grant us access. */ private static PyObject getEnviron() { PyObject environ = new PyDictionary(); Map<String, String> env; try { env = System.getenv(); } catch (SecurityException se) { return environ; } for (Map.Entry<String, String> entry : env.entrySet()) { environ.__setitem__( Py.newStringOrUnicode(entry.getKey()), Py.newStringOrUnicode(entry.getValue())); } return environ; }
private static PyList initArgv(String[] args) { PyList argv = new PyList(); if (args != null) { for (String arg : args) { argv.append(Py.newStringOrUnicode(arg)); } } return argv; }
public static PyObject getcwd() { return Py.newStringOrUnicode(Py.getSystemState().getCurrentWorkingDir()); }
public static PyList listdir(PyObject path) { File file = absolutePath(path).toFile(); String[] names = file.list(); if (names == null) { if (!file.isDirectory()) { throw Py.OSError(Errno.ENOTDIR, path); } if (!file.canRead()) { throw Py.OSError(Errno.EACCES, path); } throw Py.OSError("listdir(): an unknown error occurred: " + path); } PyList list = new PyList(); for (String name : names) { list.append(Py.newStringOrUnicode(path, name)); } return list; }
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); } }
private static boolean runMainFromImporter(InteractiveConsole interp, String filename) { // Support http://bugs.python.org/issue1739468 - Allow interpreter to execute a zip file or directory PyString argv0 = Py.newStringOrUnicode(filename); PyObject importer = imp.getImporter(argv0); if (!(importer instanceof PyNullImporter)) { /* argv0 is usable as an import source, so put it in sys.path[0] and import __main__ */ Py.getSystemState().path.insert(0, argv0); runModule(interp, "__main__", true); return true; } return false; }
@Hide(OS.NT) public static PyString readlink(PyObject path) { try { return Py.newStringOrUnicode(path, Files.readSymbolicLink(absolutePath(path)).toString()); } catch (NotLinkException ex) { throw Py.OSError(Errno.EINVAL, path); } catch (NoSuchFileException ex) { throw Py.OSError(Errno.ENOENT, path); } catch (IOException ioe) { throw Py.OSError(ioe); } catch (SecurityException ex) { throw Py.OSError(Errno.EACCES, path); } }
@ExposedMethod public String toString() { String owner = _lock.getOwnerName(); return Py.newString("<_threading.RLock owner=%r count=%d>"). __mod__(new PyTuple( owner != null ? Py.newStringOrUnicode(owner) : Py.None, Py.newInteger(_lock.getHoldCount()))).toString(); } }
@ExposedMethod public String toString() { String owner = _lock.getOwnerName(); return Py.newString("<_threading.Lock owner=%r locked=%s>"). __mod__(new PyTuple( owner != null ? Py.newStringOrUnicode(owner) : Py.None, Py.newBoolean(_lock.isLocked()))).toString(); }
path = ""; Py.getSystemState().path.insert(0, Py.newStringOrUnicode(path)); if (opts.jar) { try {