Open aivarannamaa opened 10 years ago
Not able to test this at the moment, but I figure this has to do with some assumptions that the built in sys.stdin
that we are mocking operates on - it not receiving anything is assumed to be the same as entering EOF.
A workaround for this should be to m.stdin.put("\n")
which I would expect to behave much the same.
You can also dig into the python stdio implementation or spec and fix it yourself - I can give you commit access. :)
A workaround for this should be to m.stdin.put("\n")
Nope, this results in "\n\n" being sent to stdin.
While digging I arrived here - https://github.com/akheron/cpython/blob/d04cd9a21a22a56ec3cb577229808c019217b8e0/Objects/fileobject.c#L107. Not sure what the fix is, but perhaps will help you.
A workaround for this should be to m.stdin.put("\n")
Nope, this results in "\n\n" being sent to stdin.
My mistake, I tested it incorrectly. The workaround actually works.
But I also noticed that you're using the same m.stdin
object as spoofed stdin (I thought this is just a convenience wrapper). The problem is that it doesn't follow the normal stream contract which says that method readline
reads up to and including next newline in the stream (or up to EOF). Current code works as long as one doesn't put
a string with newline in the middle and when stdin
is read only with input
(which strips the (possibly non-existing) trailing newline anyway).
My plan is to replace everywhere in my fork m.stdin.write
-s with m.stdin.put
-s, redefine SpoofedStdin.write
and SpoofedStdin.readline
according to stream contract and leave SpoofedStdin.put
as a conveniece method which appends "\n"
to input automatically.
That sounds like a plausibleplan - I'd prefer if you work directly on this repo (gave you access).
When my demo_solution.py is
and demo_tester.py is
Then
python -m grader demo_tester.py demo_solution.py
gives me