]> khamidou — GitHub mirrors - imapclient.git/commitdiff
#43: numeric folder names break list_folders
authorMenno Smits <menno@freshfoo.com>
Thu, 29 Apr 2010 21:49:35 +0000 (22:49 +0100)
committerMenno Smits <menno@freshfoo.com>
Thu, 29 Apr 2010 21:49:35 +0000 (22:49 +0100)
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.

imapclient/response_parser.py
livetest.py

index 218d7b07afb4d66f047e6344e4704b8f3bf7df94..259d0836b77dd5934ca5340e8fa911eca0eb5381 100644 (file)
@@ -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:
index deb53a4c51df726dd5024c08c097ba7496010cad..0e41c3274b6101fc45a018292cc0c87aeeeb710f 100755 (executable)
@@ -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)