summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichele Simionato <michele.simionato@gmail.com>2010-12-15 16:29:01 +0100
committerMichele Simionato <michele.simionato@gmail.com>2010-12-15 16:29:01 +0100
commit46a22a5342e17aa4dc9dc251b03aef5e2eb41b95 (patch)
treeb3d160b89b89b7c6329518c4f1ea08c2e8e5f21f
parentfd9a2705af0c57459243d6c2e985e5393ee3d6e1 (diff)
downloadmicheles-46a22a5342e17aa4dc9dc251b03aef5e2eb41b95.tar.gz
Moved the import of readline inside plac (otherwise just importing plac would change the line-buffering, not nice for applications talking to a script via unbuffered pipes)
-rw-r--r--plac/plac.py2
-rw-r--r--plac/plac_ext.py22
2 files changed, 14 insertions, 10 deletions
diff --git a/plac/plac.py b/plac/plac.py
index 211e43d..af01d87 100644
--- a/plac/plac.py
+++ b/plac/plac.py
@@ -27,7 +27,7 @@
See doc/plac.pdf, doc/plac_adv.pdf for the documentation.
"""
-__version__ = '0.7.4'
+__version__ = '0.7.5'
from plac_core import *
diff --git a/plac/plac_ext.py b/plac/plac_ext.py
index 29471bb..463339f 100644
--- a/plac/plac_ext.py
+++ b/plac/plac_ext.py
@@ -6,10 +6,6 @@ from gettext import gettext as _
import imp, inspect, os, sys, cmd, shlex, subprocess
import itertools, traceback, multiprocessing, signal, threading
import plac_core
-try:
- import readline
-except ImportError:
- readline = False
############################# generic utils ################################
@@ -97,22 +93,24 @@ class ReadlineInput(object):
self.histfile = histfile
if not case_sensitive:
self.completions = map(str.upper, completions)
+ import readline
+ self.rl = readline
readline.parse_and_bind("tab: complete")
readline.set_completer(self.complete)
def __enter__(self):
- self.old_completer = readline.get_completer()
+ self.old_completer = self.rl.get_completer()
try:
if self.histfile:
- readline.read_history_file(self.histfile)
+ self.rl.read_history_file(self.histfile)
except IOError: # the first time
pass
return self
def __exit__(self, etype, exc, tb):
- readline.set_completer(self.old_completer)
+ self.rl.set_completer(self.old_completer)
if self.histfile:
- readline.write_history_file(self.histfile)
+ self.rl.write_history_file(self.histfile)
def complete(self, kw, state):
# state is 0, 1, 2, ... and increases by hitting TAB
@@ -491,6 +489,7 @@ class TaskManager(object):
outstr = '\n'.join(map(str, task.outlist))
if fname:
open(fname, 'w').write(outstr)
+ yield 'saved output on %s' % fname; return
yield task
if len(task.outlist) > 20 and use_less:
less(outstr)
@@ -821,7 +820,12 @@ class Interpreter(object):
def interact(self, stdin=sys.stdin, prompt='i> ', verbose=False):
"Starts an interactive command loop reading commands from the consolle"
- if stdin is sys.stdin and readline: # use readline
+ try:
+ import readline
+ readline_present = True
+ except ImportError:
+ readline_present = False
+ if stdin is sys.stdin and readline_present: # use readline
histfile = os.path.expanduser('~/.%s.history' % self.name)
self.stdin = ReadlineInput(self.commands, histfile=histfile)
else: