Skip to content

Convert str to bytes for comparing 'key' #1057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions jupyter_client/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,20 @@ def _reconcile_connection_info(self, info: KernelConnectionInfo) -> None:
def _equal_connections(conn1: KernelConnectionInfo, conn2: KernelConnectionInfo) -> bool:
"""Compares pertinent keys of connection info data. Returns True if equivalent, False otherwise."""

def _normalize_connection_info_keys(conn1, conn2):
"""
Ensure 'key' values in both conn1 and conn2 are bytes before comparison.
Modifies conn1 and conn2 in-place.
"""
key = "key"
val1 = conn1.get(key)
val2 = conn2.get(key)

if isinstance(val1, str) and isinstance(val2, bytes):
conn1[key] = val1.encode("utf-8")
elif isinstance(val1, bytes) and isinstance(val2, str):
conn2[key] = val2.encode("utf-8")

pertinent_keys = [
"key",
"ip",
Expand All @@ -627,6 +641,7 @@ def _equal_connections(conn1: KernelConnectionInfo, conn2: KernelConnectionInfo)
"signature_scheme",
]

_normalize_connection_info_keys(conn1, conn2)
return all(conn1.get(key) == conn2.get(key) for key in pertinent_keys)

# --------------------------------------------------------------------------
Expand Down
Loading