diff options
author | engn33r <engn33r@users.noreply.github.com> | 2022-08-26 00:00:00 +0000 |
---|---|---|
committer | engn33r <engn33r@users.noreply.github.com> | 2022-08-26 00:00:00 +0000 |
commit | 0c9ea4aa92aad5cf15a0407a7b106c9f7d4625c8 (patch) | |
tree | c86055994915bd07abde3fb72ed84f48eccc0977 | |
parent | bd84b50d265501d98412604f106847ab3c49d5b3 (diff) | |
download | websocket-client-0c9ea4aa92aad5cf15a0407a7b106c9f7d4625c8.tar.gz |
Clean README, run doctest CI on README examples
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | docs/source/examples.rst | 62 |
2 files changed, 62 insertions, 9 deletions
@@ -127,12 +127,3 @@ result = ws.recv() print("Received '%s'" % result) ws.close() ``` - -If you want to customize socket options, set sockopt, as seen below: - -```python -from websocket import create_connection - -ws = create_connection("ws://echo.websocket.events/", - sockopt=((socket.IPPROTO_TCP, socket.TCP_NODELAY),)) -``` diff --git a/docs/source/examples.rst b/docs/source/examples.rst index 26f18db..d3d5b99 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -704,6 +704,68 @@ You can use an asynchronous dispatcher such as `rel <https://pypi.org/project/re >>> rel.signal(2, rel.abort) # Keyboard Interrupt # doctest: +SKIP >>> rel.dispatch() # doctest: +SKIP + +README Examples +========================= + +The examples are found in the README and are copied here for sphinx doctests to verify they run without errors. + +**Long-lived Connection** + +.. doctest:: long-lived-connection + + >>> import websocket + >>> import _thread + >>> import time + >>> import rel + + >>> def on_message(ws, message): + ... print(message) + + >>> def on_error(ws, error): + ... print(error) + + >>> def on_close(ws, close_status_code, close_msg): + ... print("### closed ###") + + >>> def on_open(ws): + ... print("Opened connection") + + >>> if __name__ == "__main__": + ... websocket.enableTrace(True) + ... ws = websocket.WebSocketApp("wss://api.gemini.com/v1/marketdata/BTCUSD", + ... on_open=on_open, + ... on_message=on_message, + ... on_error=on_error, + ... on_close=on_close) + + >>> ws.run_forever(dispatcher=rel) # Set dispatcher to automatic reconnection # doctest: +SKIP + >>> rel.signal(2, rel.abort) # Keyboard Interrupt + <Signal Object | Callback:"abort"> + >>> rel.dispatch() # doctest: +SKIP + +**Short-lived Connection** + +.. doctest:: short-lived-connection + + >>> from websocket import create_connection + + >>> ws = create_connection("ws://echo.websocket.events/") + >>> print(ws.recv()) + echo.websocket.events sponsored by Lob.com + >>> print("Sending 'Hello, World'...") + Sending 'Hello, World'... + >>> ws.send("Hello, World") + 18 + >>> print("Sent") + Sent + >>> print("Receiving...") + Receiving... + >>> result = ws.recv() + >>> print("Received '%s'" % result) + Received ... + >>> ws.close() + Real-world Examples ========================= |