##// 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:

r4872:34c10438
r9853:7f9a133e
Show More
ipy_winpdb.py
84 lines | 2.3 KiB | text/x-python | PythonLexer
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 """ Debug a script (like %run -d) in IPython process, Using WinPdb
Usage:
%wdb test.py
Bernardo B. Marques
remove all trailling spaces
r4872 run test.py, with a winpdb breakpoint at start of the file
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 %wdb pass
Change the password (e.g. if you have forgotten the old one)
Fernando Perez
Add a note about the conflict winpdb causes with PyTables.
r1867
Notes
-----
**WARNING**: As of March 2009 (IPython 0.10), WinPdb has a known bug, which
causes PyTables to become impossible to import if winpdb is loaded. Therefore,
if you need PyTables, do *not* use this extension.
For more details: https://bugs.launchpad.net/ipython/+bug/249036
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 """
import os
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 from IPython.core import ipapi
Brian Granger
Continuing a massive refactor of everything.
r2205 from IPython.core.error import UsageError
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 import rpdb2
Brian Granger
ipapi.py => core/ipapi.py and imports updated.
r2027 ip = ipapi.get()
Ville M. Vainio
fix crlf on ipy_winpdb
r1137
rpdb_started = False
def wdb_f(self, arg):
""" Debug a script (like %run -d) in IPython process, Using WinPdb
Bernardo B. Marques
remove all trailling spaces
r4872
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 Usage:
Bernardo B. Marques
remove all trailling spaces
r4872
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 %wdb test.py
Bernardo B. Marques
remove all trailling spaces
r4872 run test.py, with a winpdb breakpoint at start of the file
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 %wdb pass
Change the password (e.g. if you have forgotten the old one)
Bernardo B. Marques
remove all trailling spaces
r4872
Note that after the script has been run, you need to do "Go" (f5)
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 in WinPdb to resume normal IPython operation.
"""
global rpdb_started
if not arg.strip():
print __doc__
return
Bernardo B. Marques
remove all trailling spaces
r4872
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 if arg.strip() == 'pass':
passwd = raw_input('Enter new winpdb session password: ')
ip.db['winpdb_pass'] = passwd
print "Winpdb password changed"
if rpdb_started:
print "You need to restart IPython to use the new password"
Bernardo B. Marques
remove all trailling spaces
r4872 return
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 path = os.path.abspath(arg)
if not os.path.isfile(path):
Brian Granger
Continuing a massive refactor of everything.
r2205 raise UsageError("%%wdb: file %s does not exist" % path)
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 if not rpdb_started:
passwd = ip.db.get('winpdb_pass', None)
if passwd is None:
import textwrap
print textwrap.dedent("""\
Winpdb sessions need a password that you use for attaching the external
Bernardo B. Marques
remove all trailling spaces
r4872 winpdb session. IPython will remember this. You can change the password later
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 by '%wpdb pass'
""")
passwd = raw_input('Enter new winpdb session password: ')
ip.db['winpdb_pass'] = passwd
Bernardo B. Marques
remove all trailling spaces
r4872
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 print "Starting rpdb2 in IPython process"
rpdb2.start_embedded_debugger(passwd, timeout = 0)
rpdb_started = True
Bernardo B. Marques
remove all trailling spaces
r4872
Ville M. Vainio
fix crlf on ipy_winpdb
r1137 rpdb2.set_temp_breakpoint(path)
print 'It is time to attach with WinPdb (launch WinPdb if needed, File -> Attach)'
ip.magic('%run ' + arg)
Bernardo B. Marques
remove all trailling spaces
r4872
Ville M. Vainio
fix crlf on ipy_winpdb
r1137
Brian Granger
Continuing a massive refactor of everything.
r2205 ip.define_magic('wdb', wdb_f)