Skip to content

Commit

Permalink
revert #442
Browse files Browse the repository at this point in the history
  • Loading branch information
liris committed Aug 19, 2018
1 parent 8a8a2eb commit ae58949
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 122 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
47 changes: 0 additions & 47 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------------
Expand Down
40 changes: 0 additions & 40 deletions examples/echoapp_client_inheritance.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup
import pkg_resources

VERSION = "0.50.0"
VERSION = "0.51.0"
NAME = "websocket_client"

install_requires = ["six"]
Expand Down
2 changes: 1 addition & 1 deletion websocket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
from ._logging import *
from ._socket import *

__version__ = "0.50.0"
__version__ = "0.51.0"
21 changes: 10 additions & 11 deletions websocket/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ def __init__(self, url, header=None,
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
Expand Down Expand Up @@ -311,7 +311,6 @@ def create_dispatcher(self, ping_timeout):
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:
Expand All @@ -330,7 +329,7 @@ def _get_close_args(self, data):
def _callback(self, callback, *args):
if callback:
try:
if inspect.ismethod(callback) and isinstance(callback.__self__, WebSocketApp):
if inspect.ismethod(callback):

This comment has been minimized.

Copy link
@bhy

bhy Sep 27, 2018

Looks like the revert isn't done cleanly. ismethod shouldn't be here.

This comment has been minimized.

Copy link
@engn33r

engn33r Feb 15, 2021

Collaborator

Thanks, good catch! I fixed this with 3112b7d, so I think the revert is now complete

callback(*args)
else:
callback(self, *args)
Expand Down
22 changes: 0 additions & 22 deletions websocket/tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,28 +542,6 @@ def on_open(self, *args, **kwargs):
# 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")
Expand Down

0 comments on commit ae58949

Please sign in to comment.