From 973a67d93443ab2e1a8e7cf5aed3ed6a9d2b50b5 Mon Sep 17 00:00:00 2001
From: Per Cederqvist <ceder@lysator.liu.se>
Date: Sun, 26 Oct 2003 19:12:05 +0000
Subject: [PATCH] Documentation added. (TcpBase): New class.  This contains
 most of the old Tcp class, 	except for the socket creating and connecting
 code. (Tcp): Renamed to TcpBase. (TcpClient): New class.
 (TcpClient.__init__): New method.

---
 pcl_expect/tcp.py | 49 ++++++++++++++++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 13 deletions(-)

diff --git a/pcl_expect/tcp.py b/pcl_expect/tcp.py
index 91cbbf3..23d824c 100644
--- a/pcl_expect/tcp.py
+++ b/pcl_expect/tcp.py
@@ -1,32 +1,55 @@
+"""Connect to a TCP socket.
+
+   This module provides the TcpClient class.  It inherits Expectable
+   and can be used to communicate with a TCP/IP server.
+"""
+
 import socket
 
 import pcl_expect
 
 __all__ = [
-    "Tcp",
+    "TcpBase",
+    "TcpClient",
     ]
 
-class Tcp(pcl_expect.Expectable):
-
-    """Connect to a TCP port."""
+class TcpBase(pcl_expect.Expectable):
 
-    def __init__(self, sockaddr):
-        """Connect a TCP socket to the address given by sockaddr.
-
-           sockaddr is passed to the connect() method of a socket
-           object.  It should normally be a pair of a host name and
-           port number.
+    """Communicate with a remote TCP port."""
 
+    def __init__(self, sock):
+        """Communicate with sock, which should be a connected socket object.
         """
 
-        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-        self.sock.connect(sockaddr)
+        self.sock = sock
         pcl_expect.Expectable.__init__(self, self.sock.fileno())
 
     def send(self, s):
+        """Send a string to the remote TCP port."""
         self.sock.send(s)
 
     def close(self):
+        """Close the session."""
         pcl_expect.Expectable.close(self)
         self.sock.close()
+
+class TcpClient(TcpBase):
+
+    """Connect to a remote TCP port."""
+
+    def __init__(self, sockaddr):
+        """Connect a TCP socket to the address given by sockaddr.
+
+           sockaddr is passed to the connect() method of a socket
+           object.  It should normally be a pair of a host name and
+           port number.
+
+        """
+
+        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+        sock.connect(sockaddr)
+        TcpBase.__init__(self, sock)
+
+# FIXME (bug 1180): It would be nice to provide a TcpServer class as
+# well, but it wouldn't fit in the current Expectable framework.
-- 
GitLab