[Jython-checkins] jython: Implement os.pipe() using java.nio.channels.Pipe. The pipe's source
darjus.loktevic
jython-checkins at python.org
Sun Nov 15 19:56:17 EST 2015
https://hg.python.org/jython/rev/9ac36add65aa
changeset: 7811:9ac36add65aa
user: Stephen Drake <steve at synergyconsultingnz.com>
date: Sat Nov 14 21:20:35 2015 +1100
summary:
Implement os.pipe() using java.nio.channels.Pipe. The pipe's source
and sink channels are wrapped with StreamIO to be compatible with
fdopen() and io.open().
Fixes http://bugs.jython.org/issue1984
files:
src/org/python/modules/posix/PosixModule.java | 21 ++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/src/org/python/modules/posix/PosixModule.java b/src/org/python/modules/posix/PosixModule.java
--- a/src/org/python/modules/posix/PosixModule.java
+++ b/src/org/python/modules/posix/PosixModule.java
@@ -12,6 +12,7 @@
import java.nio.channels.Channel;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel;
+import java.nio.channels.Pipe;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
@@ -50,6 +51,7 @@
import org.python.core.PyException;
import org.python.core.PyFile;
import org.python.core.PyFloat;
+import org.python.core.PyJavaType;
import org.python.core.PyList;
import org.python.core.PyObject;
import org.python.core.PyString;
@@ -60,6 +62,7 @@
import org.python.core.io.FileIO;
import org.python.core.io.IOBase;
import org.python.core.io.RawIOBase;
+import org.python.core.io.StreamIO;
import org.python.core.util.StringUtil;
/**
@@ -779,6 +782,24 @@
return new FileIO((PyString) path, fileIOMode);
}
+ public static PyString __doc__pipe = new PyString(
+ "pipe() -> (read_end, write_end)\n\n" +
+ "Create a pipe.");
+ public static PyTuple pipe() {
+ try {
+ Pipe pipe = Pipe.open();
+
+ StreamIO pipe_read = new StreamIO(pipe.source());
+ StreamIO pipe_write = new StreamIO(pipe.sink());
+
+ return new PyTuple(
+ PyJavaType.wrapJavaObject(pipe_read.fileno()),
+ PyJavaType.wrapJavaObject(pipe_write.fileno()));
+ } catch (IOException ioe) {
+ throw Py.OSError(ioe);
+ }
+ }
+
public static PyString __doc__popen = new PyString(
"popen(command [, mode='r' [, bufsize]]) -> pipe\n\n" +
"Open a pipe to/from a command returning a file object.");
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list