From: Menno Smits Date: Thu, 29 Apr 2010 21:49:35 +0000 (+0100) Subject: #43: numeric folder names break list_folders X-Git-Tag: 0.7~42 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=d8213f4435f8f34269a4529168596c9c1cf792d2;p=imapclient.git #43: numeric folder names break list_folders Further hacks to the lexer to allow the response parser to distinguish between a string with digits in it and an actual integer. This prevents folder names comprising of just digits from being returned as integers instead of strings. --- diff --git a/imapclient/response_parser.py b/imapclient/response_parser.py index 218d7b0..259d083 100644 --- a/imapclient/response_parser.py +++ b/imapclient/response_parser.py @@ -140,16 +140,22 @@ class LiteralHandlingReader: self.literal = None def read(self, n): - # We also hack into the lexer so we get special treatment for '\\' - # chars - they are only special inside a quoted string. + # Two additional hacks: + # 1. Hack into the lexer so we get special treatment for backslash + # chars - they are only special inside a quoted string. + # 2. For quoted strings return the quotes around the string so + # that atom() can distinguish numbers from strings. Eg. "123" vs 123. + # These are stripped off before returning them to the user. assert n==1 if self.pushed is not None: ret = self.pushed self.pushed = None else: ret = self.src.read(n) - if ret=="\\" and self.lexer.state not in '"\\': + if ret == "\\" and self.lexer.state not in '"\\': self.pushed = "\\" + elif ret == '"' and self.lexer.state != '\\': + self.lexer.token += '"' return ret def close(self): @@ -207,6 +213,8 @@ def atom(src, token): raise ParseError('Expecting literal of size %d, got %d' % ( literal_len, len(literal_text))) return literal_text + elif len(token) >= 2 and (token[0] == token[-1] == '"'): + return token[1:-1] elif token.isdigit(): return int(token) else: diff --git a/livetest.py b/livetest.py index deb53a4..0e41c32 100755 --- a/livetest.py +++ b/livetest.py @@ -146,7 +146,8 @@ def test_folders(client): '"foobar"', 'foo "bar"', 'stuff & things', - u'test & \u2622'] + u'test & \u2622', + '123'] for folder in test_folders: assert not client.folder_exists(folder)