]> khamidou — GitHub mirrors - imapclient.git/commitdiff
experimenting with fix for BODYSTRUCTURE tuples issue (#58)
authorMenno Smits <menno@freshfoo.com>
Thu, 16 Sep 2010 16:49:57 +0000 (17:49 +0100)
committerMenno Smits <menno@freshfoo.com>
Thu, 16 Sep 2010 16:49:57 +0000 (17:49 +0100)
imapclient/response_lexer.py

index 74eb63e77eeb599fcfb828fdeaacab35d6d86a7e..364acd776979e07cf1f575ed02d0a93e6014cdc2 100644 (file)
@@ -93,7 +93,10 @@ class Lexer(object):
                         # Other punctuation, eg. "("
                         if token:
                             yield token
-                        yield nextchar    # yield the punctuation
+                        if nextchar == ')' and stream_i.peek() == '(':
+                            yield ')('
+                        else:
+                            yield nextchar    # yield the punctuation
                     break
             else:
                 if token:
@@ -139,6 +142,8 @@ class LiteralHandlingIter:
 
 class PushableIterator(object):
 
+    NO_MORE = object()
+
     def __init__(self, it):
         self.it = iter(it)
         self.pushed = []
@@ -153,3 +158,11 @@ class PushableIterator(object):
 
     def push(self, item):
         self.pushed.append(item)
+
+    def peek(self, default=NO_MORE):
+        if not self.pushed:
+            try:
+                self.pushed.append(self.it.next())
+            except StopIteration:
+                return default
+        return self.pushed[-1]