Changeset 229:85569119917a
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r204
|
r229
|
|
| 95 | 95 | yield nextchar + read_until(stream_i, nextchar) |
| 96 | 96 | else: |
| 97 | | # Other punctuation, eg. "(" |
| | 97 | # Other punctuation, eg. "(". This ends the current token. |
| 98 | 98 | if token: |
| 99 | 99 | 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 |
| 105 | 101 | break |
| 106 | 102 | else: |
| … |
… |
|
| 165 | 161 | self.pushed.append(item) |
| 166 | 162 | |
| 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 | | |
| 175 | 163 | |
| 176 | 164 | |
-
|
r208
|
r229
|
|
| 91 | 91 | msg_data[word] = _convert_INTERNALDATE(value) |
| 92 | 92 | elif word in ('BODY', 'BODYSTRUCTURE'): |
| 93 | | msg_data[word] = BodyData(value) |
| | 93 | msg_data[word] = BodyData.create(value) |
| 94 | 94 | else: |
| 95 | 95 | msg_data[word] = value |
| … |
… |
|
| 109 | 109 | class BodyData(tuple): |
| 110 | 110 | |
| | 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 | |
| 111 | 119 | @property |
| 112 | 120 | def is_multipart(self): |
| … |
… |
|
| 165 | 173 | if token == ")": |
| 166 | 174 | 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)) |
| 171 | 176 | # no terminator |
| 172 | 177 | 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) |
| 192 | 178 | |
| 193 | 179 | |