Show
Ignore:
Timestamp:
12/17/09 12:00:01 (2 years ago)
Author:
Menno Smits <menno@…>
Branch:
default
Message:

committing response parser progress so far, lots of failing tests

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • imapclient/response_parser.py

    r107 r109  
    66 
    77import shlex 
     8from cStringIO import StringIO 
    89 
    910#XXX higher level response type response type processing 
     
    2122 
    2223def parse_response(text): 
    23     #XXX 
     24    #XXX doc 
    2425    src = ResponseTokeniser(text) 
    2526    try: 
    26         return tuple([atom(src, token) for token in src]) 
     27        return tuple(atom(src, token) for token in src) 
    2728    except ParseError: 
    2829        raise 
     
    3233 
    3334def parse_fetch_response(text): 
    34     #XXX 
    35     response = parse_response(text) 
     35    response = iter(parse_response(text)) 
    3636 
    37     msgid = response[0] 
     37    def expect(expected_value): 
     38        next_value = response.next() 
     39        if next_value != expected_value: 
     40            raise ParseError('expected %r, got %r' % (expected_value, next_value)) 
    3841 
    39     # Second item should be FETCH 
    40     if response[1] != 'FETCH': 
    41         raise ParseError('not a FETCH response') 
    42  
    43  
     42    msg_data = {} 
     43    while True: 
     44        try: 
     45            expect('*') 
     46        except StopIteration: 
     47            break 
     48        msgid = int(response.next()) 
     49        expect('FETCH') 
     50        msg_data[msgid] = response.next() 
     51    return msg_data 
    4452 
    4553