4Suite API Documentation

Module Ft.Server.ThirdParty.pyftpd.timeout_socket

Sockets with timeouts.
Defines a "timeout_socket" class for connections that can potentially
cause the server to hang.  It uses select, and is based on code originally
from Scott Cotton.

The following people have contributed to the development of this module:

        Scott Cotton <scott@chronis.pobox.com>
        Lloyd Zusman <ljz@asfast.com
        Phil Mayes <pmayes@olivebr.com>
        Piers Lauder <piers@cs.su.oz.au>

Here are examples using smtplib.py and poplib.py by inheriting:

class timeout_POP3(poplib.POP3):
    def __init__(self, host, port = poplib.POP3_PORT):
        self.host = host
        self.port = port
        self.sock = timeout_socket.timeout_socket()
        self.sock.connect(self.host, self.port)
        self.file = self.sock.makefile('rb') # same as poplib.POP3
        self._debugging = 0
        self.welcome = self._getresp()

class timeout_SMTP(smtplib.SMTP):
    def connect(self, host='localhost', port = 0):
        '''Connect to a host on a given port.
        Override the std SMTP connect in order to use a timeout_socket.
        if not port:
            i = string.find(host, ':')
            if i >= 0:
                host, port = host[:i], host[i+1:]
                try: port = string.atoi(port)
                except string.atoi_error:
                    raise socket.error, "nonnumeric port"
        if not port: port = smtplib.SMTP_PORT
        self.sock = timeout_socket.timeout_socket()
        if self.debuglevel > 0: print 'connect:', (host, port)
        self.sock.connect(host, port)
        if self.debuglevel >0 : print "connect:", msg
        return (code,msg)

This allows one to use poplib.py & smtplib.py unchanged.


class Timeout(Exception)

Methods inherited from class Exception

__getitem__, __init__, __str__
class timeout_socket
Instantiate with:
        timeout_socket(timeout=20, sock=None)

where `timeout' is the desired timeout in seconds (default 20),
and `sock' is a pre-existing socket (default: one is created).


__getattr__(self, name)
__init__(self, timeout=20.0, sock=None)
connect(self, *addr)
makefile(self, flags='r', buffsize=-1)
read(self, amt)
This only returns when amt has been read or socket times out
readine for socket - buffers data
recv(self, amt, flags=0)
recvpending(self, timeout=0)
returns 1/0
send(self, data, flags=0)
timeout(self, newtimo)
change socket timeout
write(self, data)