def lesspager(lines):
cmd = "<STR_LIT>"<EOL>if sys.version_info[<NUM_LIT:0>] >= <NUM_LIT:3>:<EOL><INDENT>"""<STR_LIT>"""<EOL>import subprocess<EOL>proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE)<EOL>try:<EOL><INDENT>with io.TextIOWrapper(proc.stdin, errors='<STR_LIT>') as pipe:<EOL><INDENT>try:<EOL><INDENT>for l in lines:<EOL><INDENT>pipe.write(l)<EOL><DEDENT><DEDENT>except KeyboardInterrupt:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>except OSError:<EOL><INDENT>pass <EOL><DEDENT>while True:<EOL><INDENT>try:<EOL><INDENT>proc.wait()<EOL>break<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>proc = os.popen(cmd, '<STR_LIT:w>')<EOL>try:<EOL><INDENT>for l in lines:<EOL><INDENT>proc.write(l)<EOL><DEDENT><DEDENT>except IOError:<EOL><INDENT>proc.close()<EOL>sys.exit()<EOL><DEDENT><DEDENT>
Use for streaming writes to a less process
Taken from pydoc.pipepager:
/usr/lib/python2.7/pydoc.py
and
/usr/lib/python3.5/pydoc.py