@@ -21,7 +21,7 @@ def error(self, msg):
2121 raise OptionParserFailed ()
2222
2323
24- def parse (args , extras = None ):
24+ def parse (args , extras = None , ignore_stdin = False ):
2525 """Receive an argument list - if None, use sys.argv - parse all args and
2626 take appropriate action. Also receive optional extra options: this should
2727 be a tuple of (title, description, options)
@@ -87,8 +87,11 @@ def parse(args, extras=None):
8787 'See AUTHORS for detail.' )
8888 raise SystemExit
8989
90- if not (sys .stdin .isatty () and sys .stdout .isatty ()):
91- run_stdin (sys .stdin )
90+ if not ignore_stdin and not (sys .stdin .isatty () and sys .stdout .isatty ()):
91+ interpreter = code .InteractiveInterpreter ()
92+ interpreter .runsource (sys .stdin .read ())
93+ raise SystemExit
94+
9295 path = os .path .expanduser ('~/.bpythonrc' )
9396 # migrating old configuration file
9497 if os .path .isfile (path ):
@@ -110,11 +113,3 @@ def exec_code(interpreter, args):
110113 sys .path .insert (0 , os .path .abspath (os .path .dirname (args [0 ])))
111114 interpreter .runcode (code_obj )
112115 sys .argv = old_argv
113-
114- def run_stdin (stdin ):
115- """
116- Run code from a file-like object and exit.
117- """
118- interpreter = code .InteractiveInterpreter ()
119- interpreter .runsource (stdin .read ())
120- raise SystemExit
0 commit comments