Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ipykernel/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from IPython.core.profiledir import ProfileDir
from IPython.paths import get_ipython_dir
from ipython_genutils.path import filefind
from ipython_genutils.py3compat import str_to_bytes

import jupyter_client
from jupyter_client import write_connection_file
Expand Down Expand Up @@ -131,7 +130,7 @@ def get_connection_info(connection_file=None, unpack=False, profile=None):
if unpack:
info = json.loads(info)
# ensure key is bytes:
info['key'] = str_to_bytes(info.get('key', ''))
info["key"] = info.get("key", "").encode()
return info


Expand Down
11 changes: 7 additions & 4 deletions ipykernel/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

from jupyter_client.session import extract_header

from ipython_genutils import py3compat

#-----------------------------------------------------------------------------
# Globals
Expand Down Expand Up @@ -288,8 +287,12 @@ class OutStream(TextIOBase):

def __init__(self, session, pub_thread, name, pipe=None, echo=None):
if pipe is not None:
warnings.warn("pipe argument to OutStream is deprecated and ignored",
DeprecationWarning)
warnings.warn(
"pipe argument to OutStream is deprecated and ignored",
" since ipykernel 4.2.3.",
DeprecationWarning,
stacklevel=2,
)
# This is necessary for compatibility with Python built-in streams
self.session = session
if not isinstance(pub_thread, IOPubThread):
Expand All @@ -300,7 +303,7 @@ def __init__(self, session, pub_thread, name, pipe=None, echo=None):
pub_thread.start()
self.pub_thread = pub_thread
self.name = name
self.topic = b'stream.' + py3compat.cast_bytes(name)
self.topic = b"stream." + name.encode()
self.parent_header = {}
self._master_pid = os.getpid()
self._flush_pending = False
Expand Down
7 changes: 3 additions & 4 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

from traitlets.config.configurable import SingletonConfigurable
from IPython.core.error import StdinNotImplementedError
from ipython_genutils import py3compat
from ipykernel.jsonutil import json_clean
from traitlets import (
Any, Instance, Float, Dict, List, Set, Integer, Unicode, Bool,
Expand Down Expand Up @@ -824,7 +823,7 @@ def _topic(self, topic):
"""prefixed topic for IOPub messages"""
base = "kernel.%s" % self.ident

return py3compat.cast_bytes("%s.%s" % (base, topic))
return ("%s.%s" % (base, topic)).encode()

_aborting = Bool(False)

Expand Down Expand Up @@ -939,8 +938,8 @@ def _input_request(self, prompt, ident, parent, password=False):
self.log.warning("Invalid Message:", exc_info=True)

try:
value = py3compat.unicode_to_str(reply['content']['value'])
except:
value = reply["content"]["value"]
except Exception:
self.log.error("Bad input_reply: %s", parent)
value = ''
if value == '\x04':
Expand Down
9 changes: 1 addition & 8 deletions ipykernel/tests/test_jsonutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from .. import jsonutil
from ..jsonutil import json_clean, encode_images
from ipython_genutils.py3compat import unicode_to_str

class MyInt(object):
def __int__(self):
Expand Down Expand Up @@ -80,14 +79,8 @@ def test_encode_images():
encoded2 = json_clean(encode_images(encoded))
assert encoded == encoded2

# test that we don't double-encode base64 str
b64_str = {}
for key, encoded in encoded.items():
b64_str[key] = unicode_to_str(encoded)
encoded3 = json_clean(encode_images(b64_str))
assert encoded3 == b64_str
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unicode to str is no-op, and then this code becomes strictly identical to the one with encoded2.

for key, value in fmt.items():
decoded = a2b_base64(encoded3[key])
decoded = a2b_base64(encoded[key])
assert decoded == value

def test_lambda():
Expand Down