offlineimap rev 502
"Automatic Subversion Change Mailer" <[email protected]> Wed, 16 Jul 2003 15:31:01 -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 15:30:49 -0500 (Wed, 16 Jul 2003)
New Revision: 502
Modified:
imaplib/head/imap2/parser/grammar.g
imaplib/head/imap2/parser/grammar.py
imaplib/head/imap2/parser/grammarTest.py
Log:
Got some startup bugs worked out. The system can now properly parse a
greeting string.
Diff:
Modified: imaplib/head/imap2/parser/grammar.g
==============================================================================
--- imaplib/head/imap2/parser/grammar.g 2003-07-16 19:55:40 UTC (rev 501)
+++ imaplib/head/imap2/parser/grammar.g 2003-07-16 20:30:49 UTC (rev 502)
@@ -2,7 +2,7 @@
# $Id$
# COPYRIGHT #
-# Copyright (C) 2002 John Goerzen
+# Copyright (C) 2003 John Goerzen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -18,6 +18,9 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# END OF COPYRIGHT #
+
+from Objects import *
+
%%
parser IMAP:
@@ -210,10 +213,9 @@
rule capability: ("(?i)AUTH=" auth_type {{ v = "AUTH=" + auth_type }}
| atom {{ v = atom }} ) {{ return v }}
+ # This rule does not enforce IMAP4rev1
rule capability_data: "(?i)CAPABILITY" {{ v = [] }}
- (SP capability {{ v.append(capability) }})*
- "(?i)IMAP4rev1" {{ v.append("IMAP4rev1") }}
- (SP capability {{ v.append(capability) }})*
+ (SP capability {{ v.append(capability) }})+
{{ return v }}
#rule command:
#rule command_any:
@@ -421,13 +423,13 @@
rule response: {{ v = [] }}
(continue_req {{ v.append(continue_req)}}
| response_data {{ v.append(response_data) }} )*
- response_done {{ return [response_done] + v }}
+ response_done {{ return Response(response_done, v) }}
rule response_data: ASTERISK SP (
resp_cond_state {{ v = resp_cond_state }}
| resp_cond_bye {{ v = resp_cond_bye}}
| mailbox_data {{ v = mailbox_data }}
| message_data {{ v = message_data }}
- | capability_data {{ v = capability_data}}) CRLF {{ return v }}
+ | capability_data {{ v = capability_data}} ) CRLF {{ return v }}
rule response_done: (response_tagged {{ v = response_tagged}}
| response_fatal {{ v = response_fatal}}) {{ return v}}
rule response_fatal: ASTERISK SP resp_cond_bye CRLF {{ return resp_cond_bye}}
@@ -533,3 +535,9 @@
##############################
rule zone: PLUSMINUS DIGITx4 {{ return PLUSMINUS + DIGITx4 }}
+
+ ##################################################
+ # Testing
+ ##################################################
+
+ rule test_capability_data: capability_data END {{ return capability_data }}
Modified: imaplib/head/imap2/parser/grammar.py
==============================================================================
--- imaplib/head/imap2/parser/grammar.py 2003-07-16 19:55:40 UTC (rev 501)
+++ imaplib/head/imap2/parser/grammar.py 2003-07-16 20:30:49 UTC (rev 502)
@@ -2,7 +2,7 @@
# $Id: grammar.g 491 2003-07-16 19:38:49Z jgoerzen $
# COPYRIGHT #
-# Copyright (C) 2002 John Goerzen
+# Copyright (C) 2003 John Goerzen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -19,6 +19,9 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# END OF COPYRIGHT #
+from Objects import *
+
+
from string import *
import re
from yappsrt import *
@@ -58,7 +61,6 @@
("r'\\}'", re.compile('\\}')),
("r'\\{'", re.compile('\\{')),
("r'(?i)\\\\Recent'", re.compile('(?i)\\\\Recent')),
- ('"(?i)IMAP4rev1"', re.compile('(?i)IMAP4rev1')),
('"(?i)CAPABILITY"', re.compile('(?i)CAPABILITY')),
('"(?i)AUTH="', re.compile('(?i)AUTH=')),
('"="', re.compile('=')),
@@ -178,7 +180,7 @@
while 1:
ATOM_CHAR = self._scan('ATOM_CHAR')
v += ATOM_CHAR
- if self._peek('ATOM_CHAR', 'SP', 'RESP_TEXT_CHAR', 'CRLF', 'RBRACKET', '"(?i)IMAP4rev1"', 'RPAREN') != 'ATOM_CHAR': break
+ if self._peek('ATOM_CHAR', 'SP', 'RESP_TEXT_CHAR', 'CRLF', 'RBRACKET', 'END', 'RPAREN') != 'ATOM_CHAR': break
return v
def ASTRING_CHAR(self):
@@ -485,16 +487,11 @@
def capability_data(self):
self._scan('"(?i)CAPABILITY"')
v = []
- while self._peek('SP', '"(?i)IMAP4rev1"') == 'SP':
+ while 1:
SP = self._scan('SP')
capability = self.capability()
v.append(capability)
- self._scan('"(?i)IMAP4rev1"')
- v.append("IMAP4rev1")
- while self._peek('SP', 'RESP_TEXT_CHAR', 'CRLF', 'RBRACKET') == 'SP':
- SP = self._scan('SP')
- capability = self.capability()
- v.append(capability)
+ if self._peek('SP', 'END', 'RESP_TEXT_CHAR', 'CRLF', 'RBRACKET') != 'SP': break
return v
def continue_req(self):
@@ -1003,7 +1000,7 @@
response_data = self.response_data()
v.append(response_data)
response_done = self.response_done()
- return [response_done] + v
+ return Response(response_done, v)
def response_data(self):
ASTERISK = self._scan('ASTERISK')
@@ -1282,7 +1279,12 @@
self._scan('DIGITx4')
return PLUSMINUS + DIGITx4
+ def test_capability_data(self):
+ capability_data = self.capability_data()
+ END = self._scan('END')
+ return capability_data
+
def parse(rule, text):
P = IMAP(IMAPScanner(text))
return wrap_error_reporter(P, rule)
Modified: imaplib/head/imap2/parser/grammarTest.py
==============================================================================
--- imaplib/head/imap2/parser/grammarTest.py 2003-07-16 19:55:40 UTC (rev 501)
+++ imaplib/head/imap2/parser/grammarTest.py 2003-07-16 20:30:49 UTC (rev 502)
@@ -23,17 +23,17 @@
import GrammarClass
def parse(text, goal = 'goal'):
- return GrammarClass.parse('goal', text)
+ return GrammarClass.parse(goal, text)
class ParseTestCase(unittest.TestCase):
# These examples are from the RFC.
def test_ex_Connect(self):
result = parse("* OK IMAP4rev1 Service Ready\r\n", 'goal_connect')
- self.assertEquals(result, [])
+ self.assertEquals(result, {'result': 'OK', 'detail': {'text': 'IMAP4rev1 Service Ready'}})
def test_ex_Login(self):
result = parse("a001 OK LOGIN completed\r\n")
- self.assertEquals(result, [{'state': {'result': 'OK', 'detail': {'text': 'LOGIN completed'}}, 'tag': 'a001'}])
+ self.assertEquals(result, {'data': [], 'response': {'state': {'result': 'OK', 'detail': {'text': 'LOGIN completed'}}, 'tag': 'a001'}})
def test_ex_Select(self):
result = parse("* 18 EXISTS\r\n" + \
@@ -42,8 +42,18 @@
"* 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(result, [{'state': {'result': 'OK', 'detail': {'text': 'SELECT completed', 'code': ['READ-WRITE']}}, 'tag': 'a002'}, {'EXISTS': 18L}, {'flags': ['\\Answered', '\\Flagged', '\\Deleted', '\\Seen', '\\Draft']}, {'RECENT': 2L}, {'result': 'OK', 'detail': {'text': 'Message 17 is the first unseen message', 'code': ['UNSEEN', 17L]}}, {'result': 'OK', 'detail': {'text': 'UIDs valid', 'code': ['UIDVALIDITY', 3857529045L]}}])
+ self.assertEquals(result, {'data': [{'EXISTS': 18L}, {'flags': ['\\Answered', '\\Flagged', '\\Deleted', '\\Seen', '\\Draft']}, {'RECENT': 2L}, {'result': 'OK', 'detail': {'text': 'Message 17 is the first unseen message', 'code': ['UNSEEN', 17L]}}, {'result': 'OK', 'detail': {'text': 'UIDs valid', 'code': ['UIDVALIDITY', 3857529045L]}}], 'response': {'state': {'result': 'OK', 'detail': {'text': 'SELECT completed', 'code': ['READ-WRITE']}}, 'tag': 'a002'}})
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(result, [])
+ self.assertEquals(result, {'result': 'OK', 'detail': {'text': 'Courier-IMAP ready. Copyright 1998-2003 Double Precision, Inc. See COPYING for distribution information.', 'code': [['IMAP4rev1', 'CHILDREN', 'NAMESPACE', 'THREAD=ORDEREDSUBJECT', 'THREAD=REFERENCES', 'SORT', 'QUOTA', 'IDLE', 'AUTH=PLAIN']]}})
+
+ 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(result, {'data': [['IMAP4rev1', 'CHILDREN', 'NAMESPACE', 'THREAD=ORDEREDSUBJECT', 'THREAD=REFERENCES', 'SORT', 'QUOTA', 'IDLE']], 'response': {'state': {'result': 'OK', 'detail': {'text': 'CAPABILITY completed'}}, 'tag': '2'}})
+
+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(result, ['IMAP4rev1', 'CHILDREN', 'NAMESPACE', 'THREAD=ORDEREDSUBJECT', 'THREAD=REFERENCES', 'SORT', 'QUOTA', 'IDLE', 'AUTH=PLAIN'])
+