##// END OF EJS Templates
Release 5.0.0b4...
Release 5.0.0b4 What's new since b3: Small delay since last beta release, sorry about that, a few reasons though: - We / I slowed down a bit on the beta release pace, there was a few bugs/issues/User interface annoyance that needed a new version of prompt_toolkit to be released, there was no reasons to make extra-beta without this new version released. - We backed-down on some changes on which we had a few disagrements (more below). - I got sick, and had to catch up with backlog. Anyway, Jonathan release prompt_toolkit 1.0.1 and 1.0.2, so even if you don't try this new beta, upgrading prompt_toolkit will fix some of your issues. == Move back `TerminalInteractiveShell` to it's old place. This is a bigger breaking change since 5.0b3, the `TerminalInteractiveshell` moved back from `IPython.terminal.ptshell` to `IPython.terminal.interactiveshell`, if you've updated your project recently to adapt to this change we're sorry, but despite the fact that the version pre 5.0 and post 5.0 are relatively different the cost of conditional import for project depending on us appeared to be too high. So it's now easier to migrate from 4.0 to 5.0 as the class have the same name, and same location == Option name and default changed. `TerminalInteractiveShell.display_completions_in_column` is now gone. It was not present on 4.x so no API breakage there, and is now replaced by `TerminalInteractiveShell.display_completions` and is a enum that gained a 3rd mode for the completer: `readlinelike` for those of you that regret readline. This give us more flexibility for further options. Would appreciate testing of this new layout from vi user. The two other mode now being `column` and `multicolumn`. By popular request, `multicolumn` is not the default value for the previous option. == bug fixed: - quit/exit broken in ipdb - Copy/Past broken on windowm - Unicode broken on windows - function signature garbled when using `object?` - issue with paging text with `?` - completer could get stuck. See the complete git log for more informations.

File last commit:

r14695:bda2ad7d
r22560:1b487f7a
Show More
encoding.py
71 lines | 2.8 KiB | text/x-python | PythonLexer
# coding: utf-8
"""
Utilities for dealing with text encodings
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2012 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import sys
import locale
import warnings
# to deal with the possibility of sys.std* not being a stream at all
def get_stream_enc(stream, default=None):
"""Return the given stream's encoding or a default.
There are cases where ``sys.std*`` might not actually be a stream, so
check for the encoding attribute prior to returning it, and return
a default if it doesn't exist or evaluates as False. ``default``
is None if not provided.
"""
if not hasattr(stream, 'encoding') or not stream.encoding:
return default
else:
return stream.encoding
# Less conservative replacement for sys.getdefaultencoding, that will try
# to match the environment.
# Defined here as central function, so if we find better choices, we
# won't need to make changes all over IPython.
def getdefaultencoding(prefer_stream=True):
"""Return IPython's guess for the default encoding for bytes as text.
If prefer_stream is True (default), asks for stdin.encoding first,
to match the calling Terminal, but that is often None for subprocesses.
Then fall back on locale.getpreferredencoding(),
which should be a sensible platform default (that respects LANG environment),
and finally to sys.getdefaultencoding() which is the most conservative option,
and usually ASCII on Python 2 or UTF8 on Python 3.
"""
enc = None
if prefer_stream:
enc = get_stream_enc(sys.stdin)
if not enc or enc=='ascii':
try:
# There are reports of getpreferredencoding raising errors
# in some cases, which may well be fixed, but let's be conservative here.
enc = locale.getpreferredencoding()
except Exception:
pass
enc = enc or sys.getdefaultencoding()
# On windows `cp0` can be returned to indicate that there is no code page.
# Since cp0 is an invalid encoding return instead cp1252 which is the
# Western European default.
if enc == 'cp0':
warnings.warn(
"Invalid code page cp0 detected - using cp1252 instead."
"If cp1252 is incorrect please ensure a valid code page "
"is defined for the process.", RuntimeWarning)
return 'cp1252'
return enc
DEFAULT_ENCODING = getdefaultencoding()