From c9611069bd232ea482da173bd46b6b18fa393f3c 2014-07-11 19:30:50 From: Paul Ivanov Date: 2014-07-11 19:30:50 Subject: [PATCH] support Python older than 2.7.7 --- diff --git a/IPython/kernel/zmq/session.py b/IPython/kernel/zmq/session.py index 091e25c..a3d16e6 100644 --- a/IPython/kernel/zmq/session.py +++ b/IPython/kernel/zmq/session.py @@ -27,6 +27,13 @@ except: cPickle = None import pickle +try: + from hmac import compare_digest +except ImportError: + # Python < 2.7.7 + def compare_digest(a,b): + return a == b + import zmq from zmq.utils import jsonapi from zmq.eventloop.ioloop import IOLoop @@ -818,7 +825,7 @@ class Session(Configurable): raise ValueError("Duplicate Signature: %r" % signature) self._add_digest(signature) check = self.sign(msg_list[1:5]) - if not hmac.compare_digest(signature, check): + if not compare_digest(signature, check): raise ValueError("Invalid Signature: %r" % signature) if not len(msg_list) >= minlen: raise TypeError("malformed message, must have at least %i elements"%minlen)