##// END OF EJS Templates
First step in reintegrating Jedi...
First step in reintegrating Jedi If Jedi is installed expose a private API use it with prompt toolkit. Jedi does not _yet_ provide all the completion IPython has, so this is still a bit awkward. In order to debug this (and see what is Jedi provided we for now inject a fake Jedi/IPython delimiter in the menu. Jedi completion and this behavior are enabled by default, but could likely be opt-in. Add also a number of debug flags to be able to track why jedi is not working, and/or what completions are found by IPython and not Jedi. That should give us a bit of heads up and feedback to know whether we can remove part of the IPython completer, and more especially if we can drop `python_matches`. Once `python_matches` is dropped and some other of the current matchers are either dropped or converted to the new API, that should simplify the internal quite a bit. That would just be too much for an already BIG pull-request.

File last commit:

r14695:bda2ad7d
r23284:3ff1be2e
Show More
encoding.py
71 lines | 2.8 KiB | text/x-python | PythonLexer
Brandon Parsons
Feedback from pull request #1245
r6655 # 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
dhirschfeld
Fix for incorrect default encoding on Windows.
r12444 import warnings
Brandon Parsons
Feedback from pull request #1245
r6655
# 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.
Thomas Kluyver
Miscellaneous docs fixes
r9244 There are cases where ``sys.std*`` might not actually be a stream, so
Brandon Parsons
Feedback from pull request #1245
r6655 check for the encoding attribute prior to returning it, and return
Thomas Kluyver
Miscellaneous docs fixes
r9244 a default if it doesn't exist or evaluates as False. ``default``
Brandon Parsons
Feedback from pull request #1245
r6655 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.
MinRK
add prefer_stream arg to utils.encoding.getdefaultencoding...
r14695 def getdefaultencoding(prefer_stream=True):
Brandon Parsons
Feedback from pull request #1245
r6655 """Return IPython's guess for the default encoding for bytes as text.
MinRK
add prefer_stream arg to utils.encoding.getdefaultencoding...
r14695
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(),
Brandon Parsons
Feedback from pull request #1245
r6655 which should be a sensible platform default (that respects LANG environment),
and finally to sys.getdefaultencoding() which is the most conservative option,
MinRK
add prefer_stream arg to utils.encoding.getdefaultencoding...
r14695 and usually ASCII on Python 2 or UTF8 on Python 3.
Brandon Parsons
Feedback from pull request #1245
r6655 """
MinRK
add prefer_stream arg to utils.encoding.getdefaultencoding...
r14695 enc = None
if prefer_stream:
enc = get_stream_enc(sys.stdin)
Brandon Parsons
Feedback from pull request #1245
r6655 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
dhirschfeld
Fix for incorrect default encoding on Windows.
r12444 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
Brandon Parsons
saner default encoding mechanism
r6716
DEFAULT_ENCODING = getdefaultencoding()