tiny refactoring

This commit is contained in:
Hiroki Ohtani
2015-03-16 10:53:39 +09:00
parent d06465a287
commit ee60d90e6f
2 changed files with 10 additions and 11 deletions

View File

@@ -297,7 +297,7 @@ class WebSocket(object):
self.sock.setsockopt(*opts) self.sock.setsockopt(*opts)
for opts in self.sockopt: for opts in self.sockopt:
self.sock.setsockopt(*opts) self.sock.setsockopt(*opts)
address = addrinfo[4] address = addrinfo[4]
try: try:
self.sock.connect(address) self.sock.connect(address)
@@ -424,7 +424,7 @@ class WebSocket(object):
r = r.lower() r = r.lower()
if v != r: if v != r:
return False return False
if subprotocols: if subprotocols:
subproto = headers.get("sec-websocket-protocol", None) subproto = headers.get("sec-websocket-protocol", None)
if not subproto or subproto not in subprotocols: if not subproto or subproto not in subprotocols:
@@ -456,10 +456,10 @@ class WebSocket(object):
line = line.decode('utf-8').strip() line = line.decode('utf-8').strip()
if not line: if not line:
break break
if traceEnabled: if traceEnabled:
logger.debug(line) logger.debug(line)
if not status: if not status:
status_info = line.split(" ", 2) status_info = line.split(" ", 2)
status = int(status_info[1]) status = int(status_info[1])
@@ -599,7 +599,7 @@ class WebSocket(object):
if frame.fin: if frame.fin:
self._recving_frames = None self._recving_frames = None
if frame.fin or self.fire_cont_frame: if frame.fin or self.fire_cont_frame:
data = self._cont_data data = self._cont_data
self._cont_data = None self._cont_data = None

View File

@@ -32,7 +32,6 @@ from websocket._utils import validate_utf8
# Skip test to access the internet. # Skip test to access the internet.
TEST_WITH_INTERNET = False TEST_WITH_INTERNET = False
# TEST_WITH_INTERNET = True
# Skip Secure WebSocket test. # Skip Secure WebSocket test.
TEST_SECURE_WS = False TEST_SECURE_WS = False
@@ -480,7 +479,7 @@ class WebSocketAppTest(unittest.TestCase):
close the connection. close the connection.
""" """
WebSocketAppTest.keep_running_open = self.keep_running WebSocketAppTest.keep_running_open = self.keep_running
self.close() self.close()
def on_close(self, *args, **kwargs): def on_close(self, *args, **kwargs):
@@ -534,7 +533,7 @@ class SockOptTest(unittest.TestCase):
class UtilsTest(unittest.TestCase): class UtilsTest(unittest.TestCase):
def testUtf8Validator(self): def testUtf8Validator(self):
state = validate_utf8(six.b('\xf0\x90\x80\x80')) state = validate_utf8(six.b('\xf0\x90\x80\x80'))
self.assertEqual(state, True) self.assertEqual(state, True)
state = validate_utf8(six.b('\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5\xed\xa0\x80edited')) state = validate_utf8(six.b('\xce\xba\xe1\xbd\xb9\xcf\x83\xce\xbc\xce\xb5\xed\xa0\x80edited'))
self.assertEqual(state, False) self.assertEqual(state, False)
state = validate_utf8(six.b('')) state = validate_utf8(six.b(''))
@@ -569,9 +568,9 @@ class ProxyInfoTest(unittest.TestCase):
self.assertEqual(get_proxy_info("echo.websocket.org", False, http_proxy_host="localhost", http_proxy_auth=("a", "b")), self.assertEqual(get_proxy_info("echo.websocket.org", False, http_proxy_host="localhost", http_proxy_auth=("a", "b")),
("localhost", 0, ("a", "b"))) ("localhost", 0, ("a", "b")))
self.assertEqual(get_proxy_info("echo.websocket.org", False, http_proxy_host="localhost", http_proxy_port=3128, http_proxy_auth=("a", "b")), self.assertEqual(get_proxy_info("echo.websocket.org", False, http_proxy_host="localhost", http_proxy_port=3128, http_proxy_auth=("a", "b")),
("localhost", 3128, ("a", "b"))) ("localhost", 3128, ("a", "b")))
self.assertEqual(get_proxy_info("echo.websocket.org", True, http_proxy_host="localhost", http_proxy_auth=("a", "b")), self.assertEqual(get_proxy_info("echo.websocket.org", True, http_proxy_host="localhost", http_proxy_auth=("a", "b")),
("localhost", 0, ("a", "b"))) ("localhost", 0, ("a", "b")))
self.assertEqual(get_proxy_info("echo.websocket.org", True, http_proxy_host="localhost", http_proxy_port=3128, http_proxy_auth=("a", "b")), self.assertEqual(get_proxy_info("echo.websocket.org", True, http_proxy_host="localhost", http_proxy_port=3128, http_proxy_auth=("a", "b")),
("localhost", 3128, ("a", "b"))) ("localhost", 3128, ("a", "b")))
@@ -634,6 +633,6 @@ class ProxyInfoTest(unittest.TestCase):
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()