From: Menno Smits Date: Thu, 16 Sep 2010 16:49:57 +0000 (+0100) Subject: experimenting with fix for BODYSTRUCTURE tuples issue (#58) X-Git-Tag: 0.7~8^2~5 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=42e5fe7a3fb35c72f1f2318060befd51b8e7eb5c;p=imapclient.git experimenting with fix for BODYSTRUCTURE tuples issue (#58) --- diff --git a/imapclient/response_lexer.py b/imapclient/response_lexer.py index 74eb63e..364acd7 100644 --- a/imapclient/response_lexer.py +++ b/imapclient/response_lexer.py @@ -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]