From 42e5fe7a3fb35c72f1f2318060befd51b8e7eb5c Mon Sep 17 00:00:00 2001 From: Menno Smits Date: Thu, 16 Sep 2010 17:49:57 +0100 Subject: [PATCH] experimenting with fix for BODYSTRUCTURE tuples issue (#58) --- imapclient/response_lexer.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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] -- 2.43.0