Skip to content

Commit 59cfff7

Browse files
authored
Merge pull request #79 from tarasko/feature/ai_docs_cleanup
Feature/ai docs cleanup
2 parents 69e1e9d + 69c32d8 commit 59cfff7

File tree

6 files changed

+45
-46
lines changed

6 files changed

+45
-46
lines changed

README.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Introduction
2222
:target: https://deepwiki.com/tarasko/picows
2323
:alt: Ask DeepWiki
2424

25-
**picows** is a high-performance python library designed for building asyncio WebSocket clients and servers.
26-
Implemented in Cython, it offers exceptional speed and efficiency, surpassing other popular WebSocket python libraries.
25+
**picows** is a high-performance Python library designed for building asyncio WebSocket clients and servers.
26+
Implemented in Cython, it offers exceptional speed and efficiency, surpassing other popular Python WebSocket libraries.
2727

2828
.. image:: https://raw.githubusercontent.com/tarasko/websocket-benchmark/master/results/benchmark-256.png
2929
:target: https://github.com/tarasko/websocket-benchmark/blob/master
@@ -79,7 +79,7 @@ Getting started
7979

8080
Echo client
8181
-----------
82-
Connects to an echo server, sends a message and disconnect upon reply.
82+
Connects to an echo server, sends a message, and disconnects after receiving a reply.
8383

8484
.. code-block:: python
8585
@@ -147,8 +147,8 @@ Echo server
147147
Features
148148
====================
149149
* Maximally efficient WebSocket frame parser and builder implemented in Cython
150-
* Re-use memory as much as possible, avoid reallocations, and avoid unnecessary Python object creations
151-
* Provide Cython .pxd for efficient integration of user Cythonized code with picows
150+
* Reuse memory as much as possible, avoid reallocations, and avoid unnecessary Python object creation
151+
* Provide a Cython .pxd for efficient integration of user Cythonized code with picows
152152
* Ability to check if a frame is the last one in the receiving buffer
153153
* Auto ping-pong with an option to customize ping/pong messages.
154154
* Convenient method to measure websocket roundtrip time using ping/pong messages.
@@ -174,7 +174,7 @@ Contributing / Building From Source
174174
# To build docs
175175
$ pip install -r docs/requirements.txt
176176

177-
4. Build inplace and run tests::
177+
4. Build in place and run tests::
178178

179179
$ python setup.py build_ext --inplace
180180
$ pytest -s -v
@@ -185,4 +185,3 @@ Contributing / Building From Source
185185
5. Build docs::
186186

187187
$ make -C docs clean html
188-

docs/source/guides.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ Eager tasks do not wait for the next event loop cycle and get executed immediate
1919
See `echo_client_async_callbacks.py <https://raw.githubusercontent.com/tarasko/picows/master/examples/echo_client_async_callbacks.py>`_
2020
illustrating this approach.
2121

22-
If you need an async get_message(), similar to what aiohttp and websockets offer, than you would have to use asyncio.Queue.
22+
If you need an async receive_message(), similar to what aiohttp and websockets offer, then you would have to use asyncio.Queue.
2323
The latency penalty will become bigger, since awaiting coroutine can only be woken up on the next event loop cycle
2424
and message payload will always have to be copied.
2525
See `echo_client_async_iteration.py <https://raw.githubusercontent.com/tarasko/picows/master/examples/echo_client_async_iteration.py>`_
2626
illustrating this approach.
2727

28-
**picows** let you choose the best possible approach for your project. Very often turning async is not really necessary on
28+
**picows** lets you choose the best possible approach for your project. Very often turning async is not really necessary on
2929
the data path. With **picows** you can delay this and do it only when necessary, for example, only when you actually have to start
3030
some async operation.
3131

@@ -77,10 +77,10 @@ debug logging.
7777
Exceptions handling
7878
-------------------
7979

80-
When talking about how library deals with exceptions, there are 2 questions that
80+
When talking about how the library deals with exceptions, there are two questions that
8181
must be addressed:
8282

83-
**What kinds of exceptions can the library functions throws?**
83+
**What kinds of exceptions can the library functions throw?**
8484

8585
**picows** may raise any exception that the underlying system calls may raise.
8686
For example, `ConnectionResetError` from :any:`ws_connect` or `BrokenPipeError`
@@ -113,7 +113,7 @@ From the user's perspective, these frames function like regular frames and may c
113113

114114
**picows** offers an efficient 'auto ping' mechanism to automatically send a PING to the remote peer after a specified period of inactivity and to handle and verify PONG responses. If no PONG is received, the WebSocket will be disconnected.
115115

116-
This behaviour is controlled by the 3 parameters passed to :any:`ws_connect` or :any:`ws_create_server`:
116+
This behavior is controlled by three parameters passed to :any:`ws_connect` or :any:`ws_create_server`:
117117

118118
.. code-block:: python
119119
@@ -126,7 +126,7 @@ This behaviour is controlled by the 3 parameters passed to :any:`ws_connect` or
126126
127127
128128
Furthermore, it is possible to customize what will be ping and pong frames.
129-
Apart from PING/PONG msg types other common options are:
129+
Apart from PING/PONG message types, other common options are:
130130

131131
* TEXT frames with 'ping' and 'pong' payload.
132132
* TEXT frames with full json payload like {"op": "ping"} and {"op": "pong"}
@@ -198,13 +198,13 @@ Measuring/checking round-trip time
198198
----------------------------------
199199
`Available since 1.5`
200200

201-
**picows** allows to conveniently measure round-trip time to a remote peer using
202-
:any:`measure_roundtrip_time`. This is done by sending PING request multiple
201+
**picows** allows you to conveniently measure round-trip time to a remote peer using
202+
:any:`measure_roundtrip_time`. This is done by sending PING requests multiple
203203
times and measuring response delay.
204204

205-
Checkout an `okx_roundtrip_time.py <https://raw.githubusercontent.com/tarasko/picows/master/examples/okx_roundtrip_time.py>`_
205+
Check out `okx_roundtrip_time.py <https://raw.githubusercontent.com/tarasko/picows/master/examples/okx_roundtrip_time.py>`_
206206
example of how to measure RTT to a popular OKX crypto-currency exchange and initiate
207-
reconnect if it doesn't satisfy a predefined threshold.
207+
reconnect if it does not satisfy a predefined threshold.
208208

209209
Dealing with slow clients
210210
-------------------------
@@ -236,7 +236,7 @@ Using proxies
236236

237237
:any:`ws_connect` supports HTTP, SOCKS4 and SOCKS5 proxies via
238238
`python-socks <https://github.com/romis2012/python-socks>`_.
239-
Use ``proxy`` argument with a proxy URL. HTTPS proxy URLs (``https://...``)
239+
Use the ``proxy`` argument with a proxy URL. HTTPS proxy URLs (``https://...``)
240240
are not currently supported:
241241

242242
.. code-block:: python
@@ -254,10 +254,10 @@ Hostname resolution generally happens at the proxy, unless it is SOCK4.
254254
SOCK4 is an old protocol, where CONNECT request doesn't support host names, only IP addresses.
255255
SOCK4 hostname resolution is performed at the client.
256256

257-
Basic auth is supported. Login/password can be specified in proxy url.
257+
Basic auth is supported. Login and password can be specified in the proxy URL.
258258

259259
.. _getproxies: https://docs.python.org/3/library/urllib.request.html#urllib.request.getproxies
260260

261-
Currently **picows** doesn't attempt to use system proxy settings. If you want to use
262-
a system wide proxy settings, get them using `getproxies`_ and pass one as a
261+
Currently, **picows** does not attempt to use system proxy settings. If you want to use
262+
system-wide proxy settings, get them using `getproxies`_ and pass one as the
263263
proxy argument.

docs/source/introduction.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Introduction
1616
:target: https://picows.readthedocs.io/en/latest/
1717
:alt: Latest Read The Docs
1818

19-
**picows** is a high-performance python library designed for building asyncio WebSocket clients and servers.
20-
Implemented in Cython, it offers exceptional speed and efficiency, surpassing other popular WebSocket python libraries.
19+
**picows** is a high-performance Python library designed for building asyncio WebSocket clients and servers.
20+
Implemented in Cython, it offers exceptional speed and efficiency, surpassing other popular Python WebSocket libraries.
2121

2222
.. image:: https://raw.githubusercontent.com/tarasko/websocket-benchmark/master/results/benchmark-256.png
2323
:target: https://github.com/tarasko/websocket-benchmark/blob/master
@@ -43,7 +43,7 @@ Getting started
4343

4444
Echo client
4545
-----------
46-
Connects to an echo server, sends a message and disconnect upon reply.
46+
Connects to an echo server, sends a message, and disconnects after receiving a reply.
4747

4848
.. code-block:: python
4949

docs/source/reference.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Classes
4848
:type: bool
4949

5050
Indicates whether rsv1 flag is set in the frame.
51-
Some protocol extensions use this flag to indicated that the frame data
51+
Some protocol extensions use this flag to indicate that the frame data
5252
is compressed.
5353
For example in `permessage_deflate extension <https://www.rfc-editor.org/rfc/rfc7692#section-7>`_
5454

@@ -103,7 +103,7 @@ Classes
103103
.. py:attribute:: headers
104104
:type: CIMultiDict[str, str]
105105

106-
Request headers. Keys are case insensitive
106+
Request headers. Keys are case-insensitive
107107

108108
.. autoclass:: WSUpgradeResponse
109109
:members:
@@ -121,12 +121,12 @@ Classes
121121
.. py:attribute:: headers
122122
:type: CIMultiDict[str, str]
123123

124-
Response headers. Keys are case insensitive
124+
Response headers. Keys are case-insensitive
125125

126126
.. py:attribute:: body
127127
:type: bytes
128128

129-
Optional response body. Can be non-empty in case of errors
129+
Optional response body. It can be non-empty in case of errors
130130

131131
.. autoclass:: WSUpgradeResponseWithListener
132132
:members:
@@ -140,8 +140,8 @@ Classes
140140
.. note::
141141

142142
All `send` methods never block. The data is buffered and arranged to be sent out asynchronously in case
143-
if it can't be sent immediately.
144-
This behaviour is derived from the underlying `asyncio.WriteTransport.write`
143+
if it cannot be sent immediately.
144+
This behavior is derived from the underlying `asyncio.WriteTransport.write`
145145

146146
.. py:attribute:: underlying_transport
147147
:type: asyncio.Transport
@@ -168,17 +168,17 @@ Classes
168168

169169
Send a frame over websocket with a message as its payload.
170170
This function does not copy message to prepare websocket frames.
171-
It reuses message's memory and append websocket header at the front.
171+
It reuses the message's memory and appends a WebSocket header at the front.
172172

173173
.. attention::
174174

175-
Message's buffer should have at least 14 bytes in front of the message pointer available for writing.
175+
The message buffer should have at least 14 writable bytes in front of the message pointer.
176176

177177
:param msg_type: Message type
178178
:param msg_ptr: Pointer to a message payload
179179
:param msg_size: Size of the message payload
180180
:param fin: fin bit in websocket frame.
181-
Indicate that the frame is the last one in the message.
181+
Indicates that the frame is the last one in the message.
182182
:param rsv1: first reserved bit in websocket frame.
183183
Some protocol extensions use it to indicate that payload
184184
is compressed.

picows/api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ async def ws_connect(ws_listener_factory: Callable[[], WSListener], # type: igno
5757
**kwargs
5858
) -> tuple[WSTransport, WSListener]:
5959
"""
60-
Open a websocket connection to a given ParsedURL.
60+
Open a WebSocket connection to a given URL.
6161
6262
This function forwards its `kwargs` directly to
6363
`asyncio.loop.create_connection <https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.create_connection>`_
6464
6565
:param ws_listener_factory:
6666
A parameterless factory function that returns a user handler.
6767
User handler has to derive from :any:`WSListener`.
68-
:param url: Destination ParsedURL
68+
:param url: Destination URL
6969
:param ssl_context: optional SSLContext to override default one when
70-
wss scheme is used
70+
the wss scheme is used
7171
:param disconnect_on_exception:
7272
Indicates whether the client should initiate disconnect on any exception
7373
thrown from WSListener.on_ws_frame callbacks
@@ -95,7 +95,7 @@ async def ws_connect(ws_listener_factory: Callable[[], WSListener], # type: igno
9595
* PING_WHEN_IDLE - ping only if there is no new incoming data.
9696
* PING_PERIODICALLY - send ping at regular intervals regardless of incoming data.
9797
:param enable_auto_pong:
98-
If enabled then picows will automatically reply to incoming PING frames.
98+
If enabled, picows will automatically reply to incoming PING frames.
9999
:param max_frame_size:
100100
* Maximum allowed frame size. Disconnect will be initiated if client receives a frame that is bigger than max size.
101101
:param extra_headers:
@@ -196,11 +196,11 @@ async def ws_create_server(ws_listener_factory: WSServerListenerFactory,
196196
**kwargs
197197
) -> asyncio.Server:
198198
"""
199-
Create a websocket server listening on TCP port of the host address.
199+
Create a WebSocket server listening on a TCP port at the host address.
200200
This function forwards its `kwargs` directly to
201201
`asyncio.loop.create_server <https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.create_server>`_
202202
203-
It has a few extra parameters to control the behaviour of websocket
203+
It has a few extra parameters to control WebSocket behavior.
204204
205205
:param ws_listener_factory:
206206
A factory function that accepts WSUpgradeRequest object and returns one of:
@@ -251,9 +251,9 @@ async def ws_create_server(ws_listener_factory: WSServerListenerFactory,
251251
* PING_WHEN_IDLE - ping only if there is no new incoming data.
252252
* PING_PERIODICALLY - send ping at regular intervals regardless of incoming data.
253253
:param enable_auto_pong:
254-
If enabled then picows will automatically reply to incoming PING frames.
254+
If enabled, picows will automatically reply to incoming PING frames.
255255
:param max_frame_size:
256-
* Maximum allowed frame size. Disconnect will be initiated if server side receives frame that is bigger than max size.
256+
* Maximum allowed frame size. Disconnect will be initiated if the server side receives a frame that is bigger than the max size.
257257
:return: `asyncio.Server <https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.Server>`_ object
258258
"""
259259

picows/types.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create_error_response(status: Union[int, HTTPStatus],
3838
body: Optional[bytes] = None,
3939
extra_headers: Optional[WSHeadersLike] = None) -> Any:
4040
"""
41-
Create upgrade response with error.
41+
Create an upgrade response with an error.
4242
4343
:param status: int status code or http.HTTPStatus enum value
4444
:param body: optional bytes-like response body
@@ -63,10 +63,10 @@ def create_redirect_response(status: Union[int, HTTPStatus],
6363
location: str,
6464
extra_headers: Optional[WSHeadersLike] = None) -> Any:
6565
"""
66-
Create upgrade response with error.
66+
Create an upgrade redirect response.
6767
6868
:param status: int status code or http.HTTPStatus enum value
69-
:param body: optional bytes-like response body
69+
:param location: redirect target URL
7070
:param extra_headers: optional additional headers
7171
:return: a new WSUpgradeResponse object
7272
"""
@@ -123,7 +123,7 @@ def to_bytes(self) -> bytearray:
123123

124124
class WSUpgradeResponseWithListener:
125125
"""
126-
Bind :any:`WSUpgradeResponse` and :any:`WSListener` objects together..
126+
Bind :any:`WSUpgradeResponse` and :any:`WSListener` objects together.
127127
"""
128128
__slots__ = ("response", "listener")
129129

@@ -140,7 +140,7 @@ def __init__(self, response: WSUpgradeResponse, listener: Any):
140140

141141
class WSError(RuntimeError):
142142
"""
143-
Thrown by :any:`ws_connect` on any kind of handshake errors.
143+
Raised by :any:`ws_connect` for any kind of handshake error.
144144
"""
145145
raw_header: Optional[bytes]
146146
raw_body: Optional[bytes]

0 commit comments

Comments
 (0)