summaryrefslogtreecommitdiffstats
path: root/Lib/poplib.py
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2007-03-27 18:23:21 (GMT)
committerFacundo Batista <facundobatista@gmail.com>2007-03-27 18:23:21 (GMT)
commit1b1c347311edcddac3381b6c2cfe2f86e82e2d60 (patch)
tree386ec37379cff7189ee952aa3b37562798a0c268 /Lib/poplib.py
parent3f100992896b61b52209b5c7c57b06b805347e78 (diff)
downloadcpython-1b1c347311edcddac3381b6c2cfe2f86e82e2d60.zip
cpython-1b1c347311edcddac3381b6c2cfe2f86e82e2d60.tar.gz
cpython-1b1c347311edcddac3381b6c2cfe2f86e82e2d60.tar.bz2
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.
Diffstat (limited to 'Lib/poplib.py')
-rw-r--r--Lib/poplib.py18
1 files changed, 2 insertions, 16 deletions
diff --git a/Lib/poplib.py b/Lib/poplib.py
index 1cf114a..ba40572 100644
--- a/Lib/poplib.py
+++ b/Lib/poplib.py
@@ -76,24 +76,10 @@ class POP3:
"""
- 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()