[Python-checkins] r54585 - in python/trunk: Doc/lib/libpoplib.tex Lib/poplib.py

facundo.batista python-checkins at python.org
Tue Mar 27 20:23:29 CEST 2007


Author: facundo.batista
Date: Tue Mar 27 20:23:21 2007
New Revision: 54585
Modified:
 python/trunk/Doc/lib/libpoplib.tex
 python/trunk/Lib/poplib.py
Log:
Added an optional timeout to poplib.POP3. Also created a
test_poplib.py file with a basic test and the timeout
ones. Docs are also updated.
Modified: python/trunk/Doc/lib/libpoplib.tex
==============================================================================
--- python/trunk/Doc/lib/libpoplib.tex	(original)
+++ python/trunk/Doc/lib/libpoplib.tex	Tue Mar 27 20:23:21 2007
@@ -28,10 +28,13 @@
 
 A single class is provided by the \module{poplib} module:
 
-\begin{classdesc}{POP3}{host\optional{, port}}
+\begin{classdesc}{POP3}{host\optional{, port\optional{, timeout}}}
 This class implements the actual POP3 protocol. The connection is
 created when the instance is initialized.
 If \var{port} is omitted, the standard POP3 port (110) is used.
+The optional \var{timeout} parameter specifies a timeout in seconds for the
+connection attempt (if not specified, or passed as None, the global default
+timeout setting will be used).
 \end{classdesc}
 
 \begin{classdesc}{POP3_SSL}{host\optional{, port\optional{, keyfile\optional{, certfile}}}}
Modified: python/trunk/Lib/poplib.py
==============================================================================
--- python/trunk/Lib/poplib.py	(original)
+++ python/trunk/Lib/poplib.py	Tue Mar 27 20:23:21 2007
@@ -76,24 +76,10 @@
 """
 
 
- def __init__(self, host, port = POP3_PORT):
+ def __init__(self, host, port=POP3_PORT, timeout=None):
 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.sock = socket.create_connection((host, port), timeout)
 self.file = self.sock.makefile('rb')
 self._debugging = 0
 self.welcome = self._getresp()


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /