| 211 | |
| 212 | |
| 213 | def _raw_input(prompt="", stream=None, input=None, echo_char=None, |
| 214 | term_ctrl_chars=None): |
| 215 | # This doesn't save the string in the GNU readline history. |
| 216 | if not stream: |
| 217 | stream = sys.stderr |
| 218 | if not input: |
| 219 | input = sys.stdin |
| 220 | prompt = str(prompt) |
| 221 | if prompt: |
| 222 | try: |
| 223 | stream.write(prompt) |
| 224 | except UnicodeEncodeError: |
| 225 | # Use replace error handler to get as much as possible printed. |
| 226 | prompt = prompt.encode(stream.encoding, 'replace') |
| 227 | prompt = prompt.decode(stream.encoding) |
| 228 | stream.write(prompt) |
| 229 | stream.flush() |
| 230 | # NOTE: The Python C API calls flockfile() (and unlock) during readline. |
| 231 | if echo_char: |
| 232 | return _readline_with_echo_char(stream, input, echo_char, |
| 233 | term_ctrl_chars, prompt) |
| 234 | line = input.readline() |
| 235 | if not line: |
| 236 | raise EOFError |
| 237 | if line[-1] == '\n': |
| 238 | line = line[:-1] |
| 239 | return line |
| 240 | |
| 241 | |
| 242 | def _readline_with_echo_char(stream, input, echo_char, term_ctrl_chars=None, |