33
44This file is deprecated and will be removed in a future version.
55"""
6- import functools
7- import os
8- import sys
9- import re
10- import shutil
11- import types
126import platform
7+ import builtins as builtin_mod
138
149from .encoding import DEFAULT_ENCODING
1510
@@ -18,6 +13,7 @@ def decode(s, encoding=None):
1813 encoding = encoding or DEFAULT_ENCODING
1914 return s .decode (encoding , "replace" )
2015
16+
2117def encode (u , encoding = None ):
2218 encoding = encoding or DEFAULT_ENCODING
2319 return u .encode (encoding , "replace" )
@@ -28,16 +24,6 @@ def cast_unicode(s, encoding=None):
2824 return decode (s , encoding )
2925 return s
3026
31- def cast_bytes (s , encoding = None ):
32- if not isinstance (s , bytes ):
33- return encode (s , encoding )
34- return s
35-
36- def buffer_to_bytes (buf ):
37- """Cast a buffer object to bytes"""
38- if not isinstance (buf , bytes ):
39- buf = bytes (buf )
40- return buf
4127
4228def safe_unicode (e ):
4329 """unicode(e) with various fallbacks. Used for exceptions, which may not be
@@ -53,30 +39,29 @@ def safe_unicode(e):
5339 except UnicodeError :
5440 pass
5541
56- return u'Unrecoverably corrupt evalue'
42+ return "Unrecoverably corrupt evalue"
43+
5744
5845# keep reference to builtin_mod because the kernel overrides that value
5946# to forward requests to a frontend.
60- def input (prompt = '' ):
47+ def input (prompt = "" ):
6148 return builtin_mod .input (prompt )
6249
63- builtin_mod_name = "builtins"
64- import builtins as builtin_mod
65-
66- MethodType = types .MethodType
6750
6851def execfile (fname , glob , loc = None , compiler = None ):
6952 loc = loc if (loc is not None ) else glob
70- with open (fname , 'rb' ) as f :
53+ with open (fname , "rb" ) as f :
7154 compiler = compiler or compile
72- exec (compiler (f .read (), fname , 'exec' ), glob , loc )
55+ exec (compiler (f .read (), fname , "exec" ), glob , loc )
56+
7357
7458PYPY = platform .python_implementation () == "PyPy"
7559
7660# Cython still rely on that as a Dec 28 2019
7761# See https://github.com/cython/cython/pull/3291 and
7862# https://github.com/ipython/ipython/issues/12068
7963def no_code (x , encoding = None ):
80- return x
81- unicode_to_str = cast_bytes_py2 = no_code
64+ return x
8265
66+
67+ unicode_to_str = cast_bytes_py2 = no_code
0 commit comments