Show More
@@ -26,7 +26,7 b' import sys' | |||
|
26 | 26 | from IPython.external import argparse |
|
27 | 27 | from IPython.utils.path import filefind, get_ipython_dir |
|
28 | 28 | from IPython.utils import py3compat, text, warn |
|
29 |
from IPython.utils.encoding import |
|
|
29 | from IPython.utils.encoding import DEFAULT_ENCODING | |
|
30 | 30 | |
|
31 | 31 | #----------------------------------------------------------------------------- |
|
32 | 32 | # Exceptions |
@@ -440,7 +440,7 b' class KeyValueConfigLoader(CommandLineConfigLoader):' | |||
|
440 | 440 | """decode argv if bytes, using stin.encoding, falling back on default enc""" |
|
441 | 441 | uargv = [] |
|
442 | 442 | if enc is None: |
|
443 | enc = getdefaultencoding() | |
|
443 | enc = DEFAULT_ENCODING | |
|
444 | 444 | for arg in argv: |
|
445 | 445 | if not isinstance(arg, unicode): |
|
446 | 446 | # only decode if not already decoded |
@@ -604,7 +604,7 b' class ArgParseConfigLoader(CommandLineConfigLoader):' | |||
|
604 | 604 | def _parse_args(self, args): |
|
605 | 605 | """self.parser->self.parsed_data""" |
|
606 | 606 | # decode sys.argv to support unicode command-line options |
|
607 | enc = getdefaultencoding() | |
|
607 | enc = DEFAULT_ENCODING | |
|
608 | 608 | uargs = [py3compat.cast_unicode(a, enc) for a in args] |
|
609 | 609 | self.parsed_data, self.extra_args = self.parser.parse_known_args(uargs) |
|
610 | 610 |
@@ -11,7 +11,7 b' import re' | |||
|
11 | 11 | import sys |
|
12 | 12 | |
|
13 | 13 | from IPython.utils import py3compat |
|
14 |
from IPython.utils.encoding import |
|
|
14 | from IPython.utils.encoding import DEFAULT_ENCODING | |
|
15 | 15 | |
|
16 | 16 | coding_declaration = re.compile(r"#\s*coding[:=]\s*([-\w.]+)") |
|
17 | 17 | |
@@ -36,7 +36,7 b' class Macro(object):' | |||
|
36 | 36 | lines.append(line) |
|
37 | 37 | code = "\n".join(lines) |
|
38 | 38 | if isinstance(code, bytes): |
|
39 |
code = code.decode(enc or |
|
|
39 | code = code.decode(enc or DEFAULT_ENCODING) | |
|
40 | 40 | self.value = code + '\n' |
|
41 | 41 | |
|
42 | 42 | def __str__(self): |
@@ -57,7 +57,7 b' from IPython.core.pylabtools import mpl_runner' | |||
|
57 | 57 | from IPython.testing.skipdoctest import skip_doctest |
|
58 | 58 | from IPython.utils import py3compat |
|
59 | 59 | from IPython.utils import openpy |
|
60 |
from IPython.utils.encoding import |
|
|
60 | from IPython.utils.encoding import DEFAULT_ENCODING | |
|
61 | 61 | from IPython.utils.io import file_read, nlprint |
|
62 | 62 | from IPython.utils.module_paths import find_mod |
|
63 | 63 | from IPython.utils.path import get_py_filename, unquote_filename |
@@ -950,7 +950,7 b' Currently the magic system has the following functions:\\n"""' | |||
|
950 | 950 | try: |
|
951 | 951 | vstr = str(var) |
|
952 | 952 | except UnicodeEncodeError: |
|
953 |
vstr = unicode(var).encode( |
|
|
953 | vstr = unicode(var).encode(DEFAULT_ENCODING, | |
|
954 | 954 | 'backslashreplace') |
|
955 | 955 | vstr = vstr.replace('\n','\\n') |
|
956 | 956 | if len(vstr) < 50: |
@@ -45,7 +45,7 b' from IPython.utils.process import find_cmd, getoutputerror' | |||
|
45 | 45 | from IPython.utils.text import list_strings |
|
46 | 46 | from IPython.utils.io import temp_pyfile, Tee |
|
47 | 47 | from IPython.utils import py3compat |
|
48 |
from IPython.utils.encoding import |
|
|
48 | from IPython.utils.encoding import DEFAULT_ENCODING | |
|
49 | 49 | |
|
50 | 50 | from . import decorators as dec |
|
51 | 51 | from . import skipdoctest |
@@ -323,7 +323,7 b' else:' | |||
|
323 | 323 | # so we need a class that can handle both. |
|
324 | 324 | class MyStringIO(StringIO): |
|
325 | 325 | def write(self, s): |
|
326 |
s = py3compat.cast_unicode(s, encoding= |
|
|
326 | s = py3compat.cast_unicode(s, encoding=DEFAULT_ENCODING) | |
|
327 | 327 | super(MyStringIO, self).write(s) |
|
328 | 328 | |
|
329 | 329 | notprinted_msg = """Did not find {0!r} in printed output (on {1}): |
@@ -26,7 +26,7 b' from .autoattr import auto_attr' | |||
|
26 | 26 | from ._process_common import getoutput, arg_split |
|
27 | 27 | from IPython.utils import text |
|
28 | 28 | from IPython.utils import py3compat |
|
29 |
from IPython.utils.encoding import |
|
|
29 | from IPython.utils.encoding import DEFAULT_ENCODING | |
|
30 | 30 | |
|
31 | 31 | #----------------------------------------------------------------------------- |
|
32 | 32 | # Function definitions |
@@ -129,7 +129,7 b' class ProcessHandler(object):' | |||
|
129 | 129 | int : child's exitstatus |
|
130 | 130 | """ |
|
131 | 131 | # Get likely encoding for the output. |
|
132 | enc = getdefaultencoding() | |
|
132 | enc = DEFAULT_ENCODING | |
|
133 | 133 | |
|
134 | 134 | # Patterns to match on the output, for pexpect. We read input and |
|
135 | 135 | # allow either a short timeout or EOF |
@@ -29,7 +29,7 b' from subprocess import STDOUT' | |||
|
29 | 29 | from ._process_common import read_no_interrupt, process_handler, arg_split as py_arg_split |
|
30 | 30 | from . import py3compat |
|
31 | 31 | from . import text |
|
32 | from .encoding import getdefaultencoding | |
|
32 | from .encoding import DEFAULT_ENCODING | |
|
33 | 33 | |
|
34 | 34 | #----------------------------------------------------------------------------- |
|
35 | 35 | # Function definitions |
@@ -95,7 +95,7 b' def _find_cmd(cmd):' | |||
|
95 | 95 | |
|
96 | 96 | def _system_body(p): |
|
97 | 97 | """Callback for _system.""" |
|
98 | enc = getdefaultencoding() | |
|
98 | enc = DEFAULT_ENCODING | |
|
99 | 99 | for line in read_no_interrupt(p.stdout).splitlines(): |
|
100 | 100 | line = line.decode(enc, 'replace') |
|
101 | 101 | print(line, file=sys.stdout) |
@@ -52,3 +52,5 b' def getdefaultencoding():' | |||
|
52 | 52 | except Exception: |
|
53 | 53 | pass |
|
54 | 54 | return enc or sys.getdefaultencoding() |
|
55 | ||
|
56 | DEFAULT_ENCODING = getdefaultencoding() |
@@ -17,7 +17,7 b' import types' | |||
|
17 | 17 | from datetime import datetime |
|
18 | 18 | |
|
19 | 19 | from IPython.utils import py3compat |
|
20 |
from IPython.utils.encoding import |
|
|
20 | from IPython.utils.encoding import DEFAULT_ENCODING | |
|
21 | 21 | from IPython.utils import text |
|
22 | 22 | next_attr_name = '__next__' if py3compat.PY3 else 'next' |
|
23 | 23 | |
@@ -136,7 +136,7 b' def json_clean(obj):' | |||
|
136 | 136 | return obj |
|
137 | 137 | |
|
138 | 138 | if isinstance(obj, bytes): |
|
139 |
return obj.decode( |
|
|
139 | return obj.decode(DEFAULT_ENCODING, 'replace') | |
|
140 | 140 | |
|
141 | 141 | if isinstance(obj, container_to_list) or ( |
|
142 | 142 | hasattr(obj, '__iter__') and hasattr(obj, next_attr_name)): |
@@ -6,9 +6,7 b' import sys' | |||
|
6 | 6 | import re |
|
7 | 7 | import types |
|
8 | 8 | |
|
9 | from .encoding import getdefaultencoding | |
|
10 | ||
|
11 | default_encoding = getdefaultencoding() | |
|
9 | from .encoding import DEFAULT_ENCODING | |
|
12 | 10 | |
|
13 | 11 | orig_open = open |
|
14 | 12 | |
@@ -16,11 +14,11 b' def no_code(x, encoding=None):' | |||
|
16 | 14 | return x |
|
17 | 15 | |
|
18 | 16 | def decode(s, encoding=None): |
|
19 |
encoding = encoding or |
|
|
17 | encoding = encoding or DEFAULT_ENCODING | |
|
20 | 18 | return s.decode(encoding, "replace") |
|
21 | 19 | |
|
22 | 20 | def encode(u, encoding=None): |
|
23 |
encoding = encoding or |
|
|
21 | encoding = encoding or DEFAULT_ENCODING | |
|
24 | 22 | return u.encode(encoding, "replace") |
|
25 | 23 | |
|
26 | 24 |
General Comments 0
You need to be logged in to leave comments.
Login now