Show More
@@ -748,6 +748,8 var IPython = (function (IPython) { | |||||
748 | // disable any other raw_inputs, if they are left around |
|
748 | // disable any other raw_inputs, if they are left around | |
749 | $("div.output_subarea.raw_input_container").remove(); |
|
749 | $("div.output_subarea.raw_input_container").remove(); | |
750 |
|
750 | |||
|
751 | var input_type = content.password ? 'password' : 'text'; | |||
|
752 | ||||
751 | area.append( |
|
753 | area.append( | |
752 | $("<div/>") |
|
754 | $("<div/>") | |
753 | .addClass("box-flex1 output_subarea raw_input_container") |
|
755 | .addClass("box-flex1 output_subarea raw_input_container") | |
@@ -759,7 +761,7 var IPython = (function (IPython) { | |||||
759 | .append( |
|
761 | .append( | |
760 | $("<input/>") |
|
762 | $("<input/>") | |
761 | .addClass("raw_input") |
|
763 | .addClass("raw_input") | |
762 |
.attr('type', |
|
764 | .attr('type', input_type) | |
763 | .attr("size", 47) |
|
765 | .attr("size", 47) | |
764 | .keydown(function (event, ui) { |
|
766 | .keydown(function (event, ui) { | |
765 | // make sure we submit on enter, |
|
767 | // make sure we submit on enter, | |
@@ -788,10 +790,15 var IPython = (function (IPython) { | |||||
788 | var theprompt = container.find("span.raw_input_prompt"); |
|
790 | var theprompt = container.find("span.raw_input_prompt"); | |
789 | var theinput = container.find("input.raw_input"); |
|
791 | var theinput = container.find("input.raw_input"); | |
790 | var value = theinput.val(); |
|
792 | var value = theinput.val(); | |
|
793 | var echo = value; | |||
|
794 | // don't echo if it's a password | |||
|
795 | if (theinput.attr('type') == 'password') { | |||
|
796 | echo = '········'; | |||
|
797 | } | |||
791 | var content = { |
|
798 | var content = { | |
792 | output_type : 'stream', |
|
799 | output_type : 'stream', | |
793 | name : 'stdout', |
|
800 | name : 'stdout', | |
794 |
text : theprompt.text() + |
|
801 | text : theprompt.text() + echo + '\n' | |
795 | } |
|
802 | } | |
796 | // remove form container |
|
803 | // remove form container | |
797 | container.parent().remove(); |
|
804 | container.parent().remove(); |
@@ -6,6 +6,7 | |||||
6 |
|
6 | |||
7 | from __future__ import print_function |
|
7 | from __future__ import print_function | |
8 |
|
8 | |||
|
9 | import getpass | |||
9 | import sys |
|
10 | import sys | |
10 | import time |
|
11 | import time | |
11 | import traceback |
|
12 | import traceback | |
@@ -333,7 +334,42 class Kernel(Configurable): | |||||
333 | parent=parent, |
|
334 | parent=parent, | |
334 | ident=self._topic('status'), |
|
335 | ident=self._topic('status'), | |
335 | ) |
|
336 | ) | |
|
337 | ||||
|
338 | def _forward_raw_input(self, ident, parent, allow_stdin): | |||
|
339 | """Replace raw_input. Note that is not sufficient to replace | |||
|
340 | raw_input in the user namespace. | |||
|
341 | """ | |||
|
342 | ||||
|
343 | if allow_stdin: | |||
|
344 | raw_input = lambda prompt='': self._raw_input(prompt, ident, parent) | |||
|
345 | input = lambda prompt='': eval(raw_input(prompt)) | |||
|
346 | _getpass = lambda prompt='', stream=None: self._raw_input( | |||
|
347 | prompt, ident, parent, password=True | |||
|
348 | ) | |||
|
349 | else: | |||
|
350 | _getpass = raw_input = input = lambda prompt='' : self._no_raw_input() | |||
|
351 | ||||
|
352 | ||||
|
353 | if py3compat.PY3: | |||
|
354 | self._sys_raw_input = builtin_mod.input | |||
|
355 | builtin_mod.input = raw_input | |||
|
356 | else: | |||
|
357 | self._sys_raw_input = builtin_mod.raw_input | |||
|
358 | self._sys_eval_input = builtin_mod.input | |||
|
359 | builtin_mod.raw_input = raw_input | |||
|
360 | builtin_mod.input = input | |||
|
361 | self._save_getpass = getpass.getpass | |||
|
362 | getpass.getpass = _getpass | |||
|
363 | ||||
|
364 | def _restore_raw_input(self): | |||
|
365 | # Restore raw_input | |||
|
366 | if py3compat.PY3: | |||
|
367 | builtin_mod.input = self._sys_raw_input | |||
|
368 | else: | |||
|
369 | builtin_mod.raw_input = self._sys_raw_input | |||
|
370 | builtin_mod.input = self._sys_eval_input | |||
336 |
|
371 | |||
|
372 | getpass.getpass = self._save_getpass | |||
337 |
|
373 | |||
338 | def execute_request(self, stream, ident, parent): |
|
374 | def execute_request(self, stream, ident, parent): | |
339 | """handle an execute_request""" |
|
375 | """handle an execute_request""" | |
@@ -354,22 +390,7 class Kernel(Configurable): | |||||
354 |
|
390 | |||
355 | shell = self.shell # we'll need this a lot here |
|
391 | shell = self.shell # we'll need this a lot here | |
356 |
|
392 | |||
357 | # Replace raw_input. Note that is not sufficient to replace |
|
393 | self._forward_raw_input(ident, parent, content.get('allow_stdin', False)) | |
358 | # raw_input in the user namespace. |
|
|||
359 | if content.get('allow_stdin', False): |
|
|||
360 | raw_input = lambda prompt='': self._raw_input(prompt, ident, parent) |
|
|||
361 | input = lambda prompt='': eval(raw_input(prompt)) |
|
|||
362 | else: |
|
|||
363 | raw_input = input = lambda prompt='' : self._no_raw_input() |
|
|||
364 |
|
||||
365 | if py3compat.PY3: |
|
|||
366 | self._sys_raw_input = builtin_mod.input |
|
|||
367 | builtin_mod.input = raw_input |
|
|||
368 | else: |
|
|||
369 | self._sys_raw_input = builtin_mod.raw_input |
|
|||
370 | self._sys_eval_input = builtin_mod.input |
|
|||
371 | builtin_mod.raw_input = raw_input |
|
|||
372 | builtin_mod.input = input |
|
|||
373 |
|
394 | |||
374 | # Set the parent message of the display hook and out streams. |
|
395 | # Set the parent message of the display hook and out streams. | |
375 | shell.set_parent(parent) |
|
396 | shell.set_parent(parent) | |
@@ -398,12 +419,7 class Kernel(Configurable): | |||||
398 | else: |
|
419 | else: | |
399 | status = u'ok' |
|
420 | status = u'ok' | |
400 | finally: |
|
421 | finally: | |
401 |
|
|
422 | self._restore_raw_input() | |
402 | if py3compat.PY3: |
|
|||
403 | builtin_mod.input = self._sys_raw_input |
|
|||
404 | else: |
|
|||
405 | builtin_mod.raw_input = self._sys_raw_input |
|
|||
406 | builtin_mod.input = self._sys_eval_input |
|
|||
407 |
|
423 | |||
408 | reply_content[u'status'] = status |
|
424 | reply_content[u'status'] = status | |
409 |
|
425 | |||
@@ -727,8 +743,8 class Kernel(Configurable): | |||||
727 | stdin.""" |
|
743 | stdin.""" | |
728 | raise StdinNotImplementedError("raw_input was called, but this " |
|
744 | raise StdinNotImplementedError("raw_input was called, but this " | |
729 | "frontend does not support stdin.") |
|
745 | "frontend does not support stdin.") | |
730 |
|
|
746 | ||
731 | def _raw_input(self, prompt, ident, parent): |
|
747 | def _raw_input(self, prompt, ident, parent, password=False): | |
732 | # Flush output before making the request. |
|
748 | # Flush output before making the request. | |
733 | sys.stderr.flush() |
|
749 | sys.stderr.flush() | |
734 | sys.stdout.flush() |
|
750 | sys.stdout.flush() | |
@@ -743,7 +759,7 class Kernel(Configurable): | |||||
743 | raise |
|
759 | raise | |
744 |
|
760 | |||
745 | # Send the input request. |
|
761 | # Send the input request. | |
746 | content = json_clean(dict(prompt=prompt)) |
|
762 | content = json_clean(dict(prompt=prompt, password=password)) | |
747 | self.session.send(self.stdin_socket, u'input_request', content, parent, |
|
763 | self.session.send(self.stdin_socket, u'input_request', content, parent, | |
748 | ident=ident) |
|
764 | ident=ident) | |
749 |
|
765 |
General Comments 0
You need to be logged in to leave comments.
Login now