fixed some error

This commit is contained in:
liris
2015-03-26 15:50:47 +09:00
parent f434416a1b
commit bb5f395eb2
3 changed files with 7 additions and 6 deletions

View File

@@ -30,7 +30,6 @@ if six.PY3:
else:
from base64 import encodestring as base64encode
import os
import struct
import threading
@@ -254,8 +253,9 @@ class WebSocket(object):
self.handshake_response = handshake(self.sock, *addrs, **options)
self.connected = True
except:
self.sock.close()
self.sock = None
if self.sock:
self.sock.close()
self.sock = None
raise
def send(self, payload, opcode=ABNF.OPCODE_TEXT):

View File

@@ -23,6 +23,7 @@ Copyright (C) 2010 Hiroki Ohtani(liris)
import six
import socket
import errno
import os
if six.PY3:
from base64 import encodebytes as base64encode
@@ -64,7 +65,7 @@ def connect(url, options, proxy):
if is_secure:
if HAVE_SSL:
sock = _ssl_socket(sock, options.sslopt)
sock = _ssl_socket(sock, options.sslopt, hostname)
else:
raise WebSocketException("SSL not available.")
@@ -116,7 +117,7 @@ def _open_socket(addrinfo_list, sockopt, timeout):
return sock
def _ssl_socket(sock, sslopt):
def _ssl_socket(sock, sslopt, hostname):
sslopt = dict(cert_reqs=ssl.CERT_REQUIRED)
certPath = os.path.join(
os.path.dirname(__file__), "cacert.pem")

View File

@@ -20,7 +20,7 @@ Copyright (C) 2010 Hiroki Ohtani(liris)
"""
__all__ = ["HAVE_SSL", "SSLError"]
__all__ = ["HAVE_SSL", "ssl", "SSLError"]
try:
import ssl