diff options
author | liris <liris.pp@gmail.com> | 2018-08-19 20:02:13 +0900 |
---|---|---|
committer | liris <liris.pp@gmail.com> | 2018-08-19 20:02:13 +0900 |
commit | ae589495b75162703ab4fe1f8712f50d22b12d4e (patch) | |
tree | 8f41a869365a028128e9e3c0eed5f68ca8441ca4 | |
parent | 8a8a2eb5d455b41a355b2e1ae93bf3323f333c74 (diff) | |
download | websocket-client-ae589495b75162703ab4fe1f8712f50d22b12d4e.tar.gz |
revert #442v0.51.0
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | README.rst | 47 | ||||
-rw-r--r-- | examples/echoapp_client_inheritance.py | 40 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | websocket/__init__.py | 2 | ||||
-rw-r--r-- | websocket/_app.py | 21 | ||||
-rw-r--r-- | websocket/tests/test_websocket.py | 22 |
7 files changed, 16 insertions, 122 deletions
@@ -1,6 +1,10 @@ ChangeLog ============ +- 0.51.0 + + - revert "WebSocketApp class to make it inheritable (#442)" because of breaking the compatibily + - 0.50.0 - fixed pong before ping (#461) @@ -106,53 +106,6 @@ This example is similar to how WebSocket code looks in browsers using JavaScript ws.run_forever() -Class inheritance ------------------ -Same as above with class inheritance. - -.. code:: python - - import websocket - from threading import Thread - import time - import sys - - - class MyApp(websocket.WebSocketApp): - def on_message(self, message): - print(message) - - def on_error(self, error): - print(error) - - def on_close(self): - print("### closed ###") - - def on_open(self): - def run(*args): - for i in range(3): - # send the message, then wait - # so thread doesn't exit and socket - # isn't closed - self.send("Hello %d" % i) - time.sleep(1) - - time.sleep(1) - self.close() - print("Thread terminating...") - - Thread(target=run).start() - - - if __name__ == "__main__": - websocket.enableTrace(True) - if len(sys.argv) < 2: - host = "ws://echo.websocket.org/" - else: - host = sys.argv[1] - ws = MyApp(host) - ws.run_forever() - Short-lived one-off send-receive -------------------------------- diff --git a/examples/echoapp_client_inheritance.py b/examples/echoapp_client_inheritance.py deleted file mode 100644 index 775e632..0000000 --- a/examples/echoapp_client_inheritance.py +++ /dev/null @@ -1,40 +0,0 @@ -import websocket -from threading import Thread -import time -import sys - - -class MyApp(websocket.WebSocketApp): - def on_message(self, message): - print(message) - - def on_error(self, error): - print(error) - - def on_close(self): - print("### closed ###") - - def on_open(self): - def run(*args): - for i in range(3): - # send the message, then wait - # so thread doesn't exit and socket - # isn't closed - self.send("Hello %d" % i) - time.sleep(1) - - time.sleep(1) - self.close() - print("Thread terminating...") - - Thread(target=run).start() - - -if __name__ == "__main__": - websocket.enableTrace(True) - if len(sys.argv) < 2: - host = "ws://echo.websocket.org/" - else: - host = sys.argv[1] - ws = MyApp(host) - ws.run_forever() @@ -3,7 +3,7 @@ import sys from setuptools import setup import pkg_resources -VERSION = "0.50.0" +VERSION = "0.51.0" NAME = "websocket_client" install_requires = ["six"] diff --git a/websocket/__init__.py b/websocket/__init__.py index 18e5892..e0af553 100644 --- a/websocket/__init__.py +++ b/websocket/__init__.py @@ -26,4 +26,4 @@ from ._exceptions import * from ._logging import * from ._socket import * -__version__ = "0.50.0" +__version__ = "0.51.0" diff --git a/websocket/_app.py b/websocket/_app.py index 90244b7..970f3bd 100644 --- a/websocket/_app.py +++ b/websocket/_app.py @@ -127,16 +127,16 @@ class WebSocketApp(object): self.header = header if header is not None else [] self.cookie = cookie - self.on_open = on_open or getattr(self, 'on_open', None) - self.on_message = on_message or getattr(self, 'on_message', None) - self.on_data = on_data or getattr(self, 'on_data', None) - self.on_error = on_error or getattr(self, 'on_error', None) - self.on_close = on_close or getattr(self, 'on_close', None) - self.on_ping = on_ping or getattr(self, 'on_ping', None) - self.on_pong = on_pong or getattr(self, 'on_pong', None) - self.on_cont_message = on_cont_message or getattr(self, 'on_cont_message', None) - self.get_mask_key = get_mask_key or getattr(self, 'get_mask_key', None) + self.on_open = on_open + self.on_message = on_message + self.on_data = on_data + self.on_error = on_error + self.on_close = on_close + self.on_ping = on_ping + self.on_pong = on_pong + self.on_cont_message = on_cont_message self.keep_running = False + self.get_mask_key = get_mask_key self.sock = None self.last_ping_tm = 0 self.last_pong_tm = 0 @@ -311,7 +311,6 @@ class WebSocketApp(object): def _get_close_args(self, data): """ this functions extracts the code, reason from the close body if they exists, and if the self.on_close except three arguments """ - import inspect # if the on_close callback is "old", just return empty list if sys.version_info < (3, 0): if not self.on_close or len(inspect.getargspec(self.on_close).args) != 3: @@ -330,7 +329,7 @@ class WebSocketApp(object): def _callback(self, callback, *args): if callback: try: - if inspect.ismethod(callback) and isinstance(callback.__self__, WebSocketApp): + if inspect.ismethod(callback): callback(*args) else: callback(self, *args) diff --git a/websocket/tests/test_websocket.py b/websocket/tests/test_websocket.py index 2fec954..f49a893 100644 --- a/websocket/tests/test_websocket.py +++ b/websocket/tests/test_websocket.py @@ -542,28 +542,6 @@ class WebSocketAppTest(unittest.TestCase): # Note: We can't use 'is' for comparing the functions directly, need to use 'id'. # self.assertEqual(WebSocketAppTest.get_mask_key_id, id(my_mask_key_func)) - def testSettingClassCallbacks(self): - """ App class should provide possibility to set callback functions via class instantiate call, class inheritance - and via setting instance attributes - """ - class TestApp(ws.WebSocketApp): - def on_close(self): - pass - - def on_open(ws): - pass - - def on_message(ws): - pass - - app = TestApp('ws://www.example.com/', on_open=on_open) - app.on_message = on_message - - #assert isinstance(app.on_close, function) - assert callable(app.on_open) - assert callable(app.on_message) - assert callable(app.on_close) - class SockOptTest(unittest.TestCase): @unittest.skipUnless(TEST_WITH_INTERNET, "Internet-requiring tests are disabled") |