Show
Ignore:
Timestamp:
03/06/11 16:30:15 (12 months ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

Halfway through re-working how BODY/BODYSTRUCTURE is handled so the parser doesn't have to treat paren lists without whitespace between them specially.

The failing tests light the way.

Location:
imapclient
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • imapclient/response_lexer.py

    r204 r229  
    9595                        yield nextchar + read_until(stream_i, nextchar) 
    9696                    else: 
    97                         # Other punctuation, eg. "(" 
     97                        # Other punctuation, eg. "(". This ends the current token. 
    9898                        if token: 
    9999                            yield token 
    100                         if nextchar == ')' and stream_i.peek() == '(': 
    101                             stream_i.next()     # Read the '(' 
    102                             yield ')(' 
    103                         else: 
    104                             yield nextchar    # yield the punctuation 
     100                        yield nextchar 
    105101                    break 
    106102            else: 
     
    165161        self.pushed.append(item) 
    166162 
    167     def peek(self, default=NO_MORE): 
    168         if not self.pushed: 
    169             try: 
    170                 self.pushed.append(self.it.next()) 
    171             except StopIteration: 
    172                 return default 
    173         return self.pushed[-1] 
    174  
    175163         
    176164         
  • imapclient/response_parser.py

    r208 r229  
    9191                msg_data[word] = _convert_INTERNALDATE(value) 
    9292            elif word in ('BODY', 'BODYSTRUCTURE'): 
    93                 msg_data[word] = BodyData(value) 
     93                msg_data[word] = BodyData.create(value) 
    9494            else: 
    9595                msg_data[word] = value 
     
    109109class BodyData(tuple): 
    110110 
     111    @classmethod 
     112    def create(cls, response): 
     113        # In case of multipart messages we will see at least 2 tuples 
     114        # at the start. Restructure these in to a list so that the 
     115        # returned response tuple always has a consistent number of 
     116        # items regardless of whether the message is multipart or not. 
     117        raise NotImplementedError 
     118     
    111119    @property 
    112120    def is_multipart(self): 
     
    165173        if token == ")": 
    166174            return tuple(out) 
    167         elif token == ')(': 
    168             return parse_juxtaposed_tuples(src, out) 
    169         else: 
    170             out.append(atom(src, token)) 
     175        out.append(atom(src, token)) 
    171176    # no terminator 
    172177    raise ParseError('Tuple incomplete before "(%s"' % _fmt_tuple(out)) 
    173  
    174  
    175 def parse_juxtaposed_tuples(src, init): 
    176     out = [tuple(init)] 
    177     current = [] 
    178     for token in src: 
    179         if token in (')', ')('): 
    180             out.append(tuple(current)) 
    181             if token == ')': 
    182                 return out 
    183             current = [] 
    184         else: 
    185             current.append(atom(src, token)) 
    186  
    187     # no terminator 
    188     preceeding = ''.join('(' + _fmt_tuple(t) + ')' for t in out) 
    189     if current: 
    190         preceeding += '(' + _fmt_tuple(current) 
    191     raise ParseError('Juxtaposed tuples incomplete before "%s"' % preceeding) 
    192178 
    193179