poplib for multihomed machines

Elbert Lev elbertlev at hotmail.com
Tue Jun 29 14:05:07 EDT 2004


Donn Cave <donn at u.washington.edu> wrote in message news:<donn-52178C.11032728062004 at gnus01.u.washington.edu>...
> 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


This is a major design error. NO-NO is C++. Constructor is supposed
only initialise members and take no actions. Unfortunatelly this
paradigm is violated in many Python classes.



More information about the Python-list mailing list