pyrepl/pyrepl python_reader.py,1.4,1.5 unix_console.py,1.5,1.6

[email protected] Fri, 16 May 2003 15:08:46 +0200 (MEST)
Newsgroups gmane.comp.python.pyrepl.checkins
Message-ID <[email protected]>
Update of /cvs/pyrepl/pyrepl/pyrepl
In directory thoth.codespeak.net:/tmp/cvs-serv13786

Modified Files:
	python_reader.py unix_console.py 
Log Message:
Allow different files for input and output for unix_console.

Also store both file objects and file descriptors in the UnixConsole
instance.


Index: python_reader.py
===================================================================
RCS file: /cvs/pyrepl/pyrepl/pyrepl/python_reader.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** python_reader.py	17 Jan 2003 14:01:50 -0000	1.4
--- python_reader.py	16 May 2003 13:08:43 -0000	1.5
***************
*** 310,314 ****
          else:
              from pyrepl.unix_console import UnixConsole
!             con = UnixConsole(1, None)
          print "Python", sys.version, "on", sys.platform
          print 'Type "copyright", "credits" or "license" for more information.'
--- 310,314 ----
          else:
              from pyrepl.unix_console import UnixConsole
!             con = UnixConsole(0, 1, None)
          print "Python", sys.version, "on", sys.platform
          print 'Type "copyright", "credits" or "license" for more information.'

Index: unix_console.py
===================================================================
RCS file: /cvs/pyrepl/pyrepl/pyrepl/unix_console.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** unix_console.py	17 Jan 2003 14:07:29 -0000	1.5
--- unix_console.py	16 May 2003 13:08:43 -0000	1.6
***************
*** 69,73 ****
          term, fd = os.environ["TERM"], 0
      else:
!         term, fd = con.term, con.fd
      try:
          return _keysets[(term, fd)]
--- 69,73 ----
          term, fd = os.environ["TERM"], 0
      else:
!         term, fd = con.term, con.input_fd
      try:
          return _keysets[(term, fd)]
***************
*** 112,120 ****
  
  class UnixConsole(Console):
!     def __init__(self, fd, term):
!         self.fd = fd
          self.pollob = poll()
!         self.pollob.register(fd, POLLIN)
!         curses.setupterm(term, fd)
          self.term = term
          
--- 112,133 ----
  
  class UnixConsole(Console):
!     def __init__(self, f_in=0, f_out=1, term=None):
!         if isinstance(f_in, int):
!             self.input = os.fdopen(f_in)
!             self.input_fd = f_in
!         else:
!             self.input = f_in
!             self.input_fd = f_in.fileno()
! 
!         if isinstance(f_out, int):
!             self.output = os.fdopen(f_out)
!             self.output_fd = f_out
!         else:
!             self.output = f_out
!             self.output_fd = f_out.fileno()
!         
          self.pollob = poll()
!         self.pollob.register(self.input_fd, POLLIN)
!         curses.setupterm(term, self.output_fd)
          self.term = term
          
***************
*** 250,256 ****
          self.__offset = offset
  
-         # in the refresh loop we check for a common case: the
-         # insertion of a single character.
- 
          for y, oldline, newline, in zip(range(offset, offset + height),
                                          oldscr,
--- 263,266 ----
***************
*** 371,375 ****
      def prepare(self):
          # per-readline preparations:
!         self.__svtermstate = tcgetattr(self.fd)
          raw = self.__svtermstate.copy()
          raw.iflag &=~ (termios.BRKINT | termios.INPCK |
--- 381,385 ----
      def prepare(self):
          # per-readline preparations:
!         self.__svtermstate = tcgetattr(self.input_fd)
          raw = self.__svtermstate.copy()
          raw.iflag &=~ (termios.BRKINT | termios.INPCK |
***************
*** 382,386 ****
          raw.cc[termios.VMIN] = 1
          raw.cc[termios.VTIME] = 0
!         tcsetattr(self.fd, termios.TCSADRAIN, raw)
  
          self.screen = []
--- 392,396 ----
          raw.cc[termios.VMIN] = 1
          raw.cc[termios.VTIME] = 0
!         tcsetattr(self.input_fd, termios.TCSADRAIN, raw)
  
          self.screen = []
***************
*** 407,411 ****
          self.__maybe_write_code(self._rmkx)
          self.flushoutput()
!         tcsetattr(self.fd, termios.TCSADRAIN, self.__svtermstate)
  
          signal.signal(signal.SIGWINCH, self.old_sigwinch)
--- 417,421 ----
          self.__maybe_write_code(self._rmkx)
          self.flushoutput()
!         tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
  
          signal.signal(signal.SIGWINCH, self.old_sigwinch)
***************
*** 422,427 ****
                  while 1: # All hail Unix!
                      try:
!                         c = os.read(self.fd, 1)
!                     except OSError, err:
                          if err.errno == errno.EINTR:
                              if self.__event_queue:
--- 432,437 ----
                  while 1: # All hail Unix!
                      try:
!                         c = self.input.read(1)
!                     except IOError, err:
                          if err.errno == errno.EINTR:
                              if self.__event_queue:
***************
*** 474,478 ****
              except KeyError:
                  height, width = struct.unpack(
!                     "hhhh", ioctl(self.fd, TIOCGWINSZ, "\000"*8))[0:2]
                  if not height: return 25, 80
                  return height, width
--- 484,488 ----
              except KeyError:
                  height, width = struct.unpack(
!                     "hhhh", ioctl(self.input_fd, TIOCGWINSZ, "\000"*8))[0:2]
                  if not height: return 25, 80
                  return height, width
***************
*** 485,489 ****
  
      def forgetinput(self):
!         termios.tcflush(self.fd, termios.TCIFLUSH)
  
      def flushoutput(self):
--- 495,499 ----
  
      def forgetinput(self):
!         termios.tcflush(self.input_fd, termios.TCIFLUSH)
  
      def flushoutput(self):
***************
*** 492,496 ****
                  self.__tputs(text)
              else:
!                 os.write(self.fd, text)
          del self.__buffer[:]
  
--- 502,506 ----
                  self.__tputs(text)
              else:
!                 os.write(self.output_fd, text))
          del self.__buffer[:]
  
***************
*** 508,515 ****
              m = prog.search(fmt)
              if not m:
!                 os.write(self.fd, fmt)
                  break
              x, y = m.span()
!             os.write(self.fd, fmt[:x])
              fmt = fmt[y:]
              delay = int(m.group(1))
--- 518,525 ----
              m = prog.search(fmt)
              if not m:
!                 os.write(self.output_fd, fmt)
                  break
              x, y = m.span()
!             os.write(self.output_fd, fmt[:x])
              fmt = fmt[y:]
              delay = int(m.group(1))
***************
*** 518,522 ****
              if self._pad:
                  nchars = (bps*delay)/1000
!                 os.write(self.fd, self._pad*nchars)
              else:
                  time.sleep(float(delay)/1000.0)
--- 528,532 ----
              if self._pad:
                  nchars = (bps*delay)/1000
!                 os.write(self.output_fd, self._pad*nchars)
              else:
                  time.sleep(float(delay)/1000.0)
***************
*** 537,545 ****
          def getpending(self):
              amount = struct.unpack(
!                 "i", ioctl(self.fd, FIONREAD, "\0\0\0\0"))[0]
!             return os.read(self.fd, amount)
      else:
          def getpending(self):
!             return os.read(self.fd, 100000) # that should be enough :)
  
      def clear(self):
--- 547,555 ----
          def getpending(self):
              amount = struct.unpack(
!                 "i", ioctl(self.input_fd, FIONREAD, "\0\0\0\0"))[0]
!             return os.read(self.input_fd, amount)
      else:
          def getpending(self):
!             return os.read(self.input_fd, 100000) # that should be enough :)
  
      def clear(self):