Created
June 12, 2015 19:40
-
-
Save d33tah/09144ba0ce596a6b92ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env pypy | |
import json | |
import cStringIO | |
import sys | |
def main(): | |
BUFSIZE = 10240 | |
f = sys.stdin | |
decoder = json.JSONDecoder() | |
io = cStringIO.StringIO() | |
do_continue = True | |
while True: | |
read = f.read(BUFSIZE) | |
if len(read) < BUFSIZE: | |
do_continue = False | |
io.write(read) | |
try: | |
data, offset = decoder.raw_decode(io.getvalue()) | |
print(data) | |
rest = io.getvalue()[offset:] | |
io.close() | |
io = cStringIO.StringIO() | |
if rest.startswith('\n'): | |
io.write(rest[1:]) | |
else: | |
io.write(rest) | |
except ValueError, e: | |
#print(e) | |
#print(repr(io.getvalue())) | |
continue | |
if not do_continue: | |
break | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment