Skip to content

Commit 13d0341

Browse files
committed
Rewind ugly monkeypatching fix and pick the simpler solution of an added argument to parse which ignores stdins
1 parent e6056e6 commit 13d0341

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

bpython/args.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

bpython/gtk_.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@
5050
_COLORS = dict(b='blue', c='cyan', g='green', m='magenta', r='red',
5151
w='white', y='yellow', k='black', d='black')
5252

53-
def run_stdin(stdin):
54-
"""
55-
Overwrite stdin reader from args as GTK does not supply a stdin/stdout
56-
as a tty.
57-
"""
58-
pass
59-
60-
bpython.args.run_stdin = run_stdin
61-
6253
class ArgspecFormatter(object):
6354
"""
6455
Format an argspec using Pango markup language.
@@ -755,7 +746,8 @@ def main(args=None):
755746
"Options specific to bpython's Gtk+ front end",
756747
[optparse.Option('--socket-id', dest='socket_id',
757748
type='int', help='Embed bpython')])
758-
config, options, exec_args = bpython.args.parse(args, gtk_options)
749+
config, options, exec_args = bpython.args.parse(args, gtk_options,
750+
True)
759751

760752
interpreter = repl.Interpreter(None, getpreferredencoding())
761753
repl_widget = ReplWidget(interpreter, config)

0 commit comments

Comments
 (0)