[pywin32-checkins] pywin32/Pythonwin/pywin/framework stdin.py, 1.5, 1.6
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2008-11-26 02:16:40
|
Update of /cvsroot/pywin32/pywin32/Pythonwin/pywin/framework In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14284/pywin/framework Modified Files: stdin.py Log Message: Cleanup old strange code that attempted to (poorly) delegate to another file object when closed! This fixes py3k where the real sys.stdin is actually None in a GUI. Index: stdin.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/framework/stdin.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** stdin.py 14 Nov 2008 00:22:25 -0000 1.5 --- stdin.py 26 Nov 2008 01:32:08 -0000 1.6 *************** *** 18,25 **** """ import sys - import string - true = 1 - false = 0 try: get_input_line = raw_input # py2x --- 18,22 ---- *************** *** 29,38 **** class Stdin: def __init__(self): ! self.real_file = sys.stdin self.buffer = "" def __getattr__(self, name): """Forward most functions to the real sys.stdin for absolute realism. """ return getattr(self.real_file, name) --- 26,38 ---- class Stdin: def __init__(self): ! self.real_file = sys.stdin # NOTE: Likely to be None in py3k self.buffer = "" + self.closed = False def __getattr__(self, name): """Forward most functions to the real sys.stdin for absolute realism. """ + if self.real_file is None: + raise AttributeError, name return getattr(self.real_file, name) *************** *** 50,59 **** EOF is encountered immediately. (For certain files, like ttys, it makes sense to continue reading after an EOF is hit.)""" - if self.closed: - return self.real_file.read(size) - result_size = self.__get_lines(size) return self.__extract_from_buffer(result_size) - def readline(self, size = -1): --- 50,55 ---- *************** *** 67,73 **** in the input. """ - if self.closed: - return self.real_file.readline(size) - maximum_result_size = self.__get_lines(size, lambda buffer: '\n' in buffer) --- 63,66 ---- *************** *** 88,92 **** return result ! def __get_lines(self, desired_size, done_reading = lambda buffer: false): """Keep adding lines to our internal buffer until done_reading(self.buffer) is true or EOF has been reached or we have desired_size bytes in the buffer. --- 81,85 ---- return result ! def __get_lines(self, desired_size, done_reading = lambda buffer: False): """Keep adding lines to our internal buffer until done_reading(self.buffer) is true or EOF has been reached or we have desired_size bytes in the buffer. *************** *** 101,107 **** try: self.__get_line() ! except: # deal with cancellation of get_input_line dialog desired_size = len(self.buffer) # Be satisfied! ! pass if desired_size < 0: return len(self.buffer) --- 94,100 ---- try: self.__get_line() ! except EOFError: # deal with cancellation of get_input_line dialog desired_size = len(self.buffer) # Be satisfied! ! if desired_size < 0: return len(self.buffer) *************** *** 122,128 **** (possibly after rounding up to an internal buffer size) are read. """ - if self.closed: - return self.real_file.readlines(*sizehint) - result = [] total_read = 0 --- 115,118 ---- |