]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Handling of juxtaposed tuples implemented.
authorMenno Smits <menno@freshfoo.com>
Sun, 31 Oct 2010 16:11:35 +0000 (16:11 +0000)
committerMenno Smits <menno@freshfoo.com>
Sun, 31 Oct 2010 16:11:35 +0000 (16:11 +0000)
A little messy, needs cleaning up.

imapclient/response_lexer.py
imapclient/response_parser.py
imapclient/test/test_response_parser.py

index 364acd776979e07cf1f575ed02d0a93e6014cdc2..7003481d8c8bd37bad278c0f359576941b8d3fe6 100644 (file)
@@ -94,6 +94,8 @@ class Lexer(object):
                         if token:
                             yield token
                         if nextchar == ')' and stream_i.peek() == '(':
+                            #XXX might be cleaner just to push                                     
+                            stream_i.next()
                             yield ')('
                         else:
                             yield nextchar    # yield the punctuation
index ebc521348f2f1916e23e40fdd655e137537ae2c9..c730c844702c71f2a375703936615dc8862d2fe1 100644 (file)
@@ -120,11 +120,24 @@ def _convert_INTERNALDATE(date_string):
 
 def atom(src, token):
     if token == "(":
-        out = []
+        #XXX names, use separate func?
+        out = target = []
         for token in src:
             if token == ")":
+                if target is not out:
+                    out[-1] = tuple(out[-1])
+                    return out
                 return tuple(out)
-            out.append(atom(src, token))
+            elif token == ')(':
+                if target is out:
+                    target = []
+                    out = [tuple(out), target]
+                else:
+                    out[-1] = tuple(out[-1])
+                    target = []
+                    out.append(target)
+            else:
+                target.append(atom(src, token))
         # oops - no terminator!
         preceeding = ' '.join(str(val) for val in out)
         raise ParseError('Tuple incomplete before "(%s"' % preceeding)
index b70df309c45be829cab8d297105baae5e4dbfee3..3565fa1fe0c3805518489b963db17f8577787cb6 100644 (file)
@@ -64,12 +64,18 @@ class TestParseResponse(unittest.TestCase):
         self._test('(123 "foo" ((0 1 2) "more" NIL) 66)',
                    (123, "foo", ((0, 1, 2), "more", None), 66))
 
-    def test_backed_up_tuples(self):
+    def test_juxtatposed_tuples(self):
+        # Tuples with no whitespace between them should be returned as
+        # a list of tuples
         self._test('((12 "foo")(34 NIL 0) "foo")',
                    ([(12, "foo"), (34, None, 0)], "foo"))
+        self._test('((12 "foo")(34 NIL 0)(4 55 6) "foo")',
+                   ([(12, "foo"), (34, None, 0), (4, 55, 6)], "foo"))
+        self._test('((12 "foo")(34 (NIL 1 2) 0)(4 55 6) "foo")',
+                   ([(12, "foo"), (34, (None, 1, 2), 0), (4, 55, 6)], "foo"))
 
     def test_complex_mixed(self):
-        self._test('((FOO "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 1152 23)'
+        self._test('((FOO "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 1152 23) '
                    '("TEXT" "PLAIN" ("CHARSET" "US-ASCII" "NAME" "cc.diff") '
                    '"<hi.there>" "foo" "BASE64" 4554 73) "MIXED")',
                    (('FOO', 'PLAIN', ('CHARSET', 'US-ASCII'), None, None, '7BIT', 1152, 23),