poplib for multihomed machines

Elbert Lev elbertlev at hotmail.com
Mon Jun 28 17:51:37 CEST 2004


There no way to tell the classPOP3 which of local interfaces (NICs) to
use for connections). In most cases it is OK, but requires proper
routing.

Here is the __init__ from POP3

class POP3
    def __init__(self, host, port = POP3_PORT):
        self.host = host
        self.port = port
        msg = "getaddrinfo returns an empty list"
        self.sock = None
        for res in socket.getaddrinfo(self.host, self.port, 0,
socket.SOCK_STREAM):
            af, socktype, proto, canonname, sa = res
            try:
                self.sock = socket.socket(af, socktype, proto)
                self.sock.connect(sa)
            except socket.error, msg:
                if self.sock:
                    self.sock.close()
                self.sock = None
                continue
            break
        if not self.sock:
            raise socket.error, msg
        self.file = self.sock.makefile('rb')
        self._debugging = 0
        self.welcome = self._getresp()

Can I subclass it in such a way, that derived class takes care of the
problem?

def __init__ (self, host, port = POP3_PORT, interface = ""):
	POP3.__init..(....)
	
	will create the socket and there is no way to bind it to local
interface
	

The problem with POP3 class is: it connects during __init__ and it is
"hard coded". I do not see any way to change this behavior with no
rewrite of POP3 class.

Do you?



More information about the Python-list mailing list