##// END OF EJS Templates
Backport PR #2738: Unicode content crashes the pager (console)...
Backport PR #2738: Unicode content crashes the pager (console) We've run into an interesting bug in the astropy project. https://github.com/astropy/astropy/issues/600 When displaying a docstring that contains Unicode and is also long enough that it gets sent to the pager it fails since the docstring can't be sent to the pager as ascii. This crashes in the middle of sending content to the pager, so the shell ends up in an inconsistent state and stops echoing the keyboard etc. The fix (attached) is merely to encode the content sent to the pager in the same encoding as the terminal (`sys.stdout.encoding`). Strictly speaking, this isn't always the right thing to do, since the pager may be configured to expect a different encoding than the terminal, but that is sort of an irrational way to configure a machine... ;) For example, `less`, in the absence of any special environment variables to tell it otherwise, uses the standard `LC*` environment variables to determine what to do, which should be the same mechanism the terminal also uses by default. If anyone can suggest a better fix, I'm all for it. Perhaps it should be configurable, defaulting to `sys.stdout.encoding`?

File last commit:

r2267:928c921b
r9853:7f9a133e
Show More
ipy_exportdb.py
77 lines | 2.0 KiB | text/x-python | PythonLexer
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 from IPython.core import ipapi
Brian Granger
macro.py => core/macro.py and upated imports.
r2033 from IPython.core import macro
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 ip = ipapi.get()
vivainio
crlf cleanup
r680
import os,pprint
def export(filename = None):
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 lines = ['import IPython.core.ipapi', 'ip = IPython.core.ipapi.get()','']
vivainio
crlf cleanup
r680
vars = ip.db.keys('autorestore/*')
vars.sort()
varstomove = []
get = ip.db.get
macros = []
variables = []
for var in vars:
k = os.path.basename(var)
v = get(var)
if k.startswith('_'):
continue
Brian Granger
macro.py => core/macro.py and upated imports.
r2033 if isinstance(v, macro.Macro):
vivainio
crlf cleanup
r680 macros.append((k,v))
if type(v) in [int, str, float]:
variables.append((k,v))
if macros:
lines.extend(['# === Macros ===' ,''])
for k,v in macros:
lines.append("ip.defmacro('%s'," % k)
for line in v.value.splitlines():
lines.append(' ' + repr(line+'\n'))
lines.extend([')', ''])
if variables:
lines.extend(['','# === Variables ===',''])
for k,v in variables:
varstomove.append(k)
lines.append('%s = %s' % (k,repr(v)))
Brian Granger
Continuing a massive refactor of everything.
r2205 lines.append('ip.push("%s")' % (' '.join(varstomove)))
vivainio
crlf cleanup
r680
bkms = ip.db.get('bookmarks',{})
if bkms:
lines.extend(['','# === Bookmarks ===',''])
lines.append("ip.db['bookmarks'] = %s " % pprint.pformat(bkms, indent = 2) )
aliases = ip.db.get('stored_aliases', {} )
if aliases:
lines.extend(['','# === Alias definitions ===',''])
for k,v in aliases.items():
vivainio
ipy_exportdb now tolerates new style aliases'
r809 try:
Brian Granger
Continuing a massive refactor of everything.
r2205 lines.append("ip.define_alias('%s', %s)" % (k, repr(v[1])))
vivainio
ipy_exportdb now tolerates new style aliases'
r809 except (AttributeError, TypeError):
pass
vivainio
crlf cleanup
r680
env = ip.db.get('stored_env')
if env:
lines.extend(['','# === Stored env vars ===',''])
lines.append("ip.db['stored_env'] = %s " % pprint.pformat(env, indent = 2) )
out = '\n'.join(lines)
if filename:
open(filename,'w').write(out)
else:
print out