imaplib : error reporting use 'randomly' exception or return value
- From: "aspineux" <aspineux@xxxxxxxxx>
- Date: 1 Feb 2007 14:28:17 -0800
imaplib use exception to report errors, but some problems must be
detected by checking the return value !
For example, when trying to append into a mailbox with wrong ACL,
imaplib return 'NO', but dont raise any exception (I give a sample at
the end).
This make error handling more complicate, because any imap statement
is supposed to be followed by a test of the returned value!
Why not report all problems using exceptions ?
It easy to modify imaplib.py to manage this because most of the imap
call are made through function
_simple_command this way :
def _simple_command(self, name, *args):
return self._command_complete(name, self._command(name,
*args))
I propose to replace it by something like :
def _simple_command(self, name, *args):
typ, dat=self._command_complete(name, self._command(name,
*args))
if typ!='OK':
raise self.error(dat[-1])
return typ, dat
Any comment ?
Here is an example, append on a mailbox with the wrong ACL fail by
returning a 'NO'
import imaplib
server='localhost'
login='test@xxxxxxxxxx'
passwd='password'
c=imaplib.IMAP4(server)
c.login(login, passwd)
c.setacl('INBOX', login, '') # set wrong ACL, removing 'i'
typ, dat=c.append('INBOX', None, None, "From: foo@xxxxxxx\nTo: %s
\nSubject: test append\n\nHello\n" % (login))
print typ, dat
output:
NO ['Permission denied']
.
- Follow-Ups:
- Prev by Date: Re: xml.dom.minidom memory usage
- Next by Date: Re: Newbie question: replacing nulls in CSV with preceding value
- Previous by thread: Python, readline and OS X
- Next by thread: Re: imaplib : error reporting use 'randomly' exception or return value
- Index(es):
Relevant Pages
|