fix for ssl unavialable environmnet

This commit is contained in:
Hiroki Ohtani
2013-08-21 10:51:55 +09:00
parent 2895b0074f
commit 204c0da290
2 changed files with 13 additions and 3 deletions

View File

@@ -3,7 +3,12 @@
import base64
import socket
import ssl
try:
from ssl import SSLError
except ImportError:
# dummy class of SSLError for ssl none-support environment.
class SSLError(Exception):
pass
import unittest
import uuid
@@ -191,7 +196,7 @@ class WebSocketTest(unittest.TestCase):
s.add_packet("foo")
s.add_packet(socket.timeout())
s.add_packet("bar")
s.add_packet(ssl.SSLError("The read operation timed out"))
s.add_packet(SSLError("The read operation timed out"))
s.add_packet("baz")
with self.assertRaises(ws.WebSocketTimeoutException):
data = sock._recv_strict(9)

View File

@@ -24,8 +24,13 @@ import socket
try:
import ssl
from ssl import SSLError
HAVE_SSL = True
except ImportError:
# dummy class of SSLError for ssl none-support environment.
class SSLError(Exception):
pass
HAVE_SSL = False
from urlparse import urlparse
@@ -705,7 +710,7 @@ class WebSocket(object):
bytes = self.sock.recv(bufsize)
except socket.timeout as e:
raise WebSocketTimeoutException(e.message)
except ssl.SSLError as e:
except SSLError as e:
if e.message == "The read operation timed out":
raise WebSocketTimeoutException(e.message)
else: