offlineimap rev 505
"Automatic Subversion Change Mailer" <[email protected]> Wed, 16 Jul 2003 22:14:35 -0500 (CDT)
| Newsgroups | gmane.mail.imap.offlineimap.subversion |
|---|---|
| Message-ID | <[email protected]> |
You are receiving this message because
all commits get sent to this address.
Author: jgoerzen
Date: 2003-07-16 22:14:29 -0500 (Wed, 16 Jul 2003)
New Revision: 505
Modified:
imaplib/head/docs/
imaplib/head/docs/html/
imaplib/head/imap2/parser/Objects.py
imaplib/head/imap2/parser/grammar.g
imaplib/head/imap2/parser/grammar.py
imaplib/head/imap2/parser/grammarTest.py
Log:
Work to start in on the docs and enhace the OO stuff.
Diff:
Modified: imaplib/head/imap2/parser/Objects.py
==============================================================================
--- imaplib/head/imap2/parser/Objects.py 2003-07-16 21:56:06 UTC (rev 504)
+++ imaplib/head/imap2/parser/Objects.py 2003-07-17 03:14:29 UTC (rev 505)
@@ -29,7 +29,18 @@
from imap2 import Exceptions
class Response:
+ """Response objects are returned after a call to any command, and are the top level
+ result object from IMAP server."""
def __init__(self, response_done, data):
+ """Initialize the response object. This is done automatically by the parser; you should
+ never do this yourself.
+
+ The following exceptions may be raised:
+
+ Exceptions.StreamError for generic data integrity problems
+
+ Exceptions.FatalError if the server indicated a fatal error response.
+ """
self.result = response_done['result']
self.donetype = response_done['donetype']
@@ -44,9 +55,48 @@
raise Exceptions.StreamError, "Got two entries of type %s" % key
self.data[key] = item
- self.errorcheck()
+ self._errorcheck()
- def errorcheck(self):
+ def getresult(self):
+ """Returns an object representing the final result. This object will generally a subclass
+ of Resp_Cond_Generic such as Resp_Cond_State."""
+ return self.result
+
+ def getdonetype(self):
+ """Returns the type of response you are seeing. There are only two options: tagged
+ (indicating a response to a command) and fatal (indicating a fatal error).
+
+ Example: obj.getresult() -> 'tagged'"""
+ return self.donetype
+
+ def gettag(self):
+ """Returns the tag used for this command as a string if possible. If no tag was available,
+ returns None.
+
+ Example: obj.gettag() -> 'a002'"""
+ return self.tag
+
+ def getdata(self):
+ """Returns the additional information (asterisk lines) about the request as a hash.
+
+ The keys of the hash are the types of data, and the values are objects that represent them.
+
+ Example:
+
+ obj.getdata() ->
+ {'Mailbox_Data.EXISTS': <Mailbox_Data_Tok: [infotype=EXISTS] [number=18]>,
+ 'Mailbox_Data_Flags': <Mailbox_Data_Flags: ['\\Answered', '\\Flagged', '\\Deleted',
+ '\\Seen', '\\Draft']>,
+ 'Resp.UIDVALIDITY': <Resp_Cond_State: [result=OK]
+ [code=<ResponseCode: [codename=UIDVALIDITY]
+ [codeinfo=[3857529045L]]>] [text=UIDs valid]>,
+ 'Mailbox_Data.RECENT': <Mailbox_Data_Tok: [infotype=RECENT] [number=2]>,
+ 'Resp.UNSEEN': <Resp_Cond_State: [result=OK] [code=<ResponseCode: [codename=UNSEEN]
+ [codeinfo=[17L]]>] [text=Message 17 is the first unseen message]>}
+ """
+ return self.data
+
+ def _errorcheck(self):
if self.donetype == 'fatal':
raise Exceptions.FatalError, "Fatal response to command. Result: %s %s" % (self.result, self.detail)
elif self.donetype != 'tagged':
@@ -96,6 +146,12 @@
def getname(self):
return "Resp." + self.code.getname()
+ def getresult(self):
+ return self.result
+
+ def gettext(self):
+ return self.text
+
def __repr__(self):
return "<%s: [result=%s] [code=%s] [text=%s]>" % \
(self.__class__.__name__, self.result, self.code, self.text)
@@ -151,4 +207,18 @@
return "<%s: [infotype=%s] [number=%s]>" % \
(self.__class__.__name__, self.tok, self.num)
+class Message_Data_Generic(Mailbox_Data_Generic):
+ pass
+class Message_Data_Expunge(Message_Data_Generic):
+ pass
+
+class Message_Data_Fetch(Message_Data_Generic):
+ def __init__(self, number, att):
+ self.number = number
+ self.att = att
+
+ def __repr__(self):
+ return "<%s: [number=%s] [att=%s]>" % \
+ (self.__class__.__name__, self.number, self.att)
+
Modified: imaplib/head/imap2/parser/grammar.g
==============================================================================
--- imaplib/head/imap2/parser/grammar.g 2003-07-16 21:56:06 UTC (rev 504)
+++ imaplib/head/imap2/parser/grammar.g 2003-07-17 03:14:29 UTC (rev 505)
@@ -361,9 +361,9 @@
rule media_text: DQUOTE r'(?i)TEXT' DQUOTE SP media_subtype
{{ return ('TEXT', media_subtype) }}
- rule message_data: nz_number SP {{ v = [nz_number] }}
- (r'(?i)EXPUNGE' {{ v.append('EXPUNGE') }}
- | r'(?i)FETCH' SP msg_att {{ v.extend(['FETCH', msg_att]) }}
+ rule message_data: nz_number SP
+ (r'(?i)EXPUNGE' {{ v = Message_Data_Expunge(nz_number) }}
+ | r'(?i)FETCH' SP msg_att {{ v = Message_Data_Fetch(nz_number, msg_att }}
) {{ return v }}
rule msg_att: LPAREN {{ v = {} }}
(msg_att_dynamic {{ v.update(msg_att_dynamic) }}
Modified: imaplib/head/imap2/parser/grammar.py
==============================================================================
--- imaplib/head/imap2/parser/grammar.py 2003-07-16 21:56:06 UTC (rev 504)
+++ imaplib/head/imap2/parser/grammar.py 2003-07-17 03:14:29 UTC (rev 505)
@@ -1,5 +1,5 @@
# Implementation of grammar from RFC3501
-# $Id: grammar.g 502 2003-07-16 21:03:53Z jgoerzen $
+# $Id: grammar.g 504 2003-07-16 21:56:06Z jgoerzen $
# COPYRIGHT #
# Copyright (C) 2003 John Goerzen
Modified: imaplib/head/imap2/parser/grammarTest.py
==============================================================================
--- imaplib/head/imap2/parser/grammarTest.py 2003-07-16 21:56:06 UTC (rev 504)
+++ imaplib/head/imap2/parser/grammarTest.py 2003-07-17 03:14:29 UTC (rev 505)
@@ -35,31 +35,38 @@
def test_ex_Login(self):
result = parse("a001 OK LOGIN completed\r\n")
self.assertEquals(repr(result),
- '<Response: [result=OK] [donetype=tagged] [code=None] [text=LOGIN completed] [tag=a001]>')
+ '<Response: [result=<Resp_Cond_State: [result=OK] [code=None] [text=LOGIN completed]>] [donetype=tagged] [tag=a001] [data={}]>')
def test_ex_Select(self):
- result = parse("* 18 EXISTS\r\n" + \
+ response = parse("* 18 EXISTS\r\n" + \
"* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)\r\n"+\
"* 2 RECENT\r\n" + \
"* OK [UNSEEN 17] Message 17 is the first unseen message\r\n" + \
"* OK [UIDVALIDITY 3857529045] UIDs valid\r\n" +
"a002 OK [READ-WRITE] SELECT completed\r\n")
- self.assertEquals(repr(result),
- '<Response: [result=OK] [donetype=tagged] [code=<ResponseCode: [codename=READ-WRITE] [codeinfo=[]]>] [text=SELECT completed] [tag=a002]>')
+ result = response.getresult()
+ self.assertEquals(response.getdonetype(), 'tagged')
+ self.assertEquals(response.gettag(), 'a002')
+ data = response.getdata()
+ self.assertEquals(result.getresult(), 'OK')
+ self.assertEquals(result.gettext(), 'SELECT completed')
+
+ self.assertEquals(repr(response),
+ "<Response: [result=<Resp_Cond_State: [result=OK] [code=<ResponseCode: [codename=READ-WRITE] [codeinfo=[]]>] [text=SELECT completed]>] [donetype=tagged] [tag=a002] [data={'Mailbox_Data.EXISTS': <Mailbox_Data_Tok: [infotype=EXISTS] [number=18]>, 'Mailbox_Data_Flags': <Mailbox_Data_Flags: ['\\\\Answered', '\\\\Flagged', '\\\\Deleted', '\\\\Seen', '\\\\Draft']>, 'Resp.UIDVALIDITY': <Resp_Cond_State: [result=OK] [code=<ResponseCode: [codename=UIDVALIDITY] [codeinfo=[3857529045L]]>] [text=UIDs valid]>, 'Mailbox_Data.RECENT': <Mailbox_Data_Tok: [infotype=RECENT] [number=2]>, 'Resp.UNSEEN': <Resp_Cond_State: [result=OK] [code=<ResponseCode: [codename=UNSEEN] [codeinfo=[17L]]>] [text=Message 17 is the first unseen message]>}]>")
def test_Courier_Connect(self):
result = parse("* OK [CAPABILITY IMAP4rev1 CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE AUTH=PLAIN] Courier-IMAP ready. Copyright 1998-2003 Double Precision, Inc. See COPYING for distribution information.\r\n", "goal_connect")
self.assertEquals(repr(result),
- "<Resp_Cond_State: [result=OK] [code=<ResponseCode: [codename=['IMAP4rev1', 'CHILDREN', 'NAMESPACE', 'THREAD=ORDEREDSUBJECT', 'THREAD=REFERENCES', 'SORT', 'QUOTA', 'IDLE', 'AUTH=PLAIN']] [codeinfo=[]]>] [text=Courier-IMAP ready. Copyright 1998-2003 Double Precision, Inc. See COPYING for distribution information.]>")
+ "<Resp_Cond_State: [result=OK] [code=<ResponseCode: [codename=<Capabilities ['IMAP4rev1', 'CHILDREN', 'NAMESPACE', 'THREAD=ORDEREDSUBJECT', 'THREAD=REFERENCES', 'SORT', 'QUOTA', 'IDLE', 'AUTH=PLAIN']>] [codeinfo=[]]>] [text=Courier-IMAP ready. Copyright 1998-2003 Double Precision, Inc. See COPYING for distribution information.]>")
def test_Courier_Capability(self):
result = parse("* CAPABILITY IMAP4rev1 CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE\r\n2 OK CAPABILITY completed\r\n")
self.assertEquals(repr(result),
- '<Response: [result=OK] [donetype=tagged] [code=None] [text=CAPABILITY completed] [tag=2]>')
+ "<Response: [result=<Resp_Cond_State: [result=OK] [code=None] [text=CAPABILITY completed]>] [donetype=tagged] [tag=2] [data={'Capabilities': <Capabilities ['IMAP4rev1', 'CHILDREN', 'NAMESPACE', 'THREAD=ORDEREDSUBJECT', 'THREAD=REFERENCES', 'SORT', 'QUOTA', 'IDLE']>}]>")
class RuleTestCase(unittest.TestCase):
def test_capability_data(self):
result = parse("CAPABILITY IMAP4rev1 CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE AUTH=PLAIN", "test_capability_data")
self.assertEquals(repr(result),
- "['IMAP4rev1', 'CHILDREN', 'NAMESPACE', 'THREAD=ORDEREDSUBJECT', 'THREAD=REFERENCES', 'SORT', 'QUOTA', 'IDLE', 'AUTH=PLAIN']")
+ "<Capabilities ['IMAP4rev1', 'CHILDREN', 'NAMESPACE', 'THREAD=ORDEREDSUBJECT', 'THREAD=REFERENCES', 'SORT', 'QUOTA', 'IDLE', 'AUTH=PLAIN']>")