This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Arden
Recipients Arden
Date 2018-07-26.23:54:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1532649296.79.0.56676864532.issue34243@psf.upfronthosting.co.za>
In-reply-to
Content
# spawn(argv, master_read=_read, stdin_read=_read)

With stdin_read function it's possible to customize how one can read from stdin, but it makes little sense without stdout counterpart. For example, you cannot use a wrapped ssl socket to forward a terminal over secure connection, because os.write(STDOUT_FILENO, data) is not suitable for ssl sockets.

The proposal is to add stdout_write argument.

diff --git a/pty.py b/pty.py
index e841f12..ed4a12f 100644
--- a/pty.py
+++ b/pty.py
@@ -126,10 +126,10 @@ def _read(fd):
     """Default read function."""
     return os.read(fd, 1024)
 
-def _copy(master_fd, master_read=_read, stdin_read=_read):
+def _copy(master_fd, master_read=_read, stdin_read=_read, stdout_write=_writen):
     """Parent copy loop.
     Copies
-            pty master -> standard output   (master_read)
+            pty master -> standard output   (master_read, stdout_write)
             standard input -> pty master    (stdin_read)"""
     fds = [master_fd, STDIN_FILENO]
     while True:
@@ -139,7 +139,7 @@ def _copy(master_fd, master_read=_read, stdin_read=_read):
             if not data:  # Reached EOF.
                 fds.remove(master_fd)
             else:
-                os.write(STDOUT_FILENO, data)
+                stdout_write(STDOUT_FILENO, data)
         if STDIN_FILENO in rfds:
             data = stdin_read(STDIN_FILENO)
             if not data:
@@ -147,7 +147,7 @@ def _copy(master_fd, master_read=_read, stdin_read=_read):
             else:
                 _writen(master_fd, data)
 
-def spawn(argv, master_read=_read, stdin_read=_read):
+def spawn(argv, master_read=_read, stdin_read=_read, stdout_write=_writen):
     """Create a spawned process."""
     if type(argv) == type(''):
         argv = (argv,)
@@ -161,7 +161,7 @@ def spawn(argv, master_read=_read, stdin_read=_read):
     except tty.error:    # This is the same as termios.error
         restore = 0
     try:
-        _copy(master_fd, master_read, stdin_read)
+        _copy(master_fd, master_read, stdin_read, stdout_write)
     except OSError:
         if restore:
             tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)
History
Date User Action Args
2018-07-26 23:54:56Ardensetrecipients: + Arden
2018-07-26 23:54:56Ardensetmessageid: <1532649296.79.0.56676864532.issue34243@psf.upfronthosting.co.za>
2018-07-26 23:54:56Ardenlinkissue34243 messages
2018-07-26 23:54:56Ardencreate