Changeset 230:92e425d7252a for imapclient
- Timestamp:
- 03/06/11 22:19:09 (12 months ago)
- Branch:
- default
- Location:
- imapclient
- Files:
-
- 2 modified
-
response_parser.py (modified) (1 diff)
-
test/test_response_parser.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
imapclient/response_parser.py
r229 r230 112 112 def create(cls, response): 113 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 114 # at the start. Nest these in to a list so that the returned 115 # response tuple always has a consistent number of elements 116 # regardless of whether the message is multipart or not. 117 if isinstance(response[0], tuple): 118 # Multipart, find where the message part tuples stop 119 for i, part in enumerate(response): 120 if isinstance(part, basestring): 121 break 122 return cls((list(response[:i]),) + response[i:]) 123 else: 124 return cls(response) 125 119 126 @property 120 127 def is_multipart(self): -
imapclient/test/test_response_parser.py
r228 r230 259 259 260 260 def check_BODYish_single_part(self, respType): 261 resp = '123 (UID 317 %s ("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 16 1))' % respType 262 self.assertEquals(parse_fetch_response([resp]), 263 { 317: {respType: ('TEXT', 'PLAIN', ('CHARSET', 'us-ascii'), None, None, '7BIT', 16, 1), 264 'SEQ': 123 } 265 }) 261 text = '123 (UID 317 %s ("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 16 1))' % respType 262 parsed = parse_fetch_response([text]) 263 self.assertEquals(parsed, {317: {respType: ('TEXT', 'PLAIN', ('CHARSET', 'us-ascii'), None, None, '7BIT', 16, 1), 264 'SEQ': 123 } 265 }) 266 self.assertFalse(parsed[317][respType].is_multipart) 266 267 267 268 def check_BODYish_multipart(self, respType): 268 resp= '123 (UID 269 %s (("TEXT" "HTML" ("CHARSET" "us-ascii") NIL NIL "QUOTED-PRINTABLE" 55 3)' \269 text = '123 (UID 269 %s (("TEXT" "HTML" ("CHARSET" "us-ascii") NIL NIL "QUOTED-PRINTABLE" 55 3)' \ 269 270 '("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "7BIT" 26 1) "MIXED"))' \ 270 271 % respType 271 self.assertEquals(parse_fetch_response([resp]), 272 {269: {respType: ([('TEXT', 'HTML', ('CHARSET', 'us-ascii'), None, None, 'QUOTED-PRINTABLE', 55, 3), 273 ('TEXT', 'PLAIN', ('CHARSET', 'us-ascii'), None, None, '7BIT', 26, 1)], 274 'MIXED'), 275 'SEQ': 123} 276 }) 272 parsed = parse_fetch_response([text]) 273 self.assertEquals(parsed, {269: {respType: ([('TEXT', 'HTML', ('CHARSET', 'us-ascii'), None, None, 'QUOTED-PRINTABLE', 55, 3), 274 ('TEXT', 'PLAIN', ('CHARSET', 'us-ascii'), None, None, '7BIT', 26, 1)], 275 'MIXED'), 276 'SEQ': 123} 277 }) 278 self.assertTrue(parsed[269][respType].is_multipart) 277 279 278 280 def test_partial_fetch(self):
