@@ -21,7 +21,7 @@ def error(self, msg):
21
21
raise OptionParserFailed ()
22
22
23
23
24
- def parse (args , extras = None ):
24
+ def parse (args , extras = None , ignore_stdin = False ):
25
25
"""Receive an argument list - if None, use sys.argv - parse all args and
26
26
take appropriate action. Also receive optional extra options: this should
27
27
be a tuple of (title, description, options)
@@ -87,8 +87,11 @@ def parse(args, extras=None):
87
87
'See AUTHORS for detail.' )
88
88
raise SystemExit
89
89
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
+
92
95
path = os .path .expanduser ('~/.bpythonrc' )
93
96
# migrating old configuration file
94
97
if os .path .isfile (path ):
@@ -110,11 +113,3 @@ def exec_code(interpreter, args):
110
113
sys .path .insert (0 , os .path .abspath (os .path .dirname (args [0 ])))
111
114
interpreter .runcode (code_obj )
112
115
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