cpython: d30fd9834cec (original) (raw)
Mercurial > cpython
changeset 80574:d30fd9834cec
Issue #4473: Add a POP3.capa() method to query the capabilities advertised by the POP3 server. Patch by Lorenzo Catucci. [#4473]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Fri, 23 Nov 2012 20:07:39 +0100 |
parents | 79e33578dc05 |
children | 2329f9198d7f |
files | Doc/library/poplib.rst Lib/poplib.py Lib/test/test_poplib.py Misc/NEWS |
diffstat | 4 files changed, 57 insertions(+), 0 deletions(-)[+] [-] Doc/library/poplib.rst 8 Lib/poplib.py 30 Lib/test/test_poplib.py 16 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Doc/library/poplib.rst
+++ b/Doc/library/poplib.rst
@@ -97,6 +97,14 @@ An :class:POP3
instance has the follow
Returns the greeting string sent by the POP3 server.
+.. method:: POP3.capa()
+
- Query the server's capabilities as specified in :rfc:
2449
. - Returns a dictionary in the form
{'name': ['param'...]}
. + - .. versionadded:: 3.4 +
+ .. method:: POP3.user(username) Send user command, response should indicate that a password is required.
--- a/Lib/poplib.py +++ b/Lib/poplib.py @@ -55,6 +55,7 @@ class POP3: APOP name digest apop(name, digest) TOP msg n top(msg, n) UIDL [msg] uidl(msg = None)
CAPA capa()[](#l2.7)
Raises one exception: 'error_proto'. @@ -322,6 +323,35 @@ class POP3: return self._shortcmd('UIDL %s' % which) return self._longcmd('UIDL') +
- def capa(self):
"""Return server capabilities (RFC 2449) as a dictionary[](#l2.17)
>>> c=poplib.POP3('localhost')[](#l2.18)
>>> c.capa()[](#l2.19)
{'IMPLEMENTATION': ['Cyrus', 'POP3', 'server', 'v2.2.12'],[](#l2.20)
'TOP': [], 'LOGIN-DELAY': ['0'], 'AUTH-RESP-CODE': [],[](#l2.21)
'EXPIRE': ['NEVER'], 'USER': [], 'STLS': [], 'PIPELINING': [],[](#l2.22)
'UIDL': [], 'RESP-CODES': []}[](#l2.23)
>>>[](#l2.24)
Really, according to RFC 2449, the cyrus folks should avoid[](#l2.26)
having the implementation splitted into multiple arguments...[](#l2.27)
"""[](#l2.28)
def _parsecap(line):[](#l2.29)
lst = line.decode('ascii').split()[](#l2.30)
return lst[0], lst[1:][](#l2.31)
caps = {}[](#l2.33)
try:[](#l2.34)
resp = self._longcmd('CAPA')[](#l2.35)
rawcaps = resp[1][](#l2.36)
for capline in rawcaps:[](#l2.37)
capnm, capargs = _parsecap(capline)[](#l2.38)
caps[capnm] = capargs[](#l2.39)
except error_proto as _err:[](#l2.40)
raise error_proto('-ERR CAPA not supported by server')[](#l2.41)
return caps[](#l2.42)
+ try: import ssl except ImportError:
--- a/Lib/test/test_poplib.py +++ b/Lib/test/test_poplib.py @@ -33,6 +33,8 @@ line3\r\n[](#l3.3) class DummyPOP3Handler(asynchat.async_chat):
+ def init(self, conn): asynchat.async_chat.init(self, conn) self.set_terminator(b"\r\n") @@ -112,6 +114,16 @@ class DummyPOP3Handler(asynchat.async_ch self.push('+OK closing.') self.close_when_done()
- def cmd_capa(self, arg):
self.push('+OK Capability list follows')[](#l3.17)
if self.CAPAS:[](#l3.18)
for cap, params in self.CAPAS.items():[](#l3.19)
_ln = [cap][](#l3.20)
if params:[](#l3.21)
_ln.extend(params)[](#l3.22)
self.push(' '.join(_ln))[](#l3.23)
self.push('.')[](#l3.24)
+ class DummyPOP3Server(asyncore.dispatcher, threading.Thread): @@ -232,6 +244,10 @@ class TestPOP3Class(TestCase): self.client.uidl() self.client.uidl('foo')
- def test_capa(self):
capa = self.client.capa()[](#l3.34)
self.assertTrue('IMPLEMENTATION' in capa.keys())[](#l3.35)
+ def test_quit(self): resp = self.client.quit() self.assertTrue(resp)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -138,6 +138,9 @@ Core and Builtins Library ------- +- Issue #4473: Add a POP3.capa() method to query the capabilities advertised