a oe@sdZddlZzeZWney*eZYn0GdddZedkrdad ddZ e Zz\eZ e e e e e e d e e d e e d e e WeZqeZ0nddlZee_dS) aProvides a class Stdin which can be used to emulate the regular old sys.stdin for the PythonWin interactive window. Right now it just pops up a raw_input() dialog. With luck, someone will integrate it into the actual PythonWin interactive window someday. WARNING: Importing this file automatically replaces sys.stdin with an instance of Stdin (below). This is useful because you can just open Stdin.py in PythonWin and hit the import button to get it set up right if you don't feel like changing PythonWin's source. To put things back the way they were, simply use this magic incantation: import sys sys.stdin = sys.stdin.real_file Nc@s`eZdZddZddZddZddd Zdd d Zd d ZddfddZ ddZ ddZ dS)StdincCstj|_d|_d|_dS)NF)sysstdin real_filebufferclosedselfr @C:\Program Files\Certbot\pkgs\pythonwin\pywin\framework\stdin.py__init__szStdin.__init__cCs|jdurt|t|j|S)zBForward most functions to the real sys.stdin for absolute realism.N)rAttributeErrorgetattr)r namer r r __getattr__!s zStdin.__getattr__cCsdS)zAReturn 1 if the file is connected to a tty(-like) device, else 0.r r r r r isatty'sz Stdin.isattycCs||}||S)aRead at most size bytes from the file (less if the read hits EOF or no more data is immediately available on a pipe, tty or similar device). If the size argument is negative or omitted, read all data until EOF is reached. The bytes are returned as a string object. An empty string is returned when EOF is encountered immediately. (For certain files, like ttys, it makes sense to continue reading after an EOF is hit.))_Stdin__get_lines_Stdin__extract_from_buffer)r size result_sizer r r read+s z Stdin.readcCsR||dd}d|jd|vrD|jdd|d}|dksHJn|}||S)aRead one entire line from the file. A trailing newline character is kept in the string2.6 (but may be absent when a file ends with an incomplete line). If the size argument is present and non-negative, it is a maximum byte count (including the trailing newline) and an incomplete line may be returned. An empty string is returned when EOF is hit immediately. Note: unlike stdio's fgets(), the returned string contains null characters ('') if they occurred in the input. cSsd|vS)N r rr r r @z Stdin.readline..rNrr)rrfindr)r rZmaximum_result_sizerr r r readline6s zStdin.readlinecCs"|jd|}|j|d|_|S)zfRemove the first character_count characters from the internal buffer and return them. Nr)r Zcharacter_countresultr r r Z__extract_from_bufferJszStdin.__extract_from_buffercCsdS)NFr rr r r rRrzStdin.c Csj||jsP|dks t|j|krPz |WqttfyLt|j}Yq0q|dkrbt|jS|SdS)aKeep 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. If desired_size < 0, we are never satisfied until we reach EOF. If done_reading is not supplied, it is not consulted. If desired_size < 0, returns the length of the internal buffer. Otherwise, returns desired_size. rN)rlen_Stdin__get_lineEOFErrorKeyboardInterrupt)r Z desired_sizeZ done_readingr r r Z __get_linesRs     zStdin.__get_linescCs$t}td||j|d|_dS)z@Grab one line from get_input_line() and append it to the buffer.z>>>rN)get_input_lineprintr)r liner r r Z __get_lineks zStdin.__get_linecGsJg}d}|dks||dkrF|}|dkr.qF|t|}||q|S)a3Read until EOF using readline() and return a list containing the lines thus read. If the optional sizehint argument is present, instead of reading up to EOF, whole lines totalling approximately sizehint bytes (possibly after rounding up to an internal buffer size) are read. rr r)rr!append)r sizehintr Z total_readr'r r r readlinesqs  zStdin.readlinesN)r)r) __name__ __module__ __qualname__r rrrrrrr"r*r r r r rs r__main__athis is some test input that I am hoping ~ will be very instructive and when I am done I will have tested everything. Twelve and twenty blackbirds baked in a pie. Patty cake patty cake so am I. ~ Thirty-five niggling idiots! Sell you soul to the devil, baby cCsZdtvrtt}n td}td|}t|ddat|dksP|ddkrVt|S)zjReplacement for raw_input() which pulls lines out of global test_input. For testing only! rNrr~) test_inputr!rr#)promptZend_of_line_posr r r r fake_raw_inputs   r2 /)N)__doc__rZ raw_inputr% NameErrorinputrr+r0r2xr&rrr*rr r r r s*   g