Skip to content

Commit b631aac

Browse files
committed
Improve docstring
1 parent 10b5926 commit b631aac

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

unpythonic/net/common.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8; -*-
2+
"""Pieces common to the REPL server and client."""
23

34
import json
45

@@ -9,31 +10,33 @@
910
class ApplevelProtocol:
1011
"""Application-level communication protocol.
1112
12-
We encode the payload as JSON encoded dictionaries, then encoded as utf-8
13-
text. The bytes are stuffed into a message using the `unpythonic.net.msg`
13+
We encode the payload dictionary as JSON, then encode the text as utf-8.
14+
The resulting bytes are stuffed into a message using the `unpythonic.net.msg`
1415
low-level message protocol.
1516
1617
This format was chosen instead of pickle to ensure the client and server
1718
can talk to each other regardless of the Python versions on each end of the
1819
connection.
1920
2021
Transmission is synchronous; when one end is sending, the other one must be
21-
receiving. Both sending and receiving will block until success, or until
22-
the socket is closed.
22+
receiving. Receiving will block until success, or until the socket is closed.
2323
2424
This can be used as a common base class for server/client object pairs.
25+
It can also be used as a mixin.
2526
26-
**NOTE**: The derived class must define two attributes:
27+
**NOTE**: The derived class (or class mixing this in) must define two
28+
attributes:
2729
28-
- `sock`: an open TCP socket connected to the peer to communicate with.
30+
- `sock`: a TCP socket. When `_send` or `_recv` is called, the socket
31+
must be open and connected to the peer to communicate with.
2932
3033
- `decoder`: `unpythonic.net.msg.MessageDecoder` instance for receiving
3134
messages. Typically this is connected to `sock` using an
3235
`unpythonic.net.msg.socketsource`, like
3336
`MessageDecoder(socketsource(sock))`.
3437
3538
These are left to the user code to define, because typically the client and
36-
server sides must handle this differently. The client can create `sock` and
39+
server sides must handle them differently. The client can create `sock` and
3740
`decoder` in its constructor, whereas a TCP server typically inherits from
3841
`socketserver.BaseRequestHandler`, and receives an incoming connection in
3942
its `handle` method (which is then the official place to create any

0 commit comments

Comments
 (0)