From 57cecc70c26ec4e3e9bdfb5a3ef0343086575cdf Mon Sep 17 00:00:00 2001 From: Mikhail Korobov Date: Thu, 17 Jan 2013 02:51:06 +0600 Subject: [PATCH] P3K: fix cookie parsing under Python 3.x (+ duplicate import is removed) --- IPython/frontend/html/notebook/handlers.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py index 12a091a73..4421301e4 100644 --- a/IPython/frontend/html/notebook/handlers.py +++ b/IPython/frontend/html/notebook/handlers.py @@ -27,7 +27,6 @@ import stat import threading import time import uuid -import os from tornado.escape import url_escape from tornado import web @@ -41,6 +40,7 @@ from IPython.zmq.session import Session from IPython.lib.security import passwd_check from IPython.utils.jsonutil import date_default from IPython.utils.path import filefind +from IPython.utils.py3compat import PY3 try: from docutils.core import publish_string @@ -434,8 +434,9 @@ class AuthenticatedZMQStreamHandler(ZMQStreamHandler): def _inject_cookie_message(self, msg): """Inject the first message, which is the document cookie, for authentication.""" - if isinstance(msg, unicode): - # Cookie can't constructor doesn't accept unicode strings for some reason + if not PY3 and isinstance(msg, unicode): + # Cookie constructor doesn't accept unicode strings + # under Python 2.x for some reason msg = msg.encode('utf8', 'replace') try: self.request._cookies = Cookie.SimpleCookie(msg)