poplib for multihomed machines
Donn Cave
donn at u.washington.edu
Mon Jun 28 14:03:27 EDT 2004
In article <9418be08.0406280751.6cc50097 at posting.google.com>,
elbertlev at hotmail.com (Elbert Lev) wrote:
> 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?
Well, no. It should probably use an open() method like imaplib's.
Donn Cave, donn at u.washington.edu
More information about the Python-list
mailing list