Show
Ignore:
Timestamp:
04/29/10 22:49:35 (2 years ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

#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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • imapclient/response_parser.py

    r142 r144  
    141141 
    142142    def read(self, n): 
    143         # We also hack into the lexer so we get special treatment for '\\' 
    144         # chars - they are only special inside a quoted string. 
     143        # Two additional hacks: 
     144        # 1. Hack into the lexer so we get special treatment for backslash 
     145        #    chars - they are only special inside a quoted string. 
     146        # 2. For quoted strings return the quotes around the string so 
     147        #    that atom() can distinguish numbers from strings. Eg. "123" vs 123. 
     148        #    These are stripped off before returning them to the user. 
    145149        assert n==1 
    146150        if self.pushed is not None: 
     
    149153        else: 
    150154            ret = self.src.read(n) 
    151             if ret=="\\" and self.lexer.state not in '"\\': 
     155            if ret == "\\" and self.lexer.state not in '"\\': 
    152156                self.pushed = "\\" 
     157            elif ret == '"' and self.lexer.state != '\\': 
     158                self.lexer.token += '"' 
    153159        return ret 
    154160 
     
    208214                                literal_len, len(literal_text))) 
    209215        return literal_text 
     216    elif len(token) >= 2 and (token[0] == token[-1] == '"'): 
     217        return token[1:-1] 
    210218    elif token.isdigit(): 
    211219        return int(token)