On input(..) use Sk.inputfun only if sys.stdin has not been overwritten. #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem: How to handle input and raw_input when sys.stdin is overwritten, e.g. via
sys.stdin = StringIO.StringIO(...).Sk.inputfunshould eventually be called, and may function like a browser alert including the prompt in the alert, and asking the user to supply the input.sys.stdinis overwritten, then this function should not be called, and instead the input should be read from the overwrittensys.stdin.Currently what happens is the following:
input/raw_input(Sk.builtin.raw_input) checks to see whetherSk.inputfunTakesPromptis true or not. If it is false then writes the prompt viasys["$d"]["stdout"]["write"]and reads the input viasys["$d"]["stdin"]["readline"]. This is OK behavior.Sk.inputfunTakesPromptis true, thenraw_inputdirectly calls onSk.builtin.file.$readlinebecause that method takes an extrapromptargument.Sk.builtin.file.$readlineis hard-coded to useSk.inputfunwhen thefilenois 0 (i.e. when thesys.stdinhas not been overwritten).sys.stdinhas been overwritten with e.g.StringIO(...), then whilesys["$d"]["stdin"]["readline"]would have activated the correctStringIOreadline, theSk.builtin.file.$readlinethat runs instead basically executes thefile.jsreadline but with a StringIO object. The result is expected errors when the variousfile.jsproperties are being accessed, e.g.self.lineList.length.Sk.builtin.file.$readlinewith a call tosys["$d"]["stdin"]["readline"]as the latter knows nothing about prompts and so can't handle the behavior of input by itself.raw_inputwhethersys.stdinhas been overwritten (by having the wrongfileno) and if it has been overwritten then it usessys["$d"]["stdin"]["readline"]instead, with any possible prompt written tosys.stdout.