@@ -27,23 +27,25 @@ def _handle_alarm(signum, frame):
2727signal .signal (signal .SIGALRM , _handle_alarm )
2828
2929
30- # Protocol for establishing connection:
30+ # Protocol for establishing a paired control/REPL connection:
3131# - 1: Handshake: open the control channel, ask for metadata (prompts: sys.ps1, sys.ps2)
3232# to configure the client's prompt detector before opening the primary channel.
33- # - To keep us netcat compatible, handshake is optional. It is legal
33+ # - To keep us netcat compatible, the handshake is optional. It is legal
3434# to just immediately connect on the primary channel, in which case
3535# there will be no control channel paired with the REPL session.
36- # - 2: Open the primary channel, parse the session id from the first line of text.
36+ # - 2: Open the primary channel. Parse the session id from the first line of text.
3737# - To keep us netcat compatible, we must transmit the session id as
3838# part of the primary data stream; it cannot be packaged into a message
39- # since only `unpythonic` knows about the message protocol.
40- # - So, print "Session XX connected\n" as the first line on the server side
41- # when a client connects. In the client, parse the first line (beside
39+ # since only `unpythonic` knows about the message protocol, and the
40+ # REPL and control session server objects operate independently
41+ # (they must, since each accepts a separate incoming TCP connection,
42+ # which have nothing to do with each other).
43+ # - So, the server prints "session XX connected\n" on the first line
44+ # when a client connects. The client parses the first line (beside
4245# printing it as usual, to have the same appearance for both unpythonic
43- # and netcat connections).
44- # - 3: Send command on the control channel to pair that control channel
45- # to session id XX. Maybe print a message on the client side saying
46- # that tab completion and Ctrl+C are available.
46+ # client and netcat connections).
47+ # - 3: Send a command on the control channel to pair that control channel
48+ # to session id XX.
4749
4850# Messages must be processed by just one central decoder, to prevent data
4951# races, but also to handle buffering of incoming data correctly, because
@@ -71,15 +73,15 @@ def _send_command(self, request):
7173 """Send a command to the server, get the reply.
7274
7375 request: a dict-like, containing the "command" field and any required
74- parameters (command-dependent ).
76+ parameters (specific to each particular command).
7577
7678 On success, return the `reply` dict. On failure, return `None`.
7779 """
7880 try :
7981 self ._send (request )
8082 reply = self ._recv ()
8183 if not reply :
82- print ("Socket closed by other end ." )
84+ print ("Socket closed by server ." )
8385 return None
8486 if reply ["status" ] == "ok" :
8587 return reply
@@ -161,7 +163,7 @@ class SessionExit(Exception):
161163 for r in rs :
162164 data = sock .recv (4096 )
163165 if len (data ) == 0 :
164- print ("replclient : disconnected by server." )
166+ print ("unpythonic.net.client : disconnected by server." )
165167 raise SessionExit
166168 text = data .decode ("utf-8" )
167169 sys .stdout .write (text )
@@ -184,7 +186,7 @@ def sock_to_stdout():
184186 for r in rs :
185187 data = sock .recv (4096 )
186188 if len (data ) == 0 :
187- print ("replclient : disconnected by server." )
189+ print ("unpythonic.net.client : disconnected by server." )
188190 raise SessionExit
189191 text = data .decode ("utf-8" )
190192 sys .stdout .write (text )
@@ -219,20 +221,20 @@ def sock_to_stdout():
219221 except KeyboardInterrupt :
220222 controller .send_kbinterrupt ()
221223 except EOFError :
222- print ("replclient : Ctrl+D pressed, asking server to disconnect." )
223- print ("replclient : if the server does not respond, press Ctrl+C to force." )
224+ print ("unpythonic.net.client : Ctrl+D pressed, asking server to disconnect." )
225+ print ("unpythonic.net.client : if the server does not respond, press Ctrl+C to force." )
224226 try :
225227 print ("quit()" ) # local echo
226228 sock .sendall ("quit()\n " .encode ("utf-8" ))
227229 t .join () # wait for the EOF response
228230 except KeyboardInterrupt :
229- print ("replclient : Ctrl+C pressed, forcing disconnect." )
231+ print ("unpythonic.net.client : Ctrl+C pressed, forcing disconnect." )
230232 finally :
231233 raise SessionExit
232234 except SystemExit : # catch the alarm signaled by the socket-listening thread.
233235 raise SessionExit
234236 except BrokenPipeError :
235- print ("replclient : socket closed unexpectedly, exiting." )
237+ print ("unpythonic.net.client : socket closed unexpectedly, exiting." )
236238 raise SessionExit
237239
238240 except SessionExit :
0 commit comments