diff options
author | bubbleboy14 <mario.balibrera@gmail.com> | 2023-01-20 13:14:23 -0800 |
---|---|---|
committer | bubbleboy14 <mario.balibrera@gmail.com> | 2023-01-20 13:14:23 -0800 |
commit | be4110c08c5d10b52410c36c72d1deb9e4cbf32c (patch) | |
tree | d6dddc00338bc416ba72e7de629dd170270ddb8f /websocket | |
parent | 7d83cc3e559526ca2d6774768baffc19ff14f8da (diff) | |
parent | 601a9022d6044bf6d414fdb1122916b65dc58ca7 (diff) | |
download | websocket-client-t858.tar.gz |
Merge branch 'master' into t858t858
Diffstat (limited to 'websocket')
-rw-r--r-- | websocket/__init__.py | 2 | ||||
-rw-r--r-- | websocket/_app.py | 15 | ||||
-rw-r--r-- | websocket/_core.py | 11 | ||||
-rw-r--r-- | websocket/_handshake.py | 1 | ||||
-rw-r--r-- | websocket/tests/test_app.py | 2 | ||||
-rw-r--r-- | websocket/tests/test_websocket.py | 2 |
6 files changed, 20 insertions, 13 deletions
diff --git a/websocket/__init__.py b/websocket/__init__.py index 720a842..588a8f2 100644 --- a/websocket/__init__.py +++ b/websocket/__init__.py @@ -23,4 +23,4 @@ from ._exceptions import * from ._logging import * from ._socket import * -__version__ = "1.4.1" +__version__ = "1.4.2" diff --git a/websocket/_app.py b/websocket/_app.py index d57781e..c77a3f0 100644 --- a/websocket/_app.py +++ b/websocket/_app.py @@ -5,6 +5,7 @@ import threading import time import traceback from ._abnf import ABNF +from ._url import parse_url from ._core import WebSocket, getdefaulttimeout from ._exceptions import * from . import _logging @@ -287,12 +288,12 @@ class WebSocketApp: HTTP proxy host name. http_proxy_port: int or str HTTP proxy port. If not set, set to 80. + http_no_proxy: list + Whitelisted host names that don't use the proxy. http_proxy_timeout: int or float HTTP proxy timeout, default is 60 sec as per python-socks. http_proxy_auth: tuple HTTP proxy auth information. tuple of username and password. Default is None. - http_no_proxy: list - Whitelisted host names that don't use the proxy. skip_utf8_validation: bool skip utf8 validation. host: str @@ -303,6 +304,10 @@ class WebSocketApp: customize reading data from socket. suppress_origin: bool suppress outputting origin header. + proxy_type: str + type of proxy from: http, socks4, socks4a, socks5, socks5h + reconnect: int + delay interval when reconnecting Returns ------- @@ -374,7 +379,7 @@ class WebSocketApp: self._callback(self.on_open) - _logging.warning("websocket connected") + _logging.info("websocket connected") dispatcher.read(self.sock.sock, read, check) except (WebSocketConnectionClosedException, ConnectionRefusedError, KeyboardInterrupt, SystemExit, Exception) as e: _logging.error("%s - %s" % (e, reconnect and "reconnecting" or "goodbye")) @@ -405,7 +410,7 @@ class WebSocketApp: frame.data, frame.fin) else: data = frame.data - if op_code == ABNF.OPCODE_TEXT: + if op_code == ABNF.OPCODE_TEXT and not skip_utf8_validation: data = data.decode("utf-8") self._callback(self.on_data, data, frame.opcode, True) self._callback(self.on_message, data) @@ -437,7 +442,7 @@ class WebSocketApp: teardown() custom_dispatcher = bool(dispatcher) - dispatcher = self.create_dispatcher(ping_timeout, dispatcher, not not sslopt) + dispatcher = self.create_dispatcher(ping_timeout, dispatcher, parse_url(self.url)[3]) if ping_interval: event = threading.Event() diff --git a/websocket/_core.py b/websocket/_core.py index 73d38b1..1d68829 100644 --- a/websocket/_core.py +++ b/websocket/_core.py @@ -46,8 +46,11 @@ class WebSocket: >>> import websocket >>> ws = websocket.WebSocket() - >>> ws.connect("ws://echo.websocket.org") + >>> ws.connect("ws://echo.websocket.events") + >>> ws.recv() + 'echo.websocket.events sponsored by Lob.com' >>> ws.send("Hello, Server") + 19 >>> ws.recv() 'Hello, Server' >>> ws.close() @@ -203,7 +206,7 @@ class WebSocket: If you set "header" list object, you can set your own custom header. >>> ws = WebSocket() - >>> ws.connect("ws://echo.websocket.org/", + >>> ws.connect("ws://echo.websocket.events", ... header=["User-Agent: MyProgram", ... "x-custom: header"]) @@ -283,7 +286,7 @@ class WebSocket: """ Send the data frame. - >>> ws = create_connection("ws://echo.websocket.org/") + >>> ws = create_connection("ws://echo.websocket.events") >>> frame = ABNF.create_frame("Hello", ABNF.OPCODE_TEXT) >>> ws.send_frame(frame) >>> cont_frame = ABNF.create_frame("My name is ", ABNF.OPCODE_CONT, 0) @@ -543,7 +546,7 @@ def create_connection(url, timeout=None, class_=WebSocket, **options): You can customize using 'options'. If you set "header" list object, you can set your own custom header. - >>> conn = create_connection("ws://echo.websocket.org/", + >>> conn = create_connection("ws://echo.websocket.events", ... header=["User-Agent: MyProgram", ... "x-custom: header"]) diff --git a/websocket/_handshake.py b/websocket/_handshake.py index 6a57c95..07a4cfb 100644 --- a/websocket/_handshake.py +++ b/websocket/_handshake.py @@ -101,7 +101,6 @@ def _get_handshake_headers(resource, url, host, port, options): # Append Sec-WebSocket-Key & Sec-WebSocket-Version if not manually specified if not options.get('header') or 'Sec-WebSocket-Key' not in options['header']: - key = _create_sec_websocket_key() headers.append("Sec-WebSocket-Key: %s" % key) else: key = options['header']['Sec-WebSocket-Key'] diff --git a/websocket/tests/test_app.py b/websocket/tests/test_app.py index 8614d08..5526d3e 100644 --- a/websocket/tests/test_app.py +++ b/websocket/tests/test_app.py @@ -191,7 +191,7 @@ class WebSocketAppTest(unittest.TestCase): """ Test WebSocketApp binary opcode """ # The lack of wss:// in the URL below is on purpose - app = ws.WebSocketApp('streaming.vn.teslamotors.com/streaming/') + app = ws.WebSocketApp('wss://streaming.vn.teslamotors.com/streaming/') app.run_forever(ping_interval=2, ping_timeout=1, ping_payload="Ping payload") @unittest.skipUnless(TEST_WITH_INTERNET, "Internet-requiring tests are disabled") diff --git a/websocket/tests/test_websocket.py b/websocket/tests/test_websocket.py index ae42ab5..d47d73e 100644 --- a/websocket/tests/test_websocket.py +++ b/websocket/tests/test_websocket.py @@ -432,7 +432,7 @@ class HandshakeTest(unittest.TestCase): self.assertRaises(ws._exceptions.WebSocketBadStatusException, websock3.connect, "wss://api.bitfinex.com/ws/2", cookie="chocolate", origin="testing_websockets.com", - host="echo.websocket.org/websocket-client-test", + host="echo.websocket.events/websocket-client-test", subprotocols=["testproto"], connection="Upgrade", header={"CustomHeader1":"123", |