def _pipepager(text, cmd, color):
 import subprocess
 env = dict(os.environ)
 cmd_detail = cmd.rsplit('/', 1)[(-1)].split()
 if ((color is None) and (cmd_detail[0] == 'less')):
  less_flags = (os.environ.get('LESS', '') + ' '.join(cmd_detail[1:]))
  if (not less_flags):
   env['LESS'] = '-R'
   color = True
  elif (('r' in less_flags) or ('R' in less_flags)):
   color = True
 if (not color):
  text = strip_ansi(text)
 c = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, env=env)
 encoding = get_best_encoding(c.stdin)
 try:
  c.stdin.write(text.encode(encoding, 'replace'))
  c.stdin.close()
 except (IOError, KeyboardInterrupt):
  pass
 while True:
  try:
   c.wait()
  except KeyboardInterrupt:
   pass
  else:
   break

def _pipepager ( text , cmd , color ) : import subprocess env = dict ( os . environ ) cmd_detail = cmd . rsplit ( '/' , 1 ) [ ( - 1 ) ] . split ( ) if ( ( color is None ) and ( cmd_detail [ 0 ] == 'less' ) ) : less_flags = ( os . environ . get ( 'LESS' , '' ) + ' ' . join ( cmd_detail [ 1 : ] ) ) if ( not less_flags ) : env [ 'LESS' ] = '-R' color = True elif ( ( 'r' in less_flags ) or ( 'R' in less_flags ) ) : color = True if ( not color ) : text = strip_ansi ( text ) c = subprocess . Popen ( cmd , shell = True , stdin = subprocess . PIPE , env = env ) encoding = get_best_encoding ( c . stdin ) try : c . stdin . write ( text . encode ( encoding , 'replace' ) ) c . stdin . close ( ) except ( IOError , KeyboardInterrupt ) : pass while True : try : c . wait ( ) except KeyboardInterrupt : pass else : break
page through text by feeding it to another program .