From e6ed0161ef2a32a34b78588117eefbd184e51bab Mon Sep 17 00:00:00 2001 From: liris Date: Tue, 27 Oct 2015 16:17:35 +0900 Subject: [PATCH] python 2.6 support --- websocket/_handshake.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/websocket/_handshake.py b/websocket/_handshake.py index eee1544..4d0f028 100644 --- a/websocket/_handshake.py +++ b/websocket/_handshake.py @@ -30,6 +30,7 @@ import uuid import hashlib import hmac import os +import sys from ._logging import * from ._url import * @@ -148,7 +149,11 @@ def _validate(headers, key, subprotocols): value = (key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").encode('utf-8') hashed = base64encode(hashlib.sha1(value).digest()).strip().lower() - success = hmac.compare_digest(hashed, result) + if sys.version_info[0] == 2 and sys.version_info[1] < 7: + success = (hashed == result) + else: + success = hmac.compare_digest(hashed, result) + if success: return True, subproto else: