1 | n/a | import string |
---|
2 | n/a | import unittest |
---|
3 | n/a | from email import _header_value_parser as parser |
---|
4 | n/a | from email import errors |
---|
5 | n/a | from email import policy |
---|
6 | n/a | from test.test_email import TestEmailBase, parameterize |
---|
7 | n/a | |
---|
8 | n/a | class TestTokens(TestEmailBase): |
---|
9 | n/a | |
---|
10 | n/a | # EWWhiteSpaceTerminal |
---|
11 | n/a | |
---|
12 | n/a | def test_EWWhiteSpaceTerminal(self): |
---|
13 | n/a | x = parser.EWWhiteSpaceTerminal(' \t', 'fws') |
---|
14 | n/a | self.assertEqual(x, ' \t') |
---|
15 | n/a | self.assertEqual(str(x), '') |
---|
16 | n/a | self.assertEqual(x.value, '') |
---|
17 | n/a | self.assertEqual(x.encoded, ' \t') |
---|
18 | n/a | |
---|
19 | n/a | # UnstructuredTokenList |
---|
20 | n/a | |
---|
21 | n/a | def test_undecodable_bytes_error_preserved(self): |
---|
22 | n/a | badstr = b"le pouf c\xaflebre".decode('ascii', 'surrogateescape') |
---|
23 | n/a | unst = parser.get_unstructured(badstr) |
---|
24 | n/a | self.assertDefectsEqual(unst.all_defects, [errors.UndecodableBytesDefect]) |
---|
25 | n/a | parts = list(unst.parts) |
---|
26 | n/a | self.assertDefectsEqual(parts[0].all_defects, []) |
---|
27 | n/a | self.assertDefectsEqual(parts[1].all_defects, []) |
---|
28 | n/a | self.assertDefectsEqual(parts[2].all_defects, [errors.UndecodableBytesDefect]) |
---|
29 | n/a | |
---|
30 | n/a | |
---|
31 | n/a | class TestParserMixin: |
---|
32 | n/a | |
---|
33 | n/a | def _assert_results(self, tl, rest, string, value, defects, remainder, |
---|
34 | n/a | comments=None): |
---|
35 | n/a | self.assertEqual(str(tl), string) |
---|
36 | n/a | self.assertEqual(tl.value, value) |
---|
37 | n/a | self.assertDefectsEqual(tl.all_defects, defects) |
---|
38 | n/a | self.assertEqual(rest, remainder) |
---|
39 | n/a | if comments is not None: |
---|
40 | n/a | self.assertEqual(tl.comments, comments) |
---|
41 | n/a | |
---|
42 | n/a | def _test_get_x(self, method, source, string, value, defects, |
---|
43 | n/a | remainder, comments=None): |
---|
44 | n/a | tl, rest = method(source) |
---|
45 | n/a | self._assert_results(tl, rest, string, value, defects, remainder, |
---|
46 | n/a | comments=None) |
---|
47 | n/a | return tl |
---|
48 | n/a | |
---|
49 | n/a | def _test_parse_x(self, method, input, string, value, defects, |
---|
50 | n/a | comments=None): |
---|
51 | n/a | tl = method(input) |
---|
52 | n/a | self._assert_results(tl, '', string, value, defects, '', comments) |
---|
53 | n/a | return tl |
---|
54 | n/a | |
---|
55 | n/a | |
---|
56 | n/a | class TestParser(TestParserMixin, TestEmailBase): |
---|
57 | n/a | |
---|
58 | n/a | # _wsp_splitter |
---|
59 | n/a | |
---|
60 | n/a | rfc_printable_ascii = bytes(range(33, 127)).decode('ascii') |
---|
61 | n/a | rfc_atext_chars = (string.ascii_letters + string.digits + |
---|
62 | n/a | "!#$%&\'*+-/=?^_`{}|~") |
---|
63 | n/a | rfc_dtext_chars = rfc_printable_ascii.translate(str.maketrans('','',r'\[]')) |
---|
64 | n/a | |
---|
65 | n/a | def test__wsp_splitter_one_word(self): |
---|
66 | n/a | self.assertEqual(parser._wsp_splitter('foo', 1), ['foo']) |
---|
67 | n/a | |
---|
68 | n/a | def test__wsp_splitter_two_words(self): |
---|
69 | n/a | self.assertEqual(parser._wsp_splitter('foo def', 1), |
---|
70 | n/a | ['foo', ' ', 'def']) |
---|
71 | n/a | |
---|
72 | n/a | def test__wsp_splitter_ws_runs(self): |
---|
73 | n/a | self.assertEqual(parser._wsp_splitter('foo \t def jik', 1), |
---|
74 | n/a | ['foo', ' \t ', 'def jik']) |
---|
75 | n/a | |
---|
76 | n/a | |
---|
77 | n/a | # get_fws |
---|
78 | n/a | |
---|
79 | n/a | def test_get_fws_only(self): |
---|
80 | n/a | fws = self._test_get_x(parser.get_fws, ' \t ', ' \t ', ' ', [], '') |
---|
81 | n/a | self.assertEqual(fws.token_type, 'fws') |
---|
82 | n/a | |
---|
83 | n/a | def test_get_fws_space(self): |
---|
84 | n/a | self._test_get_x(parser.get_fws, ' foo', ' ', ' ', [], 'foo') |
---|
85 | n/a | |
---|
86 | n/a | def test_get_fws_ws_run(self): |
---|
87 | n/a | self._test_get_x(parser.get_fws, ' \t foo ', ' \t ', ' ', [], 'foo ') |
---|
88 | n/a | |
---|
89 | n/a | # get_encoded_word |
---|
90 | n/a | |
---|
91 | n/a | def test_get_encoded_word_missing_start_raises(self): |
---|
92 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
93 | n/a | parser.get_encoded_word('abc') |
---|
94 | n/a | |
---|
95 | n/a | def test_get_encoded_word_missing_end_raises(self): |
---|
96 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
97 | n/a | parser.get_encoded_word('=?abc') |
---|
98 | n/a | |
---|
99 | n/a | def test_get_encoded_word_missing_middle_raises(self): |
---|
100 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
101 | n/a | parser.get_encoded_word('=?abc?=') |
---|
102 | n/a | |
---|
103 | n/a | def test_get_encoded_word_valid_ew(self): |
---|
104 | n/a | self._test_get_x(parser.get_encoded_word, |
---|
105 | n/a | '=?us-ascii?q?this_is_a_test?= bird', |
---|
106 | n/a | 'this is a test', |
---|
107 | n/a | 'this is a test', |
---|
108 | n/a | [], |
---|
109 | n/a | ' bird') |
---|
110 | n/a | |
---|
111 | n/a | def test_get_encoded_word_internal_spaces(self): |
---|
112 | n/a | self._test_get_x(parser.get_encoded_word, |
---|
113 | n/a | '=?us-ascii?q?this is a test?= bird', |
---|
114 | n/a | 'this is a test', |
---|
115 | n/a | 'this is a test', |
---|
116 | n/a | [errors.InvalidHeaderDefect], |
---|
117 | n/a | ' bird') |
---|
118 | n/a | |
---|
119 | n/a | def test_get_encoded_word_gets_first(self): |
---|
120 | n/a | self._test_get_x(parser.get_encoded_word, |
---|
121 | n/a | '=?us-ascii?q?first?= =?utf-8?q?second?=', |
---|
122 | n/a | 'first', |
---|
123 | n/a | 'first', |
---|
124 | n/a | [], |
---|
125 | n/a | ' =?utf-8?q?second?=') |
---|
126 | n/a | |
---|
127 | n/a | def test_get_encoded_word_gets_first_even_if_no_space(self): |
---|
128 | n/a | self._test_get_x(parser.get_encoded_word, |
---|
129 | n/a | '=?us-ascii?q?first?==?utf-8?q?second?=', |
---|
130 | n/a | 'first', |
---|
131 | n/a | 'first', |
---|
132 | n/a | [], |
---|
133 | n/a | '=?utf-8?q?second?=') |
---|
134 | n/a | |
---|
135 | n/a | def test_get_encoded_word_sets_extra_attributes(self): |
---|
136 | n/a | ew = self._test_get_x(parser.get_encoded_word, |
---|
137 | n/a | '=?us-ascii*jive?q?first_second?=', |
---|
138 | n/a | 'first second', |
---|
139 | n/a | 'first second', |
---|
140 | n/a | [], |
---|
141 | n/a | '') |
---|
142 | n/a | self.assertEqual(ew.encoded, '=?us-ascii*jive?q?first_second?=') |
---|
143 | n/a | self.assertEqual(ew.charset, 'us-ascii') |
---|
144 | n/a | self.assertEqual(ew.lang, 'jive') |
---|
145 | n/a | |
---|
146 | n/a | def test_get_encoded_word_lang_default_is_blank(self): |
---|
147 | n/a | ew = self._test_get_x(parser.get_encoded_word, |
---|
148 | n/a | '=?us-ascii?q?first_second?=', |
---|
149 | n/a | 'first second', |
---|
150 | n/a | 'first second', |
---|
151 | n/a | [], |
---|
152 | n/a | '') |
---|
153 | n/a | self.assertEqual(ew.encoded, '=?us-ascii?q?first_second?=') |
---|
154 | n/a | self.assertEqual(ew.charset, 'us-ascii') |
---|
155 | n/a | self.assertEqual(ew.lang, '') |
---|
156 | n/a | |
---|
157 | n/a | def test_get_encoded_word_non_printable_defect(self): |
---|
158 | n/a | self._test_get_x(parser.get_encoded_word, |
---|
159 | n/a | '=?us-ascii?q?first\x02second?=', |
---|
160 | n/a | 'first\x02second', |
---|
161 | n/a | 'first\x02second', |
---|
162 | n/a | [errors.NonPrintableDefect], |
---|
163 | n/a | '') |
---|
164 | n/a | |
---|
165 | n/a | def test_get_encoded_word_leading_internal_space(self): |
---|
166 | n/a | self._test_get_x(parser.get_encoded_word, |
---|
167 | n/a | '=?us-ascii?q?=20foo?=', |
---|
168 | n/a | ' foo', |
---|
169 | n/a | ' foo', |
---|
170 | n/a | [], |
---|
171 | n/a | '') |
---|
172 | n/a | |
---|
173 | n/a | def test_get_encoded_word_quopri_utf_escape_follows_cte(self): |
---|
174 | n/a | # Issue 18044 |
---|
175 | n/a | self._test_get_x(parser.get_encoded_word, |
---|
176 | n/a | '=?utf-8?q?=C3=89ric?=', |
---|
177 | n/a | 'Ãric', |
---|
178 | n/a | 'Ãric', |
---|
179 | n/a | [], |
---|
180 | n/a | '') |
---|
181 | n/a | |
---|
182 | n/a | # get_unstructured |
---|
183 | n/a | |
---|
184 | n/a | def _get_unst(self, value): |
---|
185 | n/a | token = parser.get_unstructured(value) |
---|
186 | n/a | return token, '' |
---|
187 | n/a | |
---|
188 | n/a | def test_get_unstructured_null(self): |
---|
189 | n/a | self._test_get_x(self._get_unst, '', '', '', [], '') |
---|
190 | n/a | |
---|
191 | n/a | def test_get_unstructured_one_word(self): |
---|
192 | n/a | self._test_get_x(self._get_unst, 'foo', 'foo', 'foo', [], '') |
---|
193 | n/a | |
---|
194 | n/a | def test_get_unstructured_normal_phrase(self): |
---|
195 | n/a | self._test_get_x(self._get_unst, 'foo bar bird', |
---|
196 | n/a | 'foo bar bird', |
---|
197 | n/a | 'foo bar bird', |
---|
198 | n/a | [], |
---|
199 | n/a | '') |
---|
200 | n/a | |
---|
201 | n/a | def test_get_unstructured_normal_phrase_with_whitespace(self): |
---|
202 | n/a | self._test_get_x(self._get_unst, 'foo \t bar bird', |
---|
203 | n/a | 'foo \t bar bird', |
---|
204 | n/a | 'foo bar bird', |
---|
205 | n/a | [], |
---|
206 | n/a | '') |
---|
207 | n/a | |
---|
208 | n/a | def test_get_unstructured_leading_whitespace(self): |
---|
209 | n/a | self._test_get_x(self._get_unst, ' foo bar', |
---|
210 | n/a | ' foo bar', |
---|
211 | n/a | ' foo bar', |
---|
212 | n/a | [], |
---|
213 | n/a | '') |
---|
214 | n/a | |
---|
215 | n/a | def test_get_unstructured_trailing_whitespace(self): |
---|
216 | n/a | self._test_get_x(self._get_unst, 'foo bar ', |
---|
217 | n/a | 'foo bar ', |
---|
218 | n/a | 'foo bar ', |
---|
219 | n/a | [], |
---|
220 | n/a | '') |
---|
221 | n/a | |
---|
222 | n/a | def test_get_unstructured_leading_and_trailing_whitespace(self): |
---|
223 | n/a | self._test_get_x(self._get_unst, ' foo bar ', |
---|
224 | n/a | ' foo bar ', |
---|
225 | n/a | ' foo bar ', |
---|
226 | n/a | [], |
---|
227 | n/a | '') |
---|
228 | n/a | |
---|
229 | n/a | def test_get_unstructured_one_valid_ew_no_ws(self): |
---|
230 | n/a | self._test_get_x(self._get_unst, '=?us-ascii?q?bar?=', |
---|
231 | n/a | 'bar', |
---|
232 | n/a | 'bar', |
---|
233 | n/a | [], |
---|
234 | n/a | '') |
---|
235 | n/a | |
---|
236 | n/a | def test_get_unstructured_one_ew_trailing_ws(self): |
---|
237 | n/a | self._test_get_x(self._get_unst, '=?us-ascii?q?bar?= ', |
---|
238 | n/a | 'bar ', |
---|
239 | n/a | 'bar ', |
---|
240 | n/a | [], |
---|
241 | n/a | '') |
---|
242 | n/a | |
---|
243 | n/a | def test_get_unstructured_one_valid_ew_trailing_text(self): |
---|
244 | n/a | self._test_get_x(self._get_unst, '=?us-ascii?q?bar?= bird', |
---|
245 | n/a | 'bar bird', |
---|
246 | n/a | 'bar bird', |
---|
247 | n/a | [], |
---|
248 | n/a | '') |
---|
249 | n/a | |
---|
250 | n/a | def test_get_unstructured_phrase_with_ew_in_middle_of_text(self): |
---|
251 | n/a | self._test_get_x(self._get_unst, 'foo =?us-ascii?q?bar?= bird', |
---|
252 | n/a | 'foo bar bird', |
---|
253 | n/a | 'foo bar bird', |
---|
254 | n/a | [], |
---|
255 | n/a | '') |
---|
256 | n/a | |
---|
257 | n/a | def test_get_unstructured_phrase_with_two_ew(self): |
---|
258 | n/a | self._test_get_x(self._get_unst, |
---|
259 | n/a | 'foo =?us-ascii?q?bar?= =?us-ascii?q?bird?=', |
---|
260 | n/a | 'foo barbird', |
---|
261 | n/a | 'foo barbird', |
---|
262 | n/a | [], |
---|
263 | n/a | '') |
---|
264 | n/a | |
---|
265 | n/a | def test_get_unstructured_phrase_with_two_ew_trailing_ws(self): |
---|
266 | n/a | self._test_get_x(self._get_unst, |
---|
267 | n/a | 'foo =?us-ascii?q?bar?= =?us-ascii?q?bird?= ', |
---|
268 | n/a | 'foo barbird ', |
---|
269 | n/a | 'foo barbird ', |
---|
270 | n/a | [], |
---|
271 | n/a | '') |
---|
272 | n/a | |
---|
273 | n/a | def test_get_unstructured_phrase_with_ew_with_leading_ws(self): |
---|
274 | n/a | self._test_get_x(self._get_unst, |
---|
275 | n/a | ' =?us-ascii?q?bar?=', |
---|
276 | n/a | ' bar', |
---|
277 | n/a | ' bar', |
---|
278 | n/a | [], |
---|
279 | n/a | '') |
---|
280 | n/a | |
---|
281 | n/a | def test_get_unstructured_phrase_with_two_ew_extra_ws(self): |
---|
282 | n/a | self._test_get_x(self._get_unst, |
---|
283 | n/a | 'foo =?us-ascii?q?bar?= \t =?us-ascii?q?bird?=', |
---|
284 | n/a | 'foo barbird', |
---|
285 | n/a | 'foo barbird', |
---|
286 | n/a | [], |
---|
287 | n/a | '') |
---|
288 | n/a | |
---|
289 | n/a | def test_get_unstructured_two_ew_extra_ws_trailing_text(self): |
---|
290 | n/a | self._test_get_x(self._get_unst, |
---|
291 | n/a | '=?us-ascii?q?test?= =?us-ascii?q?foo?= val', |
---|
292 | n/a | 'testfoo val', |
---|
293 | n/a | 'testfoo val', |
---|
294 | n/a | [], |
---|
295 | n/a | '') |
---|
296 | n/a | |
---|
297 | n/a | def test_get_unstructured_ew_with_internal_ws(self): |
---|
298 | n/a | self._test_get_x(self._get_unst, |
---|
299 | n/a | '=?iso-8859-1?q?hello=20world?=', |
---|
300 | n/a | 'hello world', |
---|
301 | n/a | 'hello world', |
---|
302 | n/a | [], |
---|
303 | n/a | '') |
---|
304 | n/a | |
---|
305 | n/a | def test_get_unstructured_ew_with_internal_leading_ws(self): |
---|
306 | n/a | self._test_get_x(self._get_unst, |
---|
307 | n/a | ' =?us-ascii?q?=20test?= =?us-ascii?q?=20foo?= val', |
---|
308 | n/a | ' test foo val', |
---|
309 | n/a | ' test foo val', |
---|
310 | n/a | [], |
---|
311 | n/a | '') |
---|
312 | n/a | |
---|
313 | n/a | def test_get_unstructured_invaild_ew(self): |
---|
314 | n/a | self._test_get_x(self._get_unst, |
---|
315 | n/a | '=?test val', |
---|
316 | n/a | '=?test val', |
---|
317 | n/a | '=?test val', |
---|
318 | n/a | [], |
---|
319 | n/a | '') |
---|
320 | n/a | |
---|
321 | n/a | def test_get_unstructured_undecodable_bytes(self): |
---|
322 | n/a | self._test_get_x(self._get_unst, |
---|
323 | n/a | b'test \xACfoo val'.decode('ascii', 'surrogateescape'), |
---|
324 | n/a | 'test \uDCACfoo val', |
---|
325 | n/a | 'test \uDCACfoo val', |
---|
326 | n/a | [errors.UndecodableBytesDefect], |
---|
327 | n/a | '') |
---|
328 | n/a | |
---|
329 | n/a | def test_get_unstructured_undecodable_bytes_in_EW(self): |
---|
330 | n/a | self._test_get_x(self._get_unst, |
---|
331 | n/a | (b'=?us-ascii?q?=20test?= =?us-ascii?q?=20\xACfoo?=' |
---|
332 | n/a | b' val').decode('ascii', 'surrogateescape'), |
---|
333 | n/a | ' test \uDCACfoo val', |
---|
334 | n/a | ' test \uDCACfoo val', |
---|
335 | n/a | [errors.UndecodableBytesDefect]*2, |
---|
336 | n/a | '') |
---|
337 | n/a | |
---|
338 | n/a | def test_get_unstructured_missing_base64_padding(self): |
---|
339 | n/a | self._test_get_x(self._get_unst, |
---|
340 | n/a | '=?utf-8?b?dmk?=', |
---|
341 | n/a | 'vi', |
---|
342 | n/a | 'vi', |
---|
343 | n/a | [errors.InvalidBase64PaddingDefect], |
---|
344 | n/a | '') |
---|
345 | n/a | |
---|
346 | n/a | def test_get_unstructured_invalid_base64_character(self): |
---|
347 | n/a | self._test_get_x(self._get_unst, |
---|
348 | n/a | '=?utf-8?b?dm\x01k===?=', |
---|
349 | n/a | 'vi', |
---|
350 | n/a | 'vi', |
---|
351 | n/a | [errors.InvalidBase64CharactersDefect], |
---|
352 | n/a | '') |
---|
353 | n/a | |
---|
354 | n/a | def test_get_unstructured_invalid_base64_character_and_bad_padding(self): |
---|
355 | n/a | self._test_get_x(self._get_unst, |
---|
356 | n/a | '=?utf-8?b?dm\x01k?=', |
---|
357 | n/a | 'vi', |
---|
358 | n/a | 'vi', |
---|
359 | n/a | [errors.InvalidBase64CharactersDefect, |
---|
360 | n/a | errors.InvalidBase64PaddingDefect], |
---|
361 | n/a | '') |
---|
362 | n/a | |
---|
363 | n/a | def test_get_unstructured_no_whitespace_between_ews(self): |
---|
364 | n/a | self._test_get_x(self._get_unst, |
---|
365 | n/a | '=?utf-8?q?foo?==?utf-8?q?bar?=', |
---|
366 | n/a | 'foobar', |
---|
367 | n/a | 'foobar', |
---|
368 | n/a | [errors.InvalidHeaderDefect], |
---|
369 | n/a | '') |
---|
370 | n/a | |
---|
371 | n/a | # get_qp_ctext |
---|
372 | n/a | |
---|
373 | n/a | def test_get_qp_ctext_only(self): |
---|
374 | n/a | ptext = self._test_get_x(parser.get_qp_ctext, |
---|
375 | n/a | 'foobar', 'foobar', ' ', [], '') |
---|
376 | n/a | self.assertEqual(ptext.token_type, 'ptext') |
---|
377 | n/a | |
---|
378 | n/a | def test_get_qp_ctext_all_printables(self): |
---|
379 | n/a | with_qp = self.rfc_printable_ascii.replace('\\', '\\\\') |
---|
380 | n/a | with_qp = with_qp. replace('(', r'\(') |
---|
381 | n/a | with_qp = with_qp.replace(')', r'\)') |
---|
382 | n/a | ptext = self._test_get_x(parser.get_qp_ctext, |
---|
383 | n/a | with_qp, self.rfc_printable_ascii, ' ', [], '') |
---|
384 | n/a | |
---|
385 | n/a | def test_get_qp_ctext_two_words_gets_first(self): |
---|
386 | n/a | self._test_get_x(parser.get_qp_ctext, |
---|
387 | n/a | 'foo de', 'foo', ' ', [], ' de') |
---|
388 | n/a | |
---|
389 | n/a | def test_get_qp_ctext_following_wsp_preserved(self): |
---|
390 | n/a | self._test_get_x(parser.get_qp_ctext, |
---|
391 | n/a | 'foo \t\tde', 'foo', ' ', [], ' \t\tde') |
---|
392 | n/a | |
---|
393 | n/a | def test_get_qp_ctext_up_to_close_paren_only(self): |
---|
394 | n/a | self._test_get_x(parser.get_qp_ctext, |
---|
395 | n/a | 'foo)', 'foo', ' ', [], ')') |
---|
396 | n/a | |
---|
397 | n/a | def test_get_qp_ctext_wsp_before_close_paren_preserved(self): |
---|
398 | n/a | self._test_get_x(parser.get_qp_ctext, |
---|
399 | n/a | 'foo )', 'foo', ' ', [], ' )') |
---|
400 | n/a | |
---|
401 | n/a | def test_get_qp_ctext_close_paren_mid_word(self): |
---|
402 | n/a | self._test_get_x(parser.get_qp_ctext, |
---|
403 | n/a | 'foo)bar', 'foo', ' ', [], ')bar') |
---|
404 | n/a | |
---|
405 | n/a | def test_get_qp_ctext_up_to_open_paren_only(self): |
---|
406 | n/a | self._test_get_x(parser.get_qp_ctext, |
---|
407 | n/a | 'foo(', 'foo', ' ', [], '(') |
---|
408 | n/a | |
---|
409 | n/a | def test_get_qp_ctext_wsp_before_open_paren_preserved(self): |
---|
410 | n/a | self._test_get_x(parser.get_qp_ctext, |
---|
411 | n/a | 'foo (', 'foo', ' ', [], ' (') |
---|
412 | n/a | |
---|
413 | n/a | def test_get_qp_ctext_open_paren_mid_word(self): |
---|
414 | n/a | self._test_get_x(parser.get_qp_ctext, |
---|
415 | n/a | 'foo(bar', 'foo', ' ', [], '(bar') |
---|
416 | n/a | |
---|
417 | n/a | def test_get_qp_ctext_non_printables(self): |
---|
418 | n/a | ptext = self._test_get_x(parser.get_qp_ctext, |
---|
419 | n/a | 'foo\x00bar)', 'foo\x00bar', ' ', |
---|
420 | n/a | [errors.NonPrintableDefect], ')') |
---|
421 | n/a | self.assertEqual(ptext.defects[0].non_printables[0], '\x00') |
---|
422 | n/a | |
---|
423 | n/a | # get_qcontent |
---|
424 | n/a | |
---|
425 | n/a | def test_get_qcontent_only(self): |
---|
426 | n/a | ptext = self._test_get_x(parser.get_qcontent, |
---|
427 | n/a | 'foobar', 'foobar', 'foobar', [], '') |
---|
428 | n/a | self.assertEqual(ptext.token_type, 'ptext') |
---|
429 | n/a | |
---|
430 | n/a | def test_get_qcontent_all_printables(self): |
---|
431 | n/a | with_qp = self.rfc_printable_ascii.replace('\\', '\\\\') |
---|
432 | n/a | with_qp = with_qp. replace('"', r'\"') |
---|
433 | n/a | ptext = self._test_get_x(parser.get_qcontent, with_qp, |
---|
434 | n/a | self.rfc_printable_ascii, |
---|
435 | n/a | self.rfc_printable_ascii, [], '') |
---|
436 | n/a | |
---|
437 | n/a | def test_get_qcontent_two_words_gets_first(self): |
---|
438 | n/a | self._test_get_x(parser.get_qcontent, |
---|
439 | n/a | 'foo de', 'foo', 'foo', [], ' de') |
---|
440 | n/a | |
---|
441 | n/a | def test_get_qcontent_following_wsp_preserved(self): |
---|
442 | n/a | self._test_get_x(parser.get_qcontent, |
---|
443 | n/a | 'foo \t\tde', 'foo', 'foo', [], ' \t\tde') |
---|
444 | n/a | |
---|
445 | n/a | def test_get_qcontent_up_to_dquote_only(self): |
---|
446 | n/a | self._test_get_x(parser.get_qcontent, |
---|
447 | n/a | 'foo"', 'foo', 'foo', [], '"') |
---|
448 | n/a | |
---|
449 | n/a | def test_get_qcontent_wsp_before_close_paren_preserved(self): |
---|
450 | n/a | self._test_get_x(parser.get_qcontent, |
---|
451 | n/a | 'foo "', 'foo', 'foo', [], ' "') |
---|
452 | n/a | |
---|
453 | n/a | def test_get_qcontent_close_paren_mid_word(self): |
---|
454 | n/a | self._test_get_x(parser.get_qcontent, |
---|
455 | n/a | 'foo"bar', 'foo', 'foo', [], '"bar') |
---|
456 | n/a | |
---|
457 | n/a | def test_get_qcontent_non_printables(self): |
---|
458 | n/a | ptext = self._test_get_x(parser.get_qcontent, |
---|
459 | n/a | 'foo\x00fg"', 'foo\x00fg', 'foo\x00fg', |
---|
460 | n/a | [errors.NonPrintableDefect], '"') |
---|
461 | n/a | self.assertEqual(ptext.defects[0].non_printables[0], '\x00') |
---|
462 | n/a | |
---|
463 | n/a | # get_atext |
---|
464 | n/a | |
---|
465 | n/a | def test_get_atext_only(self): |
---|
466 | n/a | atext = self._test_get_x(parser.get_atext, |
---|
467 | n/a | 'foobar', 'foobar', 'foobar', [], '') |
---|
468 | n/a | self.assertEqual(atext.token_type, 'atext') |
---|
469 | n/a | |
---|
470 | n/a | def test_get_atext_all_atext(self): |
---|
471 | n/a | atext = self._test_get_x(parser.get_atext, self.rfc_atext_chars, |
---|
472 | n/a | self.rfc_atext_chars, |
---|
473 | n/a | self.rfc_atext_chars, [], '') |
---|
474 | n/a | |
---|
475 | n/a | def test_get_atext_two_words_gets_first(self): |
---|
476 | n/a | self._test_get_x(parser.get_atext, |
---|
477 | n/a | 'foo bar', 'foo', 'foo', [], ' bar') |
---|
478 | n/a | |
---|
479 | n/a | def test_get_atext_following_wsp_preserved(self): |
---|
480 | n/a | self._test_get_x(parser.get_atext, |
---|
481 | n/a | 'foo \t\tbar', 'foo', 'foo', [], ' \t\tbar') |
---|
482 | n/a | |
---|
483 | n/a | def test_get_atext_up_to_special(self): |
---|
484 | n/a | self._test_get_x(parser.get_atext, |
---|
485 | n/a | 'foo@bar', 'foo', 'foo', [], '@bar') |
---|
486 | n/a | |
---|
487 | n/a | def test_get_atext_non_printables(self): |
---|
488 | n/a | atext = self._test_get_x(parser.get_atext, |
---|
489 | n/a | 'foo\x00bar(', 'foo\x00bar', 'foo\x00bar', |
---|
490 | n/a | [errors.NonPrintableDefect], '(') |
---|
491 | n/a | self.assertEqual(atext.defects[0].non_printables[0], '\x00') |
---|
492 | n/a | |
---|
493 | n/a | # get_bare_quoted_string |
---|
494 | n/a | |
---|
495 | n/a | def test_get_bare_quoted_string_only(self): |
---|
496 | n/a | bqs = self._test_get_x(parser.get_bare_quoted_string, |
---|
497 | n/a | '"foo"', '"foo"', 'foo', [], '') |
---|
498 | n/a | self.assertEqual(bqs.token_type, 'bare-quoted-string') |
---|
499 | n/a | |
---|
500 | n/a | def test_get_bare_quoted_string_must_start_with_dquote(self): |
---|
501 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
502 | n/a | parser.get_bare_quoted_string('foo"') |
---|
503 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
504 | n/a | parser.get_bare_quoted_string(' "foo"') |
---|
505 | n/a | |
---|
506 | n/a | def test_get_bare_quoted_string_following_wsp_preserved(self): |
---|
507 | n/a | self._test_get_x(parser.get_bare_quoted_string, |
---|
508 | n/a | '"foo"\t bar', '"foo"', 'foo', [], '\t bar') |
---|
509 | n/a | |
---|
510 | n/a | def test_get_bare_quoted_string_multiple_words(self): |
---|
511 | n/a | self._test_get_x(parser.get_bare_quoted_string, |
---|
512 | n/a | '"foo bar moo"', '"foo bar moo"', 'foo bar moo', [], '') |
---|
513 | n/a | |
---|
514 | n/a | def test_get_bare_quoted_string_multiple_words_wsp_preserved(self): |
---|
515 | n/a | self._test_get_x(parser.get_bare_quoted_string, |
---|
516 | n/a | '" foo moo\t"', '" foo moo\t"', ' foo moo\t', [], '') |
---|
517 | n/a | |
---|
518 | n/a | def test_get_bare_quoted_string_end_dquote_mid_word(self): |
---|
519 | n/a | self._test_get_x(parser.get_bare_quoted_string, |
---|
520 | n/a | '"foo"bar', '"foo"', 'foo', [], 'bar') |
---|
521 | n/a | |
---|
522 | n/a | def test_get_bare_quoted_string_quoted_dquote(self): |
---|
523 | n/a | self._test_get_x(parser.get_bare_quoted_string, |
---|
524 | n/a | r'"foo\"in"a', r'"foo\"in"', 'foo"in', [], 'a') |
---|
525 | n/a | |
---|
526 | n/a | def test_get_bare_quoted_string_non_printables(self): |
---|
527 | n/a | self._test_get_x(parser.get_bare_quoted_string, |
---|
528 | n/a | '"a\x01a"', '"a\x01a"', 'a\x01a', |
---|
529 | n/a | [errors.NonPrintableDefect], '') |
---|
530 | n/a | |
---|
531 | n/a | def test_get_bare_quoted_string_no_end_dquote(self): |
---|
532 | n/a | self._test_get_x(parser.get_bare_quoted_string, |
---|
533 | n/a | '"foo', '"foo"', 'foo', |
---|
534 | n/a | [errors.InvalidHeaderDefect], '') |
---|
535 | n/a | self._test_get_x(parser.get_bare_quoted_string, |
---|
536 | n/a | '"foo ', '"foo "', 'foo ', |
---|
537 | n/a | [errors.InvalidHeaderDefect], '') |
---|
538 | n/a | |
---|
539 | n/a | def test_get_bare_quoted_string_empty_quotes(self): |
---|
540 | n/a | self._test_get_x(parser.get_bare_quoted_string, |
---|
541 | n/a | '""', '""', '', [], '') |
---|
542 | n/a | |
---|
543 | n/a | # Issue 16983: apply postel's law to some bad encoding. |
---|
544 | n/a | def test_encoded_word_inside_quotes(self): |
---|
545 | n/a | self._test_get_x(parser.get_bare_quoted_string, |
---|
546 | n/a | '"=?utf-8?Q?not_really_valid?="', |
---|
547 | n/a | '"not really valid"', |
---|
548 | n/a | 'not really valid', |
---|
549 | n/a | [errors.InvalidHeaderDefect], |
---|
550 | n/a | '') |
---|
551 | n/a | |
---|
552 | n/a | # get_comment |
---|
553 | n/a | |
---|
554 | n/a | def test_get_comment_only(self): |
---|
555 | n/a | comment = self._test_get_x(parser.get_comment, |
---|
556 | n/a | '(comment)', '(comment)', ' ', [], '', ['comment']) |
---|
557 | n/a | self.assertEqual(comment.token_type, 'comment') |
---|
558 | n/a | |
---|
559 | n/a | def test_get_comment_must_start_with_paren(self): |
---|
560 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
561 | n/a | parser.get_comment('foo"') |
---|
562 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
563 | n/a | parser.get_comment(' (foo"') |
---|
564 | n/a | |
---|
565 | n/a | def test_get_comment_following_wsp_preserved(self): |
---|
566 | n/a | self._test_get_x(parser.get_comment, |
---|
567 | n/a | '(comment) \t', '(comment)', ' ', [], ' \t', ['comment']) |
---|
568 | n/a | |
---|
569 | n/a | def test_get_comment_multiple_words(self): |
---|
570 | n/a | self._test_get_x(parser.get_comment, |
---|
571 | n/a | '(foo bar) \t', '(foo bar)', ' ', [], ' \t', ['foo bar']) |
---|
572 | n/a | |
---|
573 | n/a | def test_get_comment_multiple_words_wsp_preserved(self): |
---|
574 | n/a | self._test_get_x(parser.get_comment, |
---|
575 | n/a | '( foo bar\t ) \t', '( foo bar\t )', ' ', [], ' \t', |
---|
576 | n/a | [' foo bar\t ']) |
---|
577 | n/a | |
---|
578 | n/a | def test_get_comment_end_paren_mid_word(self): |
---|
579 | n/a | self._test_get_x(parser.get_comment, |
---|
580 | n/a | '(foo)bar', '(foo)', ' ', [], 'bar', ['foo']) |
---|
581 | n/a | |
---|
582 | n/a | def test_get_comment_quoted_parens(self): |
---|
583 | n/a | self._test_get_x(parser.get_comment, |
---|
584 | n/a | r'(foo\) \(\)bar)', r'(foo\) \(\)bar)', ' ', [], '', ['foo) ()bar']) |
---|
585 | n/a | |
---|
586 | n/a | def test_get_comment_non_printable(self): |
---|
587 | n/a | self._test_get_x(parser.get_comment, |
---|
588 | n/a | '(foo\x7Fbar)', '(foo\x7Fbar)', ' ', |
---|
589 | n/a | [errors.NonPrintableDefect], '', ['foo\x7Fbar']) |
---|
590 | n/a | |
---|
591 | n/a | def test_get_comment_no_end_paren(self): |
---|
592 | n/a | self._test_get_x(parser.get_comment, |
---|
593 | n/a | '(foo bar', '(foo bar)', ' ', |
---|
594 | n/a | [errors.InvalidHeaderDefect], '', ['foo bar']) |
---|
595 | n/a | self._test_get_x(parser.get_comment, |
---|
596 | n/a | '(foo bar ', '(foo bar )', ' ', |
---|
597 | n/a | [errors.InvalidHeaderDefect], '', ['foo bar ']) |
---|
598 | n/a | |
---|
599 | n/a | def test_get_comment_nested_comment(self): |
---|
600 | n/a | comment = self._test_get_x(parser.get_comment, |
---|
601 | n/a | '(foo(bar))', '(foo(bar))', ' ', [], '', ['foo(bar)']) |
---|
602 | n/a | self.assertEqual(comment[1].content, 'bar') |
---|
603 | n/a | |
---|
604 | n/a | def test_get_comment_nested_comment_wsp(self): |
---|
605 | n/a | comment = self._test_get_x(parser.get_comment, |
---|
606 | n/a | '(foo ( bar ) )', '(foo ( bar ) )', ' ', [], '', ['foo ( bar ) ']) |
---|
607 | n/a | self.assertEqual(comment[2].content, ' bar ') |
---|
608 | n/a | |
---|
609 | n/a | def test_get_comment_empty_comment(self): |
---|
610 | n/a | self._test_get_x(parser.get_comment, |
---|
611 | n/a | '()', '()', ' ', [], '', ['']) |
---|
612 | n/a | |
---|
613 | n/a | def test_get_comment_multiple_nesting(self): |
---|
614 | n/a | comment = self._test_get_x(parser.get_comment, |
---|
615 | n/a | '(((((foo)))))', '(((((foo)))))', ' ', [], '', ['((((foo))))']) |
---|
616 | n/a | for i in range(4, 0, -1): |
---|
617 | n/a | self.assertEqual(comment[0].content, '('*(i-1)+'foo'+')'*(i-1)) |
---|
618 | n/a | comment = comment[0] |
---|
619 | n/a | self.assertEqual(comment.content, 'foo') |
---|
620 | n/a | |
---|
621 | n/a | def test_get_comment_missing_end_of_nesting(self): |
---|
622 | n/a | self._test_get_x(parser.get_comment, |
---|
623 | n/a | '(((((foo)))', '(((((foo)))))', ' ', |
---|
624 | n/a | [errors.InvalidHeaderDefect]*2, '', ['((((foo))))']) |
---|
625 | n/a | |
---|
626 | n/a | def test_get_comment_qs_in_nested_comment(self): |
---|
627 | n/a | comment = self._test_get_x(parser.get_comment, |
---|
628 | n/a | r'(foo (b\)))', r'(foo (b\)))', ' ', [], '', [r'foo (b\))']) |
---|
629 | n/a | self.assertEqual(comment[2].content, 'b)') |
---|
630 | n/a | |
---|
631 | n/a | # get_cfws |
---|
632 | n/a | |
---|
633 | n/a | def test_get_cfws_only_ws(self): |
---|
634 | n/a | cfws = self._test_get_x(parser.get_cfws, |
---|
635 | n/a | ' \t \t', ' \t \t', ' ', [], '', []) |
---|
636 | n/a | self.assertEqual(cfws.token_type, 'cfws') |
---|
637 | n/a | |
---|
638 | n/a | def test_get_cfws_only_comment(self): |
---|
639 | n/a | cfws = self._test_get_x(parser.get_cfws, |
---|
640 | n/a | '(foo)', '(foo)', ' ', [], '', ['foo']) |
---|
641 | n/a | self.assertEqual(cfws[0].content, 'foo') |
---|
642 | n/a | |
---|
643 | n/a | def test_get_cfws_only_mixed(self): |
---|
644 | n/a | cfws = self._test_get_x(parser.get_cfws, |
---|
645 | n/a | ' (foo ) ( bar) ', ' (foo ) ( bar) ', ' ', [], '', |
---|
646 | n/a | ['foo ', ' bar']) |
---|
647 | n/a | self.assertEqual(cfws[1].content, 'foo ') |
---|
648 | n/a | self.assertEqual(cfws[3].content, ' bar') |
---|
649 | n/a | |
---|
650 | n/a | def test_get_cfws_ends_at_non_leader(self): |
---|
651 | n/a | cfws = self._test_get_x(parser.get_cfws, |
---|
652 | n/a | '(foo) bar', '(foo) ', ' ', [], 'bar', ['foo']) |
---|
653 | n/a | self.assertEqual(cfws[0].content, 'foo') |
---|
654 | n/a | |
---|
655 | n/a | def test_get_cfws_ends_at_non_printable(self): |
---|
656 | n/a | cfws = self._test_get_x(parser.get_cfws, |
---|
657 | n/a | '(foo) \x07', '(foo) ', ' ', [], '\x07', ['foo']) |
---|
658 | n/a | self.assertEqual(cfws[0].content, 'foo') |
---|
659 | n/a | |
---|
660 | n/a | def test_get_cfws_non_printable_in_comment(self): |
---|
661 | n/a | cfws = self._test_get_x(parser.get_cfws, |
---|
662 | n/a | '(foo \x07) "test"', '(foo \x07) ', ' ', |
---|
663 | n/a | [errors.NonPrintableDefect], '"test"', ['foo \x07']) |
---|
664 | n/a | self.assertEqual(cfws[0].content, 'foo \x07') |
---|
665 | n/a | |
---|
666 | n/a | def test_get_cfws_header_ends_in_comment(self): |
---|
667 | n/a | cfws = self._test_get_x(parser.get_cfws, |
---|
668 | n/a | ' (foo ', ' (foo )', ' ', |
---|
669 | n/a | [errors.InvalidHeaderDefect], '', ['foo ']) |
---|
670 | n/a | self.assertEqual(cfws[1].content, 'foo ') |
---|
671 | n/a | |
---|
672 | n/a | def test_get_cfws_multiple_nested_comments(self): |
---|
673 | n/a | cfws = self._test_get_x(parser.get_cfws, |
---|
674 | n/a | '(foo (bar)) ((a)(a))', '(foo (bar)) ((a)(a))', ' ', [], |
---|
675 | n/a | '', ['foo (bar)', '(a)(a)']) |
---|
676 | n/a | self.assertEqual(cfws[0].comments, ['foo (bar)']) |
---|
677 | n/a | self.assertEqual(cfws[2].comments, ['(a)(a)']) |
---|
678 | n/a | |
---|
679 | n/a | # get_quoted_string |
---|
680 | n/a | |
---|
681 | n/a | def test_get_quoted_string_only(self): |
---|
682 | n/a | qs = self._test_get_x(parser.get_quoted_string, |
---|
683 | n/a | '"bob"', '"bob"', 'bob', [], '') |
---|
684 | n/a | self.assertEqual(qs.token_type, 'quoted-string') |
---|
685 | n/a | self.assertEqual(qs.quoted_value, '"bob"') |
---|
686 | n/a | self.assertEqual(qs.content, 'bob') |
---|
687 | n/a | |
---|
688 | n/a | def test_get_quoted_string_with_wsp(self): |
---|
689 | n/a | qs = self._test_get_x(parser.get_quoted_string, |
---|
690 | n/a | '\t "bob" ', '\t "bob" ', ' bob ', [], '') |
---|
691 | n/a | self.assertEqual(qs.quoted_value, ' "bob" ') |
---|
692 | n/a | self.assertEqual(qs.content, 'bob') |
---|
693 | n/a | |
---|
694 | n/a | def test_get_quoted_string_with_comments_and_wsp(self): |
---|
695 | n/a | qs = self._test_get_x(parser.get_quoted_string, |
---|
696 | n/a | ' (foo) "bob"(bar)', ' (foo) "bob"(bar)', ' bob ', [], '') |
---|
697 | n/a | self.assertEqual(qs[0][1].content, 'foo') |
---|
698 | n/a | self.assertEqual(qs[2][0].content, 'bar') |
---|
699 | n/a | self.assertEqual(qs.content, 'bob') |
---|
700 | n/a | self.assertEqual(qs.quoted_value, ' "bob" ') |
---|
701 | n/a | |
---|
702 | n/a | def test_get_quoted_string_with_multiple_comments(self): |
---|
703 | n/a | qs = self._test_get_x(parser.get_quoted_string, |
---|
704 | n/a | ' (foo) (bar) "bob"(bird)', ' (foo) (bar) "bob"(bird)', ' bob ', |
---|
705 | n/a | [], '') |
---|
706 | n/a | self.assertEqual(qs[0].comments, ['foo', 'bar']) |
---|
707 | n/a | self.assertEqual(qs[2].comments, ['bird']) |
---|
708 | n/a | self.assertEqual(qs.content, 'bob') |
---|
709 | n/a | self.assertEqual(qs.quoted_value, ' "bob" ') |
---|
710 | n/a | |
---|
711 | n/a | def test_get_quoted_string_non_printable_in_comment(self): |
---|
712 | n/a | qs = self._test_get_x(parser.get_quoted_string, |
---|
713 | n/a | ' (\x0A) "bob"', ' (\x0A) "bob"', ' bob', |
---|
714 | n/a | [errors.NonPrintableDefect], '') |
---|
715 | n/a | self.assertEqual(qs[0].comments, ['\x0A']) |
---|
716 | n/a | self.assertEqual(qs.content, 'bob') |
---|
717 | n/a | self.assertEqual(qs.quoted_value, ' "bob"') |
---|
718 | n/a | |
---|
719 | n/a | def test_get_quoted_string_non_printable_in_qcontent(self): |
---|
720 | n/a | qs = self._test_get_x(parser.get_quoted_string, |
---|
721 | n/a | ' (a) "a\x0B"', ' (a) "a\x0B"', ' a\x0B', |
---|
722 | n/a | [errors.NonPrintableDefect], '') |
---|
723 | n/a | self.assertEqual(qs[0].comments, ['a']) |
---|
724 | n/a | self.assertEqual(qs.content, 'a\x0B') |
---|
725 | n/a | self.assertEqual(qs.quoted_value, ' "a\x0B"') |
---|
726 | n/a | |
---|
727 | n/a | def test_get_quoted_string_internal_ws(self): |
---|
728 | n/a | qs = self._test_get_x(parser.get_quoted_string, |
---|
729 | n/a | ' (a) "foo bar "', ' (a) "foo bar "', ' foo bar ', |
---|
730 | n/a | [], '') |
---|
731 | n/a | self.assertEqual(qs[0].comments, ['a']) |
---|
732 | n/a | self.assertEqual(qs.content, 'foo bar ') |
---|
733 | n/a | self.assertEqual(qs.quoted_value, ' "foo bar "') |
---|
734 | n/a | |
---|
735 | n/a | def test_get_quoted_string_header_ends_in_comment(self): |
---|
736 | n/a | qs = self._test_get_x(parser.get_quoted_string, |
---|
737 | n/a | ' (a) "bob" (a', ' (a) "bob" (a)', ' bob ', |
---|
738 | n/a | [errors.InvalidHeaderDefect], '') |
---|
739 | n/a | self.assertEqual(qs[0].comments, ['a']) |
---|
740 | n/a | self.assertEqual(qs[2].comments, ['a']) |
---|
741 | n/a | self.assertEqual(qs.content, 'bob') |
---|
742 | n/a | self.assertEqual(qs.quoted_value, ' "bob" ') |
---|
743 | n/a | |
---|
744 | n/a | def test_get_quoted_string_header_ends_in_qcontent(self): |
---|
745 | n/a | qs = self._test_get_x(parser.get_quoted_string, |
---|
746 | n/a | ' (a) "bob', ' (a) "bob"', ' bob', |
---|
747 | n/a | [errors.InvalidHeaderDefect], '') |
---|
748 | n/a | self.assertEqual(qs[0].comments, ['a']) |
---|
749 | n/a | self.assertEqual(qs.content, 'bob') |
---|
750 | n/a | self.assertEqual(qs.quoted_value, ' "bob"') |
---|
751 | n/a | |
---|
752 | n/a | def test_get_quoted_string_no_quoted_string(self): |
---|
753 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
754 | n/a | parser.get_quoted_string(' (ab) xyz') |
---|
755 | n/a | |
---|
756 | n/a | def test_get_quoted_string_qs_ends_at_noncfws(self): |
---|
757 | n/a | qs = self._test_get_x(parser.get_quoted_string, |
---|
758 | n/a | '\t "bob" fee', '\t "bob" ', ' bob ', [], 'fee') |
---|
759 | n/a | self.assertEqual(qs.content, 'bob') |
---|
760 | n/a | self.assertEqual(qs.quoted_value, ' "bob" ') |
---|
761 | n/a | |
---|
762 | n/a | # get_atom |
---|
763 | n/a | |
---|
764 | n/a | def test_get_atom_only(self): |
---|
765 | n/a | atom = self._test_get_x(parser.get_atom, |
---|
766 | n/a | 'bob', 'bob', 'bob', [], '') |
---|
767 | n/a | self.assertEqual(atom.token_type, 'atom') |
---|
768 | n/a | |
---|
769 | n/a | def test_get_atom_with_wsp(self): |
---|
770 | n/a | self._test_get_x(parser.get_atom, |
---|
771 | n/a | '\t bob ', '\t bob ', ' bob ', [], '') |
---|
772 | n/a | |
---|
773 | n/a | def test_get_atom_with_comments_and_wsp(self): |
---|
774 | n/a | atom = self._test_get_x(parser.get_atom, |
---|
775 | n/a | ' (foo) bob(bar)', ' (foo) bob(bar)', ' bob ', [], '') |
---|
776 | n/a | self.assertEqual(atom[0][1].content, 'foo') |
---|
777 | n/a | self.assertEqual(atom[2][0].content, 'bar') |
---|
778 | n/a | |
---|
779 | n/a | def test_get_atom_with_multiple_comments(self): |
---|
780 | n/a | atom = self._test_get_x(parser.get_atom, |
---|
781 | n/a | ' (foo) (bar) bob(bird)', ' (foo) (bar) bob(bird)', ' bob ', |
---|
782 | n/a | [], '') |
---|
783 | n/a | self.assertEqual(atom[0].comments, ['foo', 'bar']) |
---|
784 | n/a | self.assertEqual(atom[2].comments, ['bird']) |
---|
785 | n/a | |
---|
786 | n/a | def test_get_atom_non_printable_in_comment(self): |
---|
787 | n/a | atom = self._test_get_x(parser.get_atom, |
---|
788 | n/a | ' (\x0A) bob', ' (\x0A) bob', ' bob', |
---|
789 | n/a | [errors.NonPrintableDefect], '') |
---|
790 | n/a | self.assertEqual(atom[0].comments, ['\x0A']) |
---|
791 | n/a | |
---|
792 | n/a | def test_get_atom_non_printable_in_atext(self): |
---|
793 | n/a | atom = self._test_get_x(parser.get_atom, |
---|
794 | n/a | ' (a) a\x0B', ' (a) a\x0B', ' a\x0B', |
---|
795 | n/a | [errors.NonPrintableDefect], '') |
---|
796 | n/a | self.assertEqual(atom[0].comments, ['a']) |
---|
797 | n/a | |
---|
798 | n/a | def test_get_atom_header_ends_in_comment(self): |
---|
799 | n/a | atom = self._test_get_x(parser.get_atom, |
---|
800 | n/a | ' (a) bob (a', ' (a) bob (a)', ' bob ', |
---|
801 | n/a | [errors.InvalidHeaderDefect], '') |
---|
802 | n/a | self.assertEqual(atom[0].comments, ['a']) |
---|
803 | n/a | self.assertEqual(atom[2].comments, ['a']) |
---|
804 | n/a | |
---|
805 | n/a | def test_get_atom_no_atom(self): |
---|
806 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
807 | n/a | parser.get_atom(' (ab) ') |
---|
808 | n/a | |
---|
809 | n/a | def test_get_atom_no_atom_before_special(self): |
---|
810 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
811 | n/a | parser.get_atom(' (ab) @') |
---|
812 | n/a | |
---|
813 | n/a | def test_get_atom_atom_ends_at_special(self): |
---|
814 | n/a | atom = self._test_get_x(parser.get_atom, |
---|
815 | n/a | ' (foo) bob(bar) @bang', ' (foo) bob(bar) ', ' bob ', [], '@bang') |
---|
816 | n/a | self.assertEqual(atom[0].comments, ['foo']) |
---|
817 | n/a | self.assertEqual(atom[2].comments, ['bar']) |
---|
818 | n/a | |
---|
819 | n/a | def test_get_atom_atom_ends_at_noncfws(self): |
---|
820 | n/a | self._test_get_x(parser.get_atom, |
---|
821 | n/a | 'bob fred', 'bob ', 'bob ', [], 'fred') |
---|
822 | n/a | |
---|
823 | n/a | def test_get_atom_rfc2047_atom(self): |
---|
824 | n/a | self._test_get_x(parser.get_atom, |
---|
825 | n/a | '=?utf-8?q?=20bob?=', ' bob', ' bob', [], '') |
---|
826 | n/a | |
---|
827 | n/a | # get_dot_atom_text |
---|
828 | n/a | |
---|
829 | n/a | def test_get_dot_atom_text(self): |
---|
830 | n/a | dot_atom_text = self._test_get_x(parser.get_dot_atom_text, |
---|
831 | n/a | 'foo.bar.bang', 'foo.bar.bang', 'foo.bar.bang', [], '') |
---|
832 | n/a | self.assertEqual(dot_atom_text.token_type, 'dot-atom-text') |
---|
833 | n/a | self.assertEqual(len(dot_atom_text), 5) |
---|
834 | n/a | |
---|
835 | n/a | def test_get_dot_atom_text_lone_atom_is_valid(self): |
---|
836 | n/a | dot_atom_text = self._test_get_x(parser.get_dot_atom_text, |
---|
837 | n/a | 'foo', 'foo', 'foo', [], '') |
---|
838 | n/a | |
---|
839 | n/a | def test_get_dot_atom_text_raises_on_leading_dot(self): |
---|
840 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
841 | n/a | parser.get_dot_atom_text('.foo.bar') |
---|
842 | n/a | |
---|
843 | n/a | def test_get_dot_atom_text_raises_on_trailing_dot(self): |
---|
844 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
845 | n/a | parser.get_dot_atom_text('foo.bar.') |
---|
846 | n/a | |
---|
847 | n/a | def test_get_dot_atom_text_raises_on_leading_non_atext(self): |
---|
848 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
849 | n/a | parser.get_dot_atom_text(' foo.bar') |
---|
850 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
851 | n/a | parser.get_dot_atom_text('@foo.bar') |
---|
852 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
853 | n/a | parser.get_dot_atom_text('"foo.bar"') |
---|
854 | n/a | |
---|
855 | n/a | def test_get_dot_atom_text_trailing_text_preserved(self): |
---|
856 | n/a | dot_atom_text = self._test_get_x(parser.get_dot_atom_text, |
---|
857 | n/a | 'foo@bar', 'foo', 'foo', [], '@bar') |
---|
858 | n/a | |
---|
859 | n/a | def test_get_dot_atom_text_trailing_ws_preserved(self): |
---|
860 | n/a | dot_atom_text = self._test_get_x(parser.get_dot_atom_text, |
---|
861 | n/a | 'foo .bar', 'foo', 'foo', [], ' .bar') |
---|
862 | n/a | |
---|
863 | n/a | # get_dot_atom |
---|
864 | n/a | |
---|
865 | n/a | def test_get_dot_atom_only(self): |
---|
866 | n/a | dot_atom = self._test_get_x(parser.get_dot_atom, |
---|
867 | n/a | 'foo.bar.bing', 'foo.bar.bing', 'foo.bar.bing', [], '') |
---|
868 | n/a | self.assertEqual(dot_atom.token_type, 'dot-atom') |
---|
869 | n/a | self.assertEqual(len(dot_atom), 1) |
---|
870 | n/a | |
---|
871 | n/a | def test_get_dot_atom_with_wsp(self): |
---|
872 | n/a | self._test_get_x(parser.get_dot_atom, |
---|
873 | n/a | '\t foo.bar.bing ', '\t foo.bar.bing ', ' foo.bar.bing ', [], '') |
---|
874 | n/a | |
---|
875 | n/a | def test_get_dot_atom_with_comments_and_wsp(self): |
---|
876 | n/a | self._test_get_x(parser.get_dot_atom, |
---|
877 | n/a | ' (sing) foo.bar.bing (here) ', ' (sing) foo.bar.bing (here) ', |
---|
878 | n/a | ' foo.bar.bing ', [], '') |
---|
879 | n/a | |
---|
880 | n/a | def test_get_dot_atom_space_ends_dot_atom(self): |
---|
881 | n/a | self._test_get_x(parser.get_dot_atom, |
---|
882 | n/a | ' (sing) foo.bar .bing (here) ', ' (sing) foo.bar ', |
---|
883 | n/a | ' foo.bar ', [], '.bing (here) ') |
---|
884 | n/a | |
---|
885 | n/a | def test_get_dot_atom_no_atom_raises(self): |
---|
886 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
887 | n/a | parser.get_dot_atom(' (foo) ') |
---|
888 | n/a | |
---|
889 | n/a | def test_get_dot_atom_leading_dot_raises(self): |
---|
890 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
891 | n/a | parser.get_dot_atom(' (foo) .bar') |
---|
892 | n/a | |
---|
893 | n/a | def test_get_dot_atom_two_dots_raises(self): |
---|
894 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
895 | n/a | parser.get_dot_atom('bar..bang') |
---|
896 | n/a | |
---|
897 | n/a | def test_get_dot_atom_trailing_dot_raises(self): |
---|
898 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
899 | n/a | parser.get_dot_atom(' (foo) bar.bang. foo') |
---|
900 | n/a | |
---|
901 | n/a | def test_get_dot_atom_rfc2047_atom(self): |
---|
902 | n/a | self._test_get_x(parser.get_dot_atom, |
---|
903 | n/a | '=?utf-8?q?=20bob?=', ' bob', ' bob', [], '') |
---|
904 | n/a | |
---|
905 | n/a | # get_word (if this were black box we'd repeat all the qs/atom tests) |
---|
906 | n/a | |
---|
907 | n/a | def test_get_word_atom_yields_atom(self): |
---|
908 | n/a | word = self._test_get_x(parser.get_word, |
---|
909 | n/a | ' (foo) bar (bang) :ah', ' (foo) bar (bang) ', ' bar ', [], ':ah') |
---|
910 | n/a | self.assertEqual(word.token_type, 'atom') |
---|
911 | n/a | self.assertEqual(word[0].token_type, 'cfws') |
---|
912 | n/a | |
---|
913 | n/a | def test_get_word_qs_yields_qs(self): |
---|
914 | n/a | word = self._test_get_x(parser.get_word, |
---|
915 | n/a | '"bar " (bang) ah', '"bar " (bang) ', 'bar ', [], 'ah') |
---|
916 | n/a | self.assertEqual(word.token_type, 'quoted-string') |
---|
917 | n/a | self.assertEqual(word[0].token_type, 'bare-quoted-string') |
---|
918 | n/a | self.assertEqual(word[0].value, 'bar ') |
---|
919 | n/a | self.assertEqual(word.content, 'bar ') |
---|
920 | n/a | |
---|
921 | n/a | def test_get_word_ends_at_dot(self): |
---|
922 | n/a | self._test_get_x(parser.get_word, |
---|
923 | n/a | 'foo.', 'foo', 'foo', [], '.') |
---|
924 | n/a | |
---|
925 | n/a | # get_phrase |
---|
926 | n/a | |
---|
927 | n/a | def test_get_phrase_simple(self): |
---|
928 | n/a | phrase = self._test_get_x(parser.get_phrase, |
---|
929 | n/a | '"Fred A. Johnson" is his name, oh.', |
---|
930 | n/a | '"Fred A. Johnson" is his name', |
---|
931 | n/a | 'Fred A. Johnson is his name', |
---|
932 | n/a | [], |
---|
933 | n/a | ', oh.') |
---|
934 | n/a | self.assertEqual(phrase.token_type, 'phrase') |
---|
935 | n/a | |
---|
936 | n/a | def test_get_phrase_complex(self): |
---|
937 | n/a | phrase = self._test_get_x(parser.get_phrase, |
---|
938 | n/a | ' (A) bird (in (my|your)) "hand " is messy\t<>\t', |
---|
939 | n/a | ' (A) bird (in (my|your)) "hand " is messy\t', |
---|
940 | n/a | ' bird hand is messy ', |
---|
941 | n/a | [], |
---|
942 | n/a | '<>\t') |
---|
943 | n/a | self.assertEqual(phrase[0][0].comments, ['A']) |
---|
944 | n/a | self.assertEqual(phrase[0][2].comments, ['in (my|your)']) |
---|
945 | n/a | |
---|
946 | n/a | def test_get_phrase_obsolete(self): |
---|
947 | n/a | phrase = self._test_get_x(parser.get_phrase, |
---|
948 | n/a | 'Fred A.(weird).O Johnson', |
---|
949 | n/a | 'Fred A.(weird).O Johnson', |
---|
950 | n/a | 'Fred A. .O Johnson', |
---|
951 | n/a | [errors.ObsoleteHeaderDefect]*3, |
---|
952 | n/a | '') |
---|
953 | n/a | self.assertEqual(len(phrase), 7) |
---|
954 | n/a | self.assertEqual(phrase[3].comments, ['weird']) |
---|
955 | n/a | |
---|
956 | n/a | def test_get_phrase_pharse_must_start_with_word(self): |
---|
957 | n/a | phrase = self._test_get_x(parser.get_phrase, |
---|
958 | n/a | '(even weirder).name', |
---|
959 | n/a | '(even weirder).name', |
---|
960 | n/a | ' .name', |
---|
961 | n/a | [errors.InvalidHeaderDefect] + [errors.ObsoleteHeaderDefect]*2, |
---|
962 | n/a | '') |
---|
963 | n/a | self.assertEqual(len(phrase), 3) |
---|
964 | n/a | self.assertEqual(phrase[0].comments, ['even weirder']) |
---|
965 | n/a | |
---|
966 | n/a | def test_get_phrase_ending_with_obsolete(self): |
---|
967 | n/a | phrase = self._test_get_x(parser.get_phrase, |
---|
968 | n/a | 'simple phrase.(with trailing comment):boo', |
---|
969 | n/a | 'simple phrase.(with trailing comment)', |
---|
970 | n/a | 'simple phrase. ', |
---|
971 | n/a | [errors.ObsoleteHeaderDefect]*2, |
---|
972 | n/a | ':boo') |
---|
973 | n/a | self.assertEqual(len(phrase), 4) |
---|
974 | n/a | self.assertEqual(phrase[3].comments, ['with trailing comment']) |
---|
975 | n/a | |
---|
976 | n/a | def get_phrase_cfws_only_raises(self): |
---|
977 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
978 | n/a | parser.get_phrase(' (foo) ') |
---|
979 | n/a | |
---|
980 | n/a | # get_local_part |
---|
981 | n/a | |
---|
982 | n/a | def test_get_local_part_simple(self): |
---|
983 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
984 | n/a | 'dinsdale@python.org', 'dinsdale', 'dinsdale', [], '@python.org') |
---|
985 | n/a | self.assertEqual(local_part.token_type, 'local-part') |
---|
986 | n/a | self.assertEqual(local_part.local_part, 'dinsdale') |
---|
987 | n/a | |
---|
988 | n/a | def test_get_local_part_with_dot(self): |
---|
989 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
990 | n/a | 'Fred.A.Johnson@python.org', |
---|
991 | n/a | 'Fred.A.Johnson', |
---|
992 | n/a | 'Fred.A.Johnson', |
---|
993 | n/a | [], |
---|
994 | n/a | '@python.org') |
---|
995 | n/a | self.assertEqual(local_part.local_part, 'Fred.A.Johnson') |
---|
996 | n/a | |
---|
997 | n/a | def test_get_local_part_with_whitespace(self): |
---|
998 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
999 | n/a | ' Fred.A.Johnson @python.org', |
---|
1000 | n/a | ' Fred.A.Johnson ', |
---|
1001 | n/a | ' Fred.A.Johnson ', |
---|
1002 | n/a | [], |
---|
1003 | n/a | '@python.org') |
---|
1004 | n/a | self.assertEqual(local_part.local_part, 'Fred.A.Johnson') |
---|
1005 | n/a | |
---|
1006 | n/a | def test_get_local_part_with_cfws(self): |
---|
1007 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1008 | n/a | ' (foo) Fred.A.Johnson (bar (bird)) @python.org', |
---|
1009 | n/a | ' (foo) Fred.A.Johnson (bar (bird)) ', |
---|
1010 | n/a | ' Fred.A.Johnson ', |
---|
1011 | n/a | [], |
---|
1012 | n/a | '@python.org') |
---|
1013 | n/a | self.assertEqual(local_part.local_part, 'Fred.A.Johnson') |
---|
1014 | n/a | self.assertEqual(local_part[0][0].comments, ['foo']) |
---|
1015 | n/a | self.assertEqual(local_part[0][2].comments, ['bar (bird)']) |
---|
1016 | n/a | |
---|
1017 | n/a | def test_get_local_part_simple_quoted(self): |
---|
1018 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1019 | n/a | '"dinsdale"@python.org', '"dinsdale"', '"dinsdale"', [], '@python.org') |
---|
1020 | n/a | self.assertEqual(local_part.token_type, 'local-part') |
---|
1021 | n/a | self.assertEqual(local_part.local_part, 'dinsdale') |
---|
1022 | n/a | |
---|
1023 | n/a | def test_get_local_part_with_quoted_dot(self): |
---|
1024 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1025 | n/a | '"Fred.A.Johnson"@python.org', |
---|
1026 | n/a | '"Fred.A.Johnson"', |
---|
1027 | n/a | '"Fred.A.Johnson"', |
---|
1028 | n/a | [], |
---|
1029 | n/a | '@python.org') |
---|
1030 | n/a | self.assertEqual(local_part.local_part, 'Fred.A.Johnson') |
---|
1031 | n/a | |
---|
1032 | n/a | def test_get_local_part_quoted_with_whitespace(self): |
---|
1033 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1034 | n/a | ' "Fred A. Johnson" @python.org', |
---|
1035 | n/a | ' "Fred A. Johnson" ', |
---|
1036 | n/a | ' "Fred A. Johnson" ', |
---|
1037 | n/a | [], |
---|
1038 | n/a | '@python.org') |
---|
1039 | n/a | self.assertEqual(local_part.local_part, 'Fred A. Johnson') |
---|
1040 | n/a | |
---|
1041 | n/a | def test_get_local_part_quoted_with_cfws(self): |
---|
1042 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1043 | n/a | ' (foo) " Fred A. Johnson " (bar (bird)) @python.org', |
---|
1044 | n/a | ' (foo) " Fred A. Johnson " (bar (bird)) ', |
---|
1045 | n/a | ' " Fred A. Johnson " ', |
---|
1046 | n/a | [], |
---|
1047 | n/a | '@python.org') |
---|
1048 | n/a | self.assertEqual(local_part.local_part, ' Fred A. Johnson ') |
---|
1049 | n/a | self.assertEqual(local_part[0][0].comments, ['foo']) |
---|
1050 | n/a | self.assertEqual(local_part[0][2].comments, ['bar (bird)']) |
---|
1051 | n/a | |
---|
1052 | n/a | |
---|
1053 | n/a | def test_get_local_part_simple_obsolete(self): |
---|
1054 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1055 | n/a | 'Fred. A.Johnson@python.org', |
---|
1056 | n/a | 'Fred. A.Johnson', |
---|
1057 | n/a | 'Fred. A.Johnson', |
---|
1058 | n/a | [errors.ObsoleteHeaderDefect], |
---|
1059 | n/a | '@python.org') |
---|
1060 | n/a | self.assertEqual(local_part.local_part, 'Fred.A.Johnson') |
---|
1061 | n/a | |
---|
1062 | n/a | def test_get_local_part_complex_obsolete_1(self): |
---|
1063 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1064 | n/a | ' (foo )Fred (bar).(bird) A.(sheep)Johnson."and dogs "@python.org', |
---|
1065 | n/a | ' (foo )Fred (bar).(bird) A.(sheep)Johnson."and dogs "', |
---|
1066 | n/a | ' Fred . A. Johnson.and dogs ', |
---|
1067 | n/a | [errors.ObsoleteHeaderDefect], |
---|
1068 | n/a | '@python.org') |
---|
1069 | n/a | self.assertEqual(local_part.local_part, 'Fred.A.Johnson.and dogs ') |
---|
1070 | n/a | |
---|
1071 | n/a | def test_get_local_part_complex_obsolete_invalid(self): |
---|
1072 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1073 | n/a | ' (foo )Fred (bar).(bird) A.(sheep)Johnson "and dogs"@python.org', |
---|
1074 | n/a | ' (foo )Fred (bar).(bird) A.(sheep)Johnson "and dogs"', |
---|
1075 | n/a | ' Fred . A. Johnson and dogs', |
---|
1076 | n/a | [errors.InvalidHeaderDefect]*2, |
---|
1077 | n/a | '@python.org') |
---|
1078 | n/a | self.assertEqual(local_part.local_part, 'Fred.A.Johnson and dogs') |
---|
1079 | n/a | |
---|
1080 | n/a | def test_get_local_part_no_part_raises(self): |
---|
1081 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1082 | n/a | parser.get_local_part(' (foo) ') |
---|
1083 | n/a | |
---|
1084 | n/a | def test_get_local_part_special_instead_raises(self): |
---|
1085 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1086 | n/a | parser.get_local_part(' (foo) @python.org') |
---|
1087 | n/a | |
---|
1088 | n/a | def test_get_local_part_trailing_dot(self): |
---|
1089 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1090 | n/a | ' borris.@python.org', |
---|
1091 | n/a | ' borris.', |
---|
1092 | n/a | ' borris.', |
---|
1093 | n/a | [errors.InvalidHeaderDefect]*2, |
---|
1094 | n/a | '@python.org') |
---|
1095 | n/a | self.assertEqual(local_part.local_part, 'borris.') |
---|
1096 | n/a | |
---|
1097 | n/a | def test_get_local_part_trailing_dot_with_ws(self): |
---|
1098 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1099 | n/a | ' borris. @python.org', |
---|
1100 | n/a | ' borris. ', |
---|
1101 | n/a | ' borris. ', |
---|
1102 | n/a | [errors.InvalidHeaderDefect]*2, |
---|
1103 | n/a | '@python.org') |
---|
1104 | n/a | self.assertEqual(local_part.local_part, 'borris.') |
---|
1105 | n/a | |
---|
1106 | n/a | def test_get_local_part_leading_dot(self): |
---|
1107 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1108 | n/a | '.borris@python.org', |
---|
1109 | n/a | '.borris', |
---|
1110 | n/a | '.borris', |
---|
1111 | n/a | [errors.InvalidHeaderDefect]*2, |
---|
1112 | n/a | '@python.org') |
---|
1113 | n/a | self.assertEqual(local_part.local_part, '.borris') |
---|
1114 | n/a | |
---|
1115 | n/a | def test_get_local_part_leading_dot_after_ws(self): |
---|
1116 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1117 | n/a | ' .borris@python.org', |
---|
1118 | n/a | ' .borris', |
---|
1119 | n/a | ' .borris', |
---|
1120 | n/a | [errors.InvalidHeaderDefect]*2, |
---|
1121 | n/a | '@python.org') |
---|
1122 | n/a | self.assertEqual(local_part.local_part, '.borris') |
---|
1123 | n/a | |
---|
1124 | n/a | def test_get_local_part_double_dot_raises(self): |
---|
1125 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1126 | n/a | ' borris.(foo).natasha@python.org', |
---|
1127 | n/a | ' borris.(foo).natasha', |
---|
1128 | n/a | ' borris. .natasha', |
---|
1129 | n/a | [errors.InvalidHeaderDefect]*2, |
---|
1130 | n/a | '@python.org') |
---|
1131 | n/a | self.assertEqual(local_part.local_part, 'borris..natasha') |
---|
1132 | n/a | |
---|
1133 | n/a | def test_get_local_part_quoted_strings_in_atom_list(self): |
---|
1134 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1135 | n/a | '""example" example"@example.com', |
---|
1136 | n/a | '""example" example"', |
---|
1137 | n/a | 'example example', |
---|
1138 | n/a | [errors.InvalidHeaderDefect]*3, |
---|
1139 | n/a | '@example.com') |
---|
1140 | n/a | self.assertEqual(local_part.local_part, 'example example') |
---|
1141 | n/a | |
---|
1142 | n/a | def test_get_local_part_valid_and_invalid_qp_in_atom_list(self): |
---|
1143 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1144 | n/a | r'"\\"example\\" example"@example.com', |
---|
1145 | n/a | r'"\\"example\\" example"', |
---|
1146 | n/a | r'\example\\ example', |
---|
1147 | n/a | [errors.InvalidHeaderDefect]*5, |
---|
1148 | n/a | '@example.com') |
---|
1149 | n/a | self.assertEqual(local_part.local_part, r'\example\\ example') |
---|
1150 | n/a | |
---|
1151 | n/a | def test_get_local_part_unicode_defect(self): |
---|
1152 | n/a | # Currently this only happens when parsing unicode, not when parsing |
---|
1153 | n/a | # stuff that was originally binary. |
---|
1154 | n/a | local_part = self._test_get_x(parser.get_local_part, |
---|
1155 | n/a | 'exámple@example.com', |
---|
1156 | n/a | 'exámple', |
---|
1157 | n/a | 'exámple', |
---|
1158 | n/a | [errors.NonASCIILocalPartDefect], |
---|
1159 | n/a | '@example.com') |
---|
1160 | n/a | self.assertEqual(local_part.local_part, 'exámple') |
---|
1161 | n/a | |
---|
1162 | n/a | # get_dtext |
---|
1163 | n/a | |
---|
1164 | n/a | def test_get_dtext_only(self): |
---|
1165 | n/a | dtext = self._test_get_x(parser.get_dtext, |
---|
1166 | n/a | 'foobar', 'foobar', 'foobar', [], '') |
---|
1167 | n/a | self.assertEqual(dtext.token_type, 'ptext') |
---|
1168 | n/a | |
---|
1169 | n/a | def test_get_dtext_all_dtext(self): |
---|
1170 | n/a | dtext = self._test_get_x(parser.get_dtext, self.rfc_dtext_chars, |
---|
1171 | n/a | self.rfc_dtext_chars, |
---|
1172 | n/a | self.rfc_dtext_chars, [], '') |
---|
1173 | n/a | |
---|
1174 | n/a | def test_get_dtext_two_words_gets_first(self): |
---|
1175 | n/a | self._test_get_x(parser.get_dtext, |
---|
1176 | n/a | 'foo bar', 'foo', 'foo', [], ' bar') |
---|
1177 | n/a | |
---|
1178 | n/a | def test_get_dtext_following_wsp_preserved(self): |
---|
1179 | n/a | self._test_get_x(parser.get_dtext, |
---|
1180 | n/a | 'foo \t\tbar', 'foo', 'foo', [], ' \t\tbar') |
---|
1181 | n/a | |
---|
1182 | n/a | def test_get_dtext_non_printables(self): |
---|
1183 | n/a | dtext = self._test_get_x(parser.get_dtext, |
---|
1184 | n/a | 'foo\x00bar]', 'foo\x00bar', 'foo\x00bar', |
---|
1185 | n/a | [errors.NonPrintableDefect], ']') |
---|
1186 | n/a | self.assertEqual(dtext.defects[0].non_printables[0], '\x00') |
---|
1187 | n/a | |
---|
1188 | n/a | def test_get_dtext_with_qp(self): |
---|
1189 | n/a | ptext = self._test_get_x(parser.get_dtext, |
---|
1190 | n/a | r'foo\]\[\\bar\b\e\l\l', |
---|
1191 | n/a | r'foo][\barbell', |
---|
1192 | n/a | r'foo][\barbell', |
---|
1193 | n/a | [errors.ObsoleteHeaderDefect], |
---|
1194 | n/a | '') |
---|
1195 | n/a | |
---|
1196 | n/a | def test_get_dtext_up_to_close_bracket_only(self): |
---|
1197 | n/a | self._test_get_x(parser.get_dtext, |
---|
1198 | n/a | 'foo]', 'foo', 'foo', [], ']') |
---|
1199 | n/a | |
---|
1200 | n/a | def test_get_dtext_wsp_before_close_bracket_preserved(self): |
---|
1201 | n/a | self._test_get_x(parser.get_dtext, |
---|
1202 | n/a | 'foo ]', 'foo', 'foo', [], ' ]') |
---|
1203 | n/a | |
---|
1204 | n/a | def test_get_dtext_close_bracket_mid_word(self): |
---|
1205 | n/a | self._test_get_x(parser.get_dtext, |
---|
1206 | n/a | 'foo]bar', 'foo', 'foo', [], ']bar') |
---|
1207 | n/a | |
---|
1208 | n/a | def test_get_dtext_up_to_open_bracket_only(self): |
---|
1209 | n/a | self._test_get_x(parser.get_dtext, |
---|
1210 | n/a | 'foo[', 'foo', 'foo', [], '[') |
---|
1211 | n/a | |
---|
1212 | n/a | def test_get_dtext_wsp_before_open_bracket_preserved(self): |
---|
1213 | n/a | self._test_get_x(parser.get_dtext, |
---|
1214 | n/a | 'foo [', 'foo', 'foo', [], ' [') |
---|
1215 | n/a | |
---|
1216 | n/a | def test_get_dtext_open_bracket_mid_word(self): |
---|
1217 | n/a | self._test_get_x(parser.get_dtext, |
---|
1218 | n/a | 'foo[bar', 'foo', 'foo', [], '[bar') |
---|
1219 | n/a | |
---|
1220 | n/a | # get_domain_literal |
---|
1221 | n/a | |
---|
1222 | n/a | def test_get_domain_literal_only(self): |
---|
1223 | n/a | domain_literal = domain_literal = self._test_get_x(parser.get_domain_literal, |
---|
1224 | n/a | '[127.0.0.1]', |
---|
1225 | n/a | '[127.0.0.1]', |
---|
1226 | n/a | '[127.0.0.1]', |
---|
1227 | n/a | [], |
---|
1228 | n/a | '') |
---|
1229 | n/a | self.assertEqual(domain_literal.token_type, 'domain-literal') |
---|
1230 | n/a | self.assertEqual(domain_literal.domain, '[127.0.0.1]') |
---|
1231 | n/a | self.assertEqual(domain_literal.ip, '127.0.0.1') |
---|
1232 | n/a | |
---|
1233 | n/a | def test_get_domain_literal_with_internal_ws(self): |
---|
1234 | n/a | domain_literal = self._test_get_x(parser.get_domain_literal, |
---|
1235 | n/a | '[ 127.0.0.1\t ]', |
---|
1236 | n/a | '[ 127.0.0.1\t ]', |
---|
1237 | n/a | '[ 127.0.0.1 ]', |
---|
1238 | n/a | [], |
---|
1239 | n/a | '') |
---|
1240 | n/a | self.assertEqual(domain_literal.domain, '[127.0.0.1]') |
---|
1241 | n/a | self.assertEqual(domain_literal.ip, '127.0.0.1') |
---|
1242 | n/a | |
---|
1243 | n/a | def test_get_domain_literal_with_surrounding_cfws(self): |
---|
1244 | n/a | domain_literal = self._test_get_x(parser.get_domain_literal, |
---|
1245 | n/a | '(foo)[ 127.0.0.1] (bar)', |
---|
1246 | n/a | '(foo)[ 127.0.0.1] (bar)', |
---|
1247 | n/a | ' [ 127.0.0.1] ', |
---|
1248 | n/a | [], |
---|
1249 | n/a | '') |
---|
1250 | n/a | self.assertEqual(domain_literal.domain, '[127.0.0.1]') |
---|
1251 | n/a | self.assertEqual(domain_literal.ip, '127.0.0.1') |
---|
1252 | n/a | |
---|
1253 | n/a | def test_get_domain_literal_no_start_char_raises(self): |
---|
1254 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1255 | n/a | parser.get_domain_literal('(foo) ') |
---|
1256 | n/a | |
---|
1257 | n/a | def test_get_domain_literal_no_start_char_before_special_raises(self): |
---|
1258 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1259 | n/a | parser.get_domain_literal('(foo) @') |
---|
1260 | n/a | |
---|
1261 | n/a | def test_get_domain_literal_bad_dtext_char_before_special_raises(self): |
---|
1262 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1263 | n/a | parser.get_domain_literal('(foo) [abc[@') |
---|
1264 | n/a | |
---|
1265 | n/a | # get_domain |
---|
1266 | n/a | |
---|
1267 | n/a | def test_get_domain_regular_domain_only(self): |
---|
1268 | n/a | domain = self._test_get_x(parser.get_domain, |
---|
1269 | n/a | 'example.com', |
---|
1270 | n/a | 'example.com', |
---|
1271 | n/a | 'example.com', |
---|
1272 | n/a | [], |
---|
1273 | n/a | '') |
---|
1274 | n/a | self.assertEqual(domain.token_type, 'domain') |
---|
1275 | n/a | self.assertEqual(domain.domain, 'example.com') |
---|
1276 | n/a | |
---|
1277 | n/a | def test_get_domain_domain_literal_only(self): |
---|
1278 | n/a | domain = self._test_get_x(parser.get_domain, |
---|
1279 | n/a | '[127.0.0.1]', |
---|
1280 | n/a | '[127.0.0.1]', |
---|
1281 | n/a | '[127.0.0.1]', |
---|
1282 | n/a | [], |
---|
1283 | n/a | '') |
---|
1284 | n/a | self.assertEqual(domain.token_type, 'domain') |
---|
1285 | n/a | self.assertEqual(domain.domain, '[127.0.0.1]') |
---|
1286 | n/a | |
---|
1287 | n/a | def test_get_domain_with_cfws(self): |
---|
1288 | n/a | domain = self._test_get_x(parser.get_domain, |
---|
1289 | n/a | '(foo) example.com(bar)\t', |
---|
1290 | n/a | '(foo) example.com(bar)\t', |
---|
1291 | n/a | ' example.com ', |
---|
1292 | n/a | [], |
---|
1293 | n/a | '') |
---|
1294 | n/a | self.assertEqual(domain.domain, 'example.com') |
---|
1295 | n/a | |
---|
1296 | n/a | def test_get_domain_domain_literal_with_cfws(self): |
---|
1297 | n/a | domain = self._test_get_x(parser.get_domain, |
---|
1298 | n/a | '(foo)[127.0.0.1]\t(bar)', |
---|
1299 | n/a | '(foo)[127.0.0.1]\t(bar)', |
---|
1300 | n/a | ' [127.0.0.1] ', |
---|
1301 | n/a | [], |
---|
1302 | n/a | '') |
---|
1303 | n/a | self.assertEqual(domain.domain, '[127.0.0.1]') |
---|
1304 | n/a | |
---|
1305 | n/a | def test_get_domain_domain_with_cfws_ends_at_special(self): |
---|
1306 | n/a | domain = self._test_get_x(parser.get_domain, |
---|
1307 | n/a | '(foo)example.com\t(bar), next', |
---|
1308 | n/a | '(foo)example.com\t(bar)', |
---|
1309 | n/a | ' example.com ', |
---|
1310 | n/a | [], |
---|
1311 | n/a | ', next') |
---|
1312 | n/a | self.assertEqual(domain.domain, 'example.com') |
---|
1313 | n/a | |
---|
1314 | n/a | def test_get_domain_domain_literal_with_cfws_ends_at_special(self): |
---|
1315 | n/a | domain = self._test_get_x(parser.get_domain, |
---|
1316 | n/a | '(foo)[127.0.0.1]\t(bar), next', |
---|
1317 | n/a | '(foo)[127.0.0.1]\t(bar)', |
---|
1318 | n/a | ' [127.0.0.1] ', |
---|
1319 | n/a | [], |
---|
1320 | n/a | ', next') |
---|
1321 | n/a | self.assertEqual(domain.domain, '[127.0.0.1]') |
---|
1322 | n/a | |
---|
1323 | n/a | def test_get_domain_obsolete(self): |
---|
1324 | n/a | domain = self._test_get_x(parser.get_domain, |
---|
1325 | n/a | '(foo) example . (bird)com(bar)\t', |
---|
1326 | n/a | '(foo) example . (bird)com(bar)\t', |
---|
1327 | n/a | ' example . com ', |
---|
1328 | n/a | [errors.ObsoleteHeaderDefect], |
---|
1329 | n/a | '') |
---|
1330 | n/a | self.assertEqual(domain.domain, 'example.com') |
---|
1331 | n/a | |
---|
1332 | n/a | def test_get_domain_no_non_cfws_raises(self): |
---|
1333 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1334 | n/a | parser.get_domain(" (foo)\t") |
---|
1335 | n/a | |
---|
1336 | n/a | def test_get_domain_no_atom_raises(self): |
---|
1337 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1338 | n/a | parser.get_domain(" (foo)\t, broken") |
---|
1339 | n/a | |
---|
1340 | n/a | |
---|
1341 | n/a | # get_addr_spec |
---|
1342 | n/a | |
---|
1343 | n/a | def test_get_addr_spec_normal(self): |
---|
1344 | n/a | addr_spec = self._test_get_x(parser.get_addr_spec, |
---|
1345 | n/a | 'dinsdale@example.com', |
---|
1346 | n/a | 'dinsdale@example.com', |
---|
1347 | n/a | 'dinsdale@example.com', |
---|
1348 | n/a | [], |
---|
1349 | n/a | '') |
---|
1350 | n/a | self.assertEqual(addr_spec.token_type, 'addr-spec') |
---|
1351 | n/a | self.assertEqual(addr_spec.local_part, 'dinsdale') |
---|
1352 | n/a | self.assertEqual(addr_spec.domain, 'example.com') |
---|
1353 | n/a | self.assertEqual(addr_spec.addr_spec, 'dinsdale@example.com') |
---|
1354 | n/a | |
---|
1355 | n/a | def test_get_addr_spec_with_doamin_literal(self): |
---|
1356 | n/a | addr_spec = self._test_get_x(parser.get_addr_spec, |
---|
1357 | n/a | 'dinsdale@[127.0.0.1]', |
---|
1358 | n/a | 'dinsdale@[127.0.0.1]', |
---|
1359 | n/a | 'dinsdale@[127.0.0.1]', |
---|
1360 | n/a | [], |
---|
1361 | n/a | '') |
---|
1362 | n/a | self.assertEqual(addr_spec.local_part, 'dinsdale') |
---|
1363 | n/a | self.assertEqual(addr_spec.domain, '[127.0.0.1]') |
---|
1364 | n/a | self.assertEqual(addr_spec.addr_spec, 'dinsdale@[127.0.0.1]') |
---|
1365 | n/a | |
---|
1366 | n/a | def test_get_addr_spec_with_cfws(self): |
---|
1367 | n/a | addr_spec = self._test_get_x(parser.get_addr_spec, |
---|
1368 | n/a | '(foo) dinsdale(bar)@ (bird) example.com (bog)', |
---|
1369 | n/a | '(foo) dinsdale(bar)@ (bird) example.com (bog)', |
---|
1370 | n/a | ' dinsdale@example.com ', |
---|
1371 | n/a | [], |
---|
1372 | n/a | '') |
---|
1373 | n/a | self.assertEqual(addr_spec.local_part, 'dinsdale') |
---|
1374 | n/a | self.assertEqual(addr_spec.domain, 'example.com') |
---|
1375 | n/a | self.assertEqual(addr_spec.addr_spec, 'dinsdale@example.com') |
---|
1376 | n/a | |
---|
1377 | n/a | def test_get_addr_spec_with_qouoted_string_and_cfws(self): |
---|
1378 | n/a | addr_spec = self._test_get_x(parser.get_addr_spec, |
---|
1379 | n/a | '(foo) "roy a bug"(bar)@ (bird) example.com (bog)', |
---|
1380 | n/a | '(foo) "roy a bug"(bar)@ (bird) example.com (bog)', |
---|
1381 | n/a | ' "roy a bug"@example.com ', |
---|
1382 | n/a | [], |
---|
1383 | n/a | '') |
---|
1384 | n/a | self.assertEqual(addr_spec.local_part, 'roy a bug') |
---|
1385 | n/a | self.assertEqual(addr_spec.domain, 'example.com') |
---|
1386 | n/a | self.assertEqual(addr_spec.addr_spec, '"roy a bug"@example.com') |
---|
1387 | n/a | |
---|
1388 | n/a | def test_get_addr_spec_ends_at_special(self): |
---|
1389 | n/a | addr_spec = self._test_get_x(parser.get_addr_spec, |
---|
1390 | n/a | '(foo) "roy a bug"(bar)@ (bird) example.com (bog) , next', |
---|
1391 | n/a | '(foo) "roy a bug"(bar)@ (bird) example.com (bog) ', |
---|
1392 | n/a | ' "roy a bug"@example.com ', |
---|
1393 | n/a | [], |
---|
1394 | n/a | ', next') |
---|
1395 | n/a | self.assertEqual(addr_spec.local_part, 'roy a bug') |
---|
1396 | n/a | self.assertEqual(addr_spec.domain, 'example.com') |
---|
1397 | n/a | self.assertEqual(addr_spec.addr_spec, '"roy a bug"@example.com') |
---|
1398 | n/a | |
---|
1399 | n/a | def test_get_addr_spec_quoted_strings_in_atom_list(self): |
---|
1400 | n/a | addr_spec = self._test_get_x(parser.get_addr_spec, |
---|
1401 | n/a | '""example" example"@example.com', |
---|
1402 | n/a | '""example" example"@example.com', |
---|
1403 | n/a | 'example example@example.com', |
---|
1404 | n/a | [errors.InvalidHeaderDefect]*3, |
---|
1405 | n/a | '') |
---|
1406 | n/a | self.assertEqual(addr_spec.local_part, 'example example') |
---|
1407 | n/a | self.assertEqual(addr_spec.domain, 'example.com') |
---|
1408 | n/a | self.assertEqual(addr_spec.addr_spec, '"example example"@example.com') |
---|
1409 | n/a | |
---|
1410 | n/a | def test_get_addr_spec_dot_atom(self): |
---|
1411 | n/a | addr_spec = self._test_get_x(parser.get_addr_spec, |
---|
1412 | n/a | 'star.a.star@example.com', |
---|
1413 | n/a | 'star.a.star@example.com', |
---|
1414 | n/a | 'star.a.star@example.com', |
---|
1415 | n/a | [], |
---|
1416 | n/a | '') |
---|
1417 | n/a | self.assertEqual(addr_spec.local_part, 'star.a.star') |
---|
1418 | n/a | self.assertEqual(addr_spec.domain, 'example.com') |
---|
1419 | n/a | self.assertEqual(addr_spec.addr_spec, 'star.a.star@example.com') |
---|
1420 | n/a | |
---|
1421 | n/a | # get_obs_route |
---|
1422 | n/a | |
---|
1423 | n/a | def test_get_obs_route_simple(self): |
---|
1424 | n/a | obs_route = self._test_get_x(parser.get_obs_route, |
---|
1425 | n/a | '@example.com, @two.example.com:', |
---|
1426 | n/a | '@example.com, @two.example.com:', |
---|
1427 | n/a | '@example.com, @two.example.com:', |
---|
1428 | n/a | [], |
---|
1429 | n/a | '') |
---|
1430 | n/a | self.assertEqual(obs_route.token_type, 'obs-route') |
---|
1431 | n/a | self.assertEqual(obs_route.domains, ['example.com', 'two.example.com']) |
---|
1432 | n/a | |
---|
1433 | n/a | def test_get_obs_route_complex(self): |
---|
1434 | n/a | obs_route = self._test_get_x(parser.get_obs_route, |
---|
1435 | n/a | '(foo),, (blue)@example.com (bar),@two.(foo) example.com (bird):', |
---|
1436 | n/a | '(foo),, (blue)@example.com (bar),@two.(foo) example.com (bird):', |
---|
1437 | n/a | ' ,, @example.com ,@two. example.com :', |
---|
1438 | n/a | [errors.ObsoleteHeaderDefect], # This is the obs-domain |
---|
1439 | n/a | '') |
---|
1440 | n/a | self.assertEqual(obs_route.token_type, 'obs-route') |
---|
1441 | n/a | self.assertEqual(obs_route.domains, ['example.com', 'two.example.com']) |
---|
1442 | n/a | |
---|
1443 | n/a | def test_get_obs_route_no_route_before_end_raises(self): |
---|
1444 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1445 | n/a | parser.get_obs_route('(foo) @example.com,') |
---|
1446 | n/a | |
---|
1447 | n/a | def test_get_obs_route_no_route_before_special_raises(self): |
---|
1448 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1449 | n/a | parser.get_obs_route('(foo) [abc],') |
---|
1450 | n/a | |
---|
1451 | n/a | def test_get_obs_route_no_route_before_special_raises2(self): |
---|
1452 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1453 | n/a | parser.get_obs_route('(foo) @example.com [abc],') |
---|
1454 | n/a | |
---|
1455 | n/a | # get_angle_addr |
---|
1456 | n/a | |
---|
1457 | n/a | def test_get_angle_addr_simple(self): |
---|
1458 | n/a | angle_addr = self._test_get_x(parser.get_angle_addr, |
---|
1459 | n/a | '<dinsdale@example.com>', |
---|
1460 | n/a | '<dinsdale@example.com>', |
---|
1461 | n/a | '<dinsdale@example.com>', |
---|
1462 | n/a | [], |
---|
1463 | n/a | '') |
---|
1464 | n/a | self.assertEqual(angle_addr.token_type, 'angle-addr') |
---|
1465 | n/a | self.assertEqual(angle_addr.local_part, 'dinsdale') |
---|
1466 | n/a | self.assertEqual(angle_addr.domain, 'example.com') |
---|
1467 | n/a | self.assertIsNone(angle_addr.route) |
---|
1468 | n/a | self.assertEqual(angle_addr.addr_spec, 'dinsdale@example.com') |
---|
1469 | n/a | |
---|
1470 | n/a | def test_get_angle_addr_empty(self): |
---|
1471 | n/a | angle_addr = self._test_get_x(parser.get_angle_addr, |
---|
1472 | n/a | '<>', |
---|
1473 | n/a | '<>', |
---|
1474 | n/a | '<>', |
---|
1475 | n/a | [errors.InvalidHeaderDefect], |
---|
1476 | n/a | '') |
---|
1477 | n/a | self.assertEqual(angle_addr.token_type, 'angle-addr') |
---|
1478 | n/a | self.assertIsNone(angle_addr.local_part) |
---|
1479 | n/a | self.assertIsNone(angle_addr.domain) |
---|
1480 | n/a | self.assertIsNone(angle_addr.route) |
---|
1481 | n/a | self.assertEqual(angle_addr.addr_spec, '<>') |
---|
1482 | n/a | |
---|
1483 | n/a | def test_get_angle_addr_with_cfws(self): |
---|
1484 | n/a | angle_addr = self._test_get_x(parser.get_angle_addr, |
---|
1485 | n/a | ' (foo) <dinsdale@example.com>(bar)', |
---|
1486 | n/a | ' (foo) <dinsdale@example.com>(bar)', |
---|
1487 | n/a | ' <dinsdale@example.com> ', |
---|
1488 | n/a | [], |
---|
1489 | n/a | '') |
---|
1490 | n/a | self.assertEqual(angle_addr.token_type, 'angle-addr') |
---|
1491 | n/a | self.assertEqual(angle_addr.local_part, 'dinsdale') |
---|
1492 | n/a | self.assertEqual(angle_addr.domain, 'example.com') |
---|
1493 | n/a | self.assertIsNone(angle_addr.route) |
---|
1494 | n/a | self.assertEqual(angle_addr.addr_spec, 'dinsdale@example.com') |
---|
1495 | n/a | |
---|
1496 | n/a | def test_get_angle_addr_qs_and_domain_literal(self): |
---|
1497 | n/a | angle_addr = self._test_get_x(parser.get_angle_addr, |
---|
1498 | n/a | '<"Fred Perfect"@[127.0.0.1]>', |
---|
1499 | n/a | '<"Fred Perfect"@[127.0.0.1]>', |
---|
1500 | n/a | '<"Fred Perfect"@[127.0.0.1]>', |
---|
1501 | n/a | [], |
---|
1502 | n/a | '') |
---|
1503 | n/a | self.assertEqual(angle_addr.local_part, 'Fred Perfect') |
---|
1504 | n/a | self.assertEqual(angle_addr.domain, '[127.0.0.1]') |
---|
1505 | n/a | self.assertIsNone(angle_addr.route) |
---|
1506 | n/a | self.assertEqual(angle_addr.addr_spec, '"Fred Perfect"@[127.0.0.1]') |
---|
1507 | n/a | |
---|
1508 | n/a | def test_get_angle_addr_internal_cfws(self): |
---|
1509 | n/a | angle_addr = self._test_get_x(parser.get_angle_addr, |
---|
1510 | n/a | '<(foo) dinsdale@example.com(bar)>', |
---|
1511 | n/a | '<(foo) dinsdale@example.com(bar)>', |
---|
1512 | n/a | '< dinsdale@example.com >', |
---|
1513 | n/a | [], |
---|
1514 | n/a | '') |
---|
1515 | n/a | self.assertEqual(angle_addr.local_part, 'dinsdale') |
---|
1516 | n/a | self.assertEqual(angle_addr.domain, 'example.com') |
---|
1517 | n/a | self.assertIsNone(angle_addr.route) |
---|
1518 | n/a | self.assertEqual(angle_addr.addr_spec, 'dinsdale@example.com') |
---|
1519 | n/a | |
---|
1520 | n/a | def test_get_angle_addr_obs_route(self): |
---|
1521 | n/a | angle_addr = self._test_get_x(parser.get_angle_addr, |
---|
1522 | n/a | '(foo)<@example.com, (bird) @two.example.com: dinsdale@example.com> (bar) ', |
---|
1523 | n/a | '(foo)<@example.com, (bird) @two.example.com: dinsdale@example.com> (bar) ', |
---|
1524 | n/a | ' <@example.com, @two.example.com: dinsdale@example.com> ', |
---|
1525 | n/a | [errors.ObsoleteHeaderDefect], |
---|
1526 | n/a | '') |
---|
1527 | n/a | self.assertEqual(angle_addr.local_part, 'dinsdale') |
---|
1528 | n/a | self.assertEqual(angle_addr.domain, 'example.com') |
---|
1529 | n/a | self.assertEqual(angle_addr.route, ['example.com', 'two.example.com']) |
---|
1530 | n/a | self.assertEqual(angle_addr.addr_spec, 'dinsdale@example.com') |
---|
1531 | n/a | |
---|
1532 | n/a | def test_get_angle_addr_missing_closing_angle(self): |
---|
1533 | n/a | angle_addr = self._test_get_x(parser.get_angle_addr, |
---|
1534 | n/a | '<dinsdale@example.com', |
---|
1535 | n/a | '<dinsdale@example.com>', |
---|
1536 | n/a | '<dinsdale@example.com>', |
---|
1537 | n/a | [errors.InvalidHeaderDefect], |
---|
1538 | n/a | '') |
---|
1539 | n/a | self.assertEqual(angle_addr.local_part, 'dinsdale') |
---|
1540 | n/a | self.assertEqual(angle_addr.domain, 'example.com') |
---|
1541 | n/a | self.assertIsNone(angle_addr.route) |
---|
1542 | n/a | self.assertEqual(angle_addr.addr_spec, 'dinsdale@example.com') |
---|
1543 | n/a | |
---|
1544 | n/a | def test_get_angle_addr_missing_closing_angle_with_cfws(self): |
---|
1545 | n/a | angle_addr = self._test_get_x(parser.get_angle_addr, |
---|
1546 | n/a | '<dinsdale@example.com (foo)', |
---|
1547 | n/a | '<dinsdale@example.com (foo)>', |
---|
1548 | n/a | '<dinsdale@example.com >', |
---|
1549 | n/a | [errors.InvalidHeaderDefect], |
---|
1550 | n/a | '') |
---|
1551 | n/a | self.assertEqual(angle_addr.local_part, 'dinsdale') |
---|
1552 | n/a | self.assertEqual(angle_addr.domain, 'example.com') |
---|
1553 | n/a | self.assertIsNone(angle_addr.route) |
---|
1554 | n/a | self.assertEqual(angle_addr.addr_spec, 'dinsdale@example.com') |
---|
1555 | n/a | |
---|
1556 | n/a | def test_get_angle_addr_ends_at_special(self): |
---|
1557 | n/a | angle_addr = self._test_get_x(parser.get_angle_addr, |
---|
1558 | n/a | '<dinsdale@example.com> (foo), next', |
---|
1559 | n/a | '<dinsdale@example.com> (foo)', |
---|
1560 | n/a | '<dinsdale@example.com> ', |
---|
1561 | n/a | [], |
---|
1562 | n/a | ', next') |
---|
1563 | n/a | self.assertEqual(angle_addr.local_part, 'dinsdale') |
---|
1564 | n/a | self.assertEqual(angle_addr.domain, 'example.com') |
---|
1565 | n/a | self.assertIsNone(angle_addr.route) |
---|
1566 | n/a | self.assertEqual(angle_addr.addr_spec, 'dinsdale@example.com') |
---|
1567 | n/a | |
---|
1568 | n/a | def test_get_angle_addr_no_angle_raise(self): |
---|
1569 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1570 | n/a | parser.get_angle_addr('(foo) ') |
---|
1571 | n/a | |
---|
1572 | n/a | def test_get_angle_addr_no_angle_before_special_raises(self): |
---|
1573 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1574 | n/a | parser.get_angle_addr('(foo) , next') |
---|
1575 | n/a | |
---|
1576 | n/a | def test_get_angle_addr_no_angle_raises(self): |
---|
1577 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1578 | n/a | parser.get_angle_addr('bar') |
---|
1579 | n/a | |
---|
1580 | n/a | def test_get_angle_addr_special_after_angle_raises(self): |
---|
1581 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1582 | n/a | parser.get_angle_addr('(foo) <, bar') |
---|
1583 | n/a | |
---|
1584 | n/a | # get_display_name This is phrase but with a different value. |
---|
1585 | n/a | |
---|
1586 | n/a | def test_get_display_name_simple(self): |
---|
1587 | n/a | display_name = self._test_get_x(parser.get_display_name, |
---|
1588 | n/a | 'Fred A Johnson', |
---|
1589 | n/a | 'Fred A Johnson', |
---|
1590 | n/a | 'Fred A Johnson', |
---|
1591 | n/a | [], |
---|
1592 | n/a | '') |
---|
1593 | n/a | self.assertEqual(display_name.token_type, 'display-name') |
---|
1594 | n/a | self.assertEqual(display_name.display_name, 'Fred A Johnson') |
---|
1595 | n/a | |
---|
1596 | n/a | def test_get_display_name_complex1(self): |
---|
1597 | n/a | display_name = self._test_get_x(parser.get_display_name, |
---|
1598 | n/a | '"Fred A. Johnson" is his name, oh.', |
---|
1599 | n/a | '"Fred A. Johnson" is his name', |
---|
1600 | n/a | '"Fred A. Johnson is his name"', |
---|
1601 | n/a | [], |
---|
1602 | n/a | ', oh.') |
---|
1603 | n/a | self.assertEqual(display_name.token_type, 'display-name') |
---|
1604 | n/a | self.assertEqual(display_name.display_name, 'Fred A. Johnson is his name') |
---|
1605 | n/a | |
---|
1606 | n/a | def test_get_display_name_complex2(self): |
---|
1607 | n/a | display_name = self._test_get_x(parser.get_display_name, |
---|
1608 | n/a | ' (A) bird (in (my|your)) "hand " is messy\t<>\t', |
---|
1609 | n/a | ' (A) bird (in (my|your)) "hand " is messy\t', |
---|
1610 | n/a | ' "bird hand is messy" ', |
---|
1611 | n/a | [], |
---|
1612 | n/a | '<>\t') |
---|
1613 | n/a | self.assertEqual(display_name[0][0].comments, ['A']) |
---|
1614 | n/a | self.assertEqual(display_name[0][2].comments, ['in (my|your)']) |
---|
1615 | n/a | self.assertEqual(display_name.display_name, 'bird hand is messy') |
---|
1616 | n/a | |
---|
1617 | n/a | def test_get_display_name_obsolete(self): |
---|
1618 | n/a | display_name = self._test_get_x(parser.get_display_name, |
---|
1619 | n/a | 'Fred A.(weird).O Johnson', |
---|
1620 | n/a | 'Fred A.(weird).O Johnson', |
---|
1621 | n/a | '"Fred A. .O Johnson"', |
---|
1622 | n/a | [errors.ObsoleteHeaderDefect]*3, |
---|
1623 | n/a | '') |
---|
1624 | n/a | self.assertEqual(len(display_name), 7) |
---|
1625 | n/a | self.assertEqual(display_name[3].comments, ['weird']) |
---|
1626 | n/a | self.assertEqual(display_name.display_name, 'Fred A. .O Johnson') |
---|
1627 | n/a | |
---|
1628 | n/a | def test_get_display_name_pharse_must_start_with_word(self): |
---|
1629 | n/a | display_name = self._test_get_x(parser.get_display_name, |
---|
1630 | n/a | '(even weirder).name', |
---|
1631 | n/a | '(even weirder).name', |
---|
1632 | n/a | ' ".name"', |
---|
1633 | n/a | [errors.InvalidHeaderDefect] + [errors.ObsoleteHeaderDefect]*2, |
---|
1634 | n/a | '') |
---|
1635 | n/a | self.assertEqual(len(display_name), 3) |
---|
1636 | n/a | self.assertEqual(display_name[0].comments, ['even weirder']) |
---|
1637 | n/a | self.assertEqual(display_name.display_name, '.name') |
---|
1638 | n/a | |
---|
1639 | n/a | def test_get_display_name_ending_with_obsolete(self): |
---|
1640 | n/a | display_name = self._test_get_x(parser.get_display_name, |
---|
1641 | n/a | 'simple phrase.(with trailing comment):boo', |
---|
1642 | n/a | 'simple phrase.(with trailing comment)', |
---|
1643 | n/a | '"simple phrase." ', |
---|
1644 | n/a | [errors.ObsoleteHeaderDefect]*2, |
---|
1645 | n/a | ':boo') |
---|
1646 | n/a | self.assertEqual(len(display_name), 4) |
---|
1647 | n/a | self.assertEqual(display_name[3].comments, ['with trailing comment']) |
---|
1648 | n/a | self.assertEqual(display_name.display_name, 'simple phrase.') |
---|
1649 | n/a | |
---|
1650 | n/a | # get_name_addr |
---|
1651 | n/a | |
---|
1652 | n/a | def test_get_name_addr_angle_addr_only(self): |
---|
1653 | n/a | name_addr = self._test_get_x(parser.get_name_addr, |
---|
1654 | n/a | '<dinsdale@example.com>', |
---|
1655 | n/a | '<dinsdale@example.com>', |
---|
1656 | n/a | '<dinsdale@example.com>', |
---|
1657 | n/a | [], |
---|
1658 | n/a | '') |
---|
1659 | n/a | self.assertEqual(name_addr.token_type, 'name-addr') |
---|
1660 | n/a | self.assertIsNone(name_addr.display_name) |
---|
1661 | n/a | self.assertEqual(name_addr.local_part, 'dinsdale') |
---|
1662 | n/a | self.assertEqual(name_addr.domain, 'example.com') |
---|
1663 | n/a | self.assertIsNone(name_addr.route) |
---|
1664 | n/a | self.assertEqual(name_addr.addr_spec, 'dinsdale@example.com') |
---|
1665 | n/a | |
---|
1666 | n/a | def test_get_name_addr_atom_name(self): |
---|
1667 | n/a | name_addr = self._test_get_x(parser.get_name_addr, |
---|
1668 | n/a | 'Dinsdale <dinsdale@example.com>', |
---|
1669 | n/a | 'Dinsdale <dinsdale@example.com>', |
---|
1670 | n/a | 'Dinsdale <dinsdale@example.com>', |
---|
1671 | n/a | [], |
---|
1672 | n/a | '') |
---|
1673 | n/a | self.assertEqual(name_addr.token_type, 'name-addr') |
---|
1674 | n/a | self.assertEqual(name_addr.display_name, 'Dinsdale') |
---|
1675 | n/a | self.assertEqual(name_addr.local_part, 'dinsdale') |
---|
1676 | n/a | self.assertEqual(name_addr.domain, 'example.com') |
---|
1677 | n/a | self.assertIsNone(name_addr.route) |
---|
1678 | n/a | self.assertEqual(name_addr.addr_spec, 'dinsdale@example.com') |
---|
1679 | n/a | |
---|
1680 | n/a | def test_get_name_addr_atom_name_with_cfws(self): |
---|
1681 | n/a | name_addr = self._test_get_x(parser.get_name_addr, |
---|
1682 | n/a | '(foo) Dinsdale (bar) <dinsdale@example.com> (bird)', |
---|
1683 | n/a | '(foo) Dinsdale (bar) <dinsdale@example.com> (bird)', |
---|
1684 | n/a | ' Dinsdale <dinsdale@example.com> ', |
---|
1685 | n/a | [], |
---|
1686 | n/a | '') |
---|
1687 | n/a | self.assertEqual(name_addr.display_name, 'Dinsdale') |
---|
1688 | n/a | self.assertEqual(name_addr.local_part, 'dinsdale') |
---|
1689 | n/a | self.assertEqual(name_addr.domain, 'example.com') |
---|
1690 | n/a | self.assertIsNone(name_addr.route) |
---|
1691 | n/a | self.assertEqual(name_addr.addr_spec, 'dinsdale@example.com') |
---|
1692 | n/a | |
---|
1693 | n/a | def test_get_name_addr_name_with_cfws_and_dots(self): |
---|
1694 | n/a | name_addr = self._test_get_x(parser.get_name_addr, |
---|
1695 | n/a | '(foo) Roy.A.Bear (bar) <dinsdale@example.com> (bird)', |
---|
1696 | n/a | '(foo) Roy.A.Bear (bar) <dinsdale@example.com> (bird)', |
---|
1697 | n/a | ' "Roy.A.Bear" <dinsdale@example.com> ', |
---|
1698 | n/a | [errors.ObsoleteHeaderDefect]*2, |
---|
1699 | n/a | '') |
---|
1700 | n/a | self.assertEqual(name_addr.display_name, 'Roy.A.Bear') |
---|
1701 | n/a | self.assertEqual(name_addr.local_part, 'dinsdale') |
---|
1702 | n/a | self.assertEqual(name_addr.domain, 'example.com') |
---|
1703 | n/a | self.assertIsNone(name_addr.route) |
---|
1704 | n/a | self.assertEqual(name_addr.addr_spec, 'dinsdale@example.com') |
---|
1705 | n/a | |
---|
1706 | n/a | def test_get_name_addr_qs_name(self): |
---|
1707 | n/a | name_addr = self._test_get_x(parser.get_name_addr, |
---|
1708 | n/a | '"Roy.A.Bear" <dinsdale@example.com>', |
---|
1709 | n/a | '"Roy.A.Bear" <dinsdale@example.com>', |
---|
1710 | n/a | '"Roy.A.Bear" <dinsdale@example.com>', |
---|
1711 | n/a | [], |
---|
1712 | n/a | '') |
---|
1713 | n/a | self.assertEqual(name_addr.display_name, 'Roy.A.Bear') |
---|
1714 | n/a | self.assertEqual(name_addr.local_part, 'dinsdale') |
---|
1715 | n/a | self.assertEqual(name_addr.domain, 'example.com') |
---|
1716 | n/a | self.assertIsNone(name_addr.route) |
---|
1717 | n/a | self.assertEqual(name_addr.addr_spec, 'dinsdale@example.com') |
---|
1718 | n/a | |
---|
1719 | n/a | def test_get_name_addr_with_route(self): |
---|
1720 | n/a | name_addr = self._test_get_x(parser.get_name_addr, |
---|
1721 | n/a | '"Roy.A.Bear" <@two.example.com: dinsdale@example.com>', |
---|
1722 | n/a | '"Roy.A.Bear" <@two.example.com: dinsdale@example.com>', |
---|
1723 | n/a | '"Roy.A.Bear" <@two.example.com: dinsdale@example.com>', |
---|
1724 | n/a | [errors.ObsoleteHeaderDefect], |
---|
1725 | n/a | '') |
---|
1726 | n/a | self.assertEqual(name_addr.display_name, 'Roy.A.Bear') |
---|
1727 | n/a | self.assertEqual(name_addr.local_part, 'dinsdale') |
---|
1728 | n/a | self.assertEqual(name_addr.domain, 'example.com') |
---|
1729 | n/a | self.assertEqual(name_addr.route, ['two.example.com']) |
---|
1730 | n/a | self.assertEqual(name_addr.addr_spec, 'dinsdale@example.com') |
---|
1731 | n/a | |
---|
1732 | n/a | def test_get_name_addr_ends_at_special(self): |
---|
1733 | n/a | name_addr = self._test_get_x(parser.get_name_addr, |
---|
1734 | n/a | '"Roy.A.Bear" <dinsdale@example.com>, next', |
---|
1735 | n/a | '"Roy.A.Bear" <dinsdale@example.com>', |
---|
1736 | n/a | '"Roy.A.Bear" <dinsdale@example.com>', |
---|
1737 | n/a | [], |
---|
1738 | n/a | ', next') |
---|
1739 | n/a | self.assertEqual(name_addr.display_name, 'Roy.A.Bear') |
---|
1740 | n/a | self.assertEqual(name_addr.local_part, 'dinsdale') |
---|
1741 | n/a | self.assertEqual(name_addr.domain, 'example.com') |
---|
1742 | n/a | self.assertIsNone(name_addr.route) |
---|
1743 | n/a | self.assertEqual(name_addr.addr_spec, 'dinsdale@example.com') |
---|
1744 | n/a | |
---|
1745 | n/a | def test_get_name_addr_no_content_raises(self): |
---|
1746 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1747 | n/a | parser.get_name_addr(' (foo) ') |
---|
1748 | n/a | |
---|
1749 | n/a | def test_get_name_addr_no_content_before_special_raises(self): |
---|
1750 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1751 | n/a | parser.get_name_addr(' (foo) ,') |
---|
1752 | n/a | |
---|
1753 | n/a | def test_get_name_addr_no_angle_after_display_name_raises(self): |
---|
1754 | n/a | with self.assertRaises(errors.HeaderParseError): |
---|
1755 | n/a | parser.get_name_addr('foo bar') |
---|
1756 | n/a | |
---|
1757 | n/a | # get_mailbox |
---|
1758 | n/a | |
---|
1759 | n/a | def test_get_mailbox_addr_spec_only(self): |
---|
1760 | n/a | mailbox = self._test_get_x(parser.get_mailbox, |
---|
1761 | n/a | 'dinsdale@example.com', |
---|
1762 | n/a | 'dinsdale@example.com', |
---|
1763 | n/a | 'dinsdale@example.com', |
---|
1764 | n/a | [], |
---|
1765 | n/a | '') |
---|
1766 | n/a | self.assertEqual(mailbox.token_type, 'mailbox') |
---|
1767 | n/a | self.assertIsNone(mailbox.display_name) |
---|
1768 | n/a | self.assertEqual(mailbox.local_part, 'dinsdale') |
---|
1769 | n/a | self.assertEqual(mailbox.domain, 'example.com') |
---|
1770 | n/a | self.assertIsNone(mailbox.route) |
---|
1771 | n/a | self.assertEqual(mailbox.addr_spec, 'dinsdale@example.com') |
---|
1772 | n/a | |
---|
1773 | n/a | def test_get_mailbox_angle_addr_only(self): |
---|
1774 | n/a | mailbox = self._test_get_x(parser.get_mailbox, |
---|
1775 | n/a | '<dinsdale@example.com>', |
---|
1776 | n/a | '<dinsdale@example.com>', |
---|
1777 | n/a | '<dinsdale@example.com>', |
---|
1778 | n/a | [], |
---|
1779 | n/a | '') |
---|
1780 | n/a | self.assertEqual(mailbox.token_type, 'mailbox') |
---|
1781 | n/a | self.assertIsNone(mailbox.display_name) |
---|
1782 | n/a | self.assertEqual(mailbox.local_part, 'dinsdale') |
---|
1783 | n/a | self.assertEqual(mailbox.domain, 'example.com') |
---|
1784 | n/a | self.assertIsNone(mailbox.route) |
---|
1785 | n/a | self.assertEqual(mailbox.addr_spec, 'dinsdale@example.com') |
---|
1786 | n/a | |
---|
1787 | n/a | def test_get_mailbox_name_addr(self): |
---|
1788 | n/a | mailbox = self._test_get_x(parser.get_mailbox, |
---|
1789 | n/a | '"Roy A. Bear" <dinsdale@example.com>', |
---|
1790 | n/a | '"Roy A. Bear" <dinsdale@example.com>', |
---|
1791 | n/a | '"Roy A. Bear" <dinsdale@example.com>', |
---|
1792 | n/a | [], |
---|
1793 | n/a | '') |
---|
1794 | n/a | self.assertEqual(mailbox.token_type, 'mailbox') |
---|
1795 | n/a | self.assertEqual(mailbox.display_name, 'Roy A. Bear') |
---|
1796 | n/a | self.assertEqual(mailbox.local_part, 'dinsdale') |
---|
1797 | n/a | self.assertEqual(mailbox.domain, 'example.com') |
---|
1798 | n/a | self.assertIsNone(mailbox.route) |
---|
1799 | n/a | self.assertEqual(mailbox.addr_spec, 'dinsdale@example.com') |
---|
1800 | n/a | |
---|
1801 | n/a | def test_get_mailbox_ends_at_special(self): |
---|
1802 | n/a | mailbox = self._test_get_x(parser.get_mailbox, |
---|
1803 | n/a | '"Roy A. Bear" <dinsdale@example.com>, rest', |
---|
1804 | n/a | '"Roy A. Bear" <dinsdale@example.com>', |
---|
1805 | n/a | '"Roy A. Bear" <dinsdale@example.com>', |
---|
1806 | n/a | [], |
---|
1807 | n/a | ', rest') |
---|
1808 | n/a | self.assertEqual(mailbox.token_type, 'mailbox') |
---|
1809 | n/a | self.assertEqual(mailbox.display_name, 'Roy A. Bear') |
---|
1810 | n/a | self.assertEqual(mailbox.local_part, 'dinsdale') |
---|
1811 | n/a | self.assertEqual(mailbox.domain, 'example.com') |
---|
1812 | n/a | self.assertIsNone(mailbox.route) |
---|
1813 | n/a | self.assertEqual(mailbox.addr_spec, 'dinsdale@example.com') |
---|
1814 | n/a | |
---|
1815 | n/a | def test_get_mailbox_quoted_strings_in_atom_list(self): |
---|
1816 | n/a | mailbox = self._test_get_x(parser.get_mailbox, |
---|
1817 | n/a | '""example" example"@example.com', |
---|
1818 | n/a | '""example" example"@example.com', |
---|
1819 | n/a | 'example example@example.com', |
---|
1820 | n/a | [errors.InvalidHeaderDefect]*3, |
---|
1821 | n/a | '') |
---|
1822 | n/a | self.assertEqual(mailbox.local_part, 'example example') |
---|
1823 | n/a | self.assertEqual(mailbox.domain, 'example.com') |
---|
1824 | n/a | self.assertEqual(mailbox.addr_spec, '"example example"@example.com') |
---|
1825 | n/a | |
---|
1826 | n/a | # get_mailbox_list |
---|
1827 | n/a | |
---|
1828 | n/a | def test_get_mailbox_list_single_addr(self): |
---|
1829 | n/a | mailbox_list = self._test_get_x(parser.get_mailbox_list, |
---|
1830 | n/a | 'dinsdale@example.com', |
---|
1831 | n/a | 'dinsdale@example.com', |
---|
1832 | n/a | 'dinsdale@example.com', |
---|
1833 | n/a | [], |
---|
1834 | n/a | '') |
---|
1835 | n/a | self.assertEqual(mailbox_list.token_type, 'mailbox-list') |
---|
1836 | n/a | self.assertEqual(len(mailbox_list.mailboxes), 1) |
---|
1837 | n/a | mailbox = mailbox_list.mailboxes[0] |
---|
1838 | n/a | self.assertIsNone(mailbox.display_name) |
---|
1839 | n/a | self.assertEqual(mailbox.local_part, 'dinsdale') |
---|
1840 | n/a | self.assertEqual(mailbox.domain, 'example.com') |
---|
1841 | n/a | self.assertIsNone(mailbox.route) |
---|
1842 | n/a | self.assertEqual(mailbox.addr_spec, 'dinsdale@example.com') |
---|
1843 | n/a | self.assertEqual(mailbox_list.mailboxes, |
---|
1844 | n/a | mailbox_list.all_mailboxes) |
---|
1845 | n/a | |
---|
1846 | n/a | def test_get_mailbox_list_two_simple_addr(self): |
---|
1847 | n/a | mailbox_list = self._test_get_x(parser.get_mailbox_list, |
---|
1848 | n/a | 'dinsdale@example.com, dinsdale@test.example.com', |
---|
1849 | n/a | 'dinsdale@example.com, dinsdale@test.example.com', |
---|
1850 | n/a | 'dinsdale@example.com, dinsdale@test.example.com', |
---|
1851 | n/a | [], |
---|
1852 | n/a | '') |
---|
1853 | n/a | self.assertEqual(mailbox_list.token_type, 'mailbox-list') |
---|
1854 | n/a | self.assertEqual(len(mailbox_list.mailboxes), 2) |
---|
1855 | n/a | self.assertEqual(mailbox_list.mailboxes[0].addr_spec, |
---|
1856 | n/a | 'dinsdale@example.com') |
---|
1857 | n/a | self.assertEqual(mailbox_list.mailboxes[1].addr_spec, |
---|
1858 | n/a | 'dinsdale@test.example.com') |
---|
1859 | n/a | self.assertEqual(mailbox_list.mailboxes, |
---|
1860 | n/a | mailbox_list.all_mailboxes) |
---|
1861 | n/a | |
---|
1862 | n/a | def test_get_mailbox_list_two_name_addr(self): |
---|
1863 | n/a | mailbox_list = self._test_get_x(parser.get_mailbox_list, |
---|
1864 | n/a | ('"Roy A. Bear" <dinsdale@example.com>,' |
---|
1865 | n/a | ' "Fred Flintstone" <dinsdale@test.example.com>'), |
---|
1866 | n/a | ('"Roy A. Bear" <dinsdale@example.com>,' |
---|
1867 | n/a | ' "Fred Flintstone" <dinsdale@test.example.com>'), |
---|
1868 | n/a | ('"Roy A. Bear" <dinsdale@example.com>,' |
---|
1869 | n/a | ' "Fred Flintstone" <dinsdale@test.example.com>'), |
---|
1870 | n/a | [], |
---|
1871 | n/a | '') |
---|
1872 | n/a | self.assertEqual(len(mailbox_list.mailboxes), 2) |
---|
1873 | n/a | self.assertEqual(mailbox_list.mailboxes[0].addr_spec, |
---|
1874 | n/a | 'dinsdale@example.com') |
---|
1875 | n/a | self.assertEqual(mailbox_list.mailboxes[0].display_name, |
---|
1876 | n/a | 'Roy A. Bear') |
---|
1877 | n/a | self.assertEqual(mailbox_list.mailboxes[1].addr_spec, |
---|
1878 | n/a | 'dinsdale@test.example.com') |
---|
1879 | n/a | self.assertEqual(mailbox_list.mailboxes[1].display_name, |
---|
1880 | n/a | 'Fred Flintstone') |
---|
1881 | n/a | self.assertEqual(mailbox_list.mailboxes, |
---|
1882 | n/a | mailbox_list.all_mailboxes) |
---|
1883 | n/a | |
---|
1884 | n/a | def test_get_mailbox_list_two_complex(self): |
---|
1885 | n/a | mailbox_list = self._test_get_x(parser.get_mailbox_list, |
---|
1886 | n/a | ('(foo) "Roy A. Bear" <dinsdale@example.com>(bar),' |
---|
1887 | n/a | ' "Fred Flintstone" <dinsdale@test.(bird)example.com>'), |
---|
1888 | n/a | ('(foo) "Roy A. Bear" <dinsdale@example.com>(bar),' |
---|
1889 | n/a | ' "Fred Flintstone" <dinsdale@test.(bird)example.com>'), |
---|
1890 | n/a | (' "Roy A. Bear" <dinsdale@example.com> ,' |
---|
1891 | n/a | ' "Fred Flintstone" <dinsdale@test. example.com>'), |
---|
1892 | n/a | [errors.ObsoleteHeaderDefect], |
---|
1893 | n/a | '') |
---|
1894 | n/a | self.assertEqual(len(mailbox_list.mailboxes), 2) |
---|
1895 | n/a | self.assertEqual(mailbox_list.mailboxes[0].addr_spec, |
---|
1896 | n/a | 'dinsdale@example.com') |
---|
1897 | n/a | self.assertEqual(mailbox_list.mailboxes[0].display_name, |
---|
1898 | n/a | 'Roy A. Bear') |
---|
1899 | n/a | self.assertEqual(mailbox_list.mailboxes[1].addr_spec, |
---|
1900 | n/a | 'dinsdale@test.example.com') |
---|
1901 | n/a | self.assertEqual(mailbox_list.mailboxes[1].display_name, |
---|
1902 | n/a | 'Fred Flintstone') |
---|
1903 | n/a | self.assertEqual(mailbox_list.mailboxes, |
---|
1904 | n/a | mailbox_list.all_mailboxes) |
---|
1905 | n/a | |
---|
1906 | n/a | def test_get_mailbox_list_unparseable_mailbox_null(self): |
---|
1907 | n/a | mailbox_list = self._test_get_x(parser.get_mailbox_list, |
---|
1908 | n/a | ('"Roy A. Bear"[] dinsdale@example.com,' |
---|
1909 | n/a | ' "Fred Flintstone" <dinsdale@test.(bird)example.com>'), |
---|
1910 | n/a | ('"Roy A. Bear"[] dinsdale@example.com,' |
---|
1911 | n/a | ' "Fred Flintstone" <dinsdale@test.(bird)example.com>'), |
---|
1912 | n/a | ('"Roy A. Bear"[] dinsdale@example.com,' |
---|
1913 | n/a | ' "Fred Flintstone" <dinsdale@test. example.com>'), |
---|
1914 | n/a | [errors.InvalidHeaderDefect, # the 'extra' text after the local part |
---|
1915 | n/a | errors.InvalidHeaderDefect, # the local part with no angle-addr |
---|
1916 | n/a | errors.ObsoleteHeaderDefect, # period in extra text (example.com) |
---|
1917 | n/a | errors.ObsoleteHeaderDefect], # (bird) in valid address. |
---|
1918 | n/a | '') |
---|
1919 | n/a | self.assertEqual(len(mailbox_list.mailboxes), 1) |
---|
1920 | n/a | self.assertEqual(len(mailbox_list.all_mailboxes), 2) |
---|
1921 | n/a | self.assertEqual(mailbox_list.all_mailboxes[0].token_type, |
---|
1922 | n/a | 'invalid-mailbox') |
---|
1923 | n/a | self.assertIsNone(mailbox_list.all_mailboxes[0].display_name) |
---|
1924 | n/a | self.assertEqual(mailbox_list.all_mailboxes[0].local_part, |
---|
1925 | n/a | 'Roy A. Bear') |
---|
1926 | n/a | self.assertIsNone(mailbox_list.all_mailboxes[0].domain) |
---|
1927 | n/a | self.assertEqual(mailbox_list.all_mailboxes[0].addr_spec, |
---|
1928 | n/a | '"Roy A. Bear"') |
---|
1929 | n/a | self.assertIs(mailbox_list.all_mailboxes[1], |
---|
1930 | n/a | mailbox_list.mailboxes[0]) |
---|
1931 | n/a | self.assertEqual(mailbox_list.mailboxes[0].addr_spec, |
---|
1932 | n/a | 'dinsdale@test.example.com') |
---|
1933 | n/a | self.assertEqual(mailbox_list.mailboxes[0].display_name, |
---|
1934 | n/a | 'Fred Flintstone') |
---|
1935 | n/a | |
---|
1936 | n/a | def test_get_mailbox_list_junk_after_valid_address(self): |
---|
1937 | n/a | mailbox_list = self._test_get_x(parser.get_mailbox_list, |
---|
1938 | n/a | ('"Roy A. Bear" <dinsdale@example.com>@@,' |
---|
1939 | n/a | ' "Fred Flintstone" <dinsdale@test.example.com>'), |
---|
1940 | n/a | ('"Roy A. Bear" <dinsdale@example.com>@@,' |
---|
1941 | n/a | ' "Fred Flintstone" <dinsdale@test.example.com>'), |
---|
1942 | n/a | ('"Roy A. Bear" <dinsdale@example.com>@@,' |
---|
1943 | n/a | ' "Fred Flintstone" <dinsdale@test.example.com>'), |
---|
1944 | n/a | [errors.InvalidHeaderDefect], |
---|
1945 | n/a | '') |
---|
1946 | n/a | self.assertEqual(len(mailbox_list.mailboxes), 1) |
---|
1947 | n/a | self.assertEqual(len(mailbox_list.all_mailboxes), 2) |
---|
1948 | n/a | self.assertEqual(mailbox_list.all_mailboxes[0].addr_spec, |
---|
1949 | n/a | 'dinsdale@example.com') |
---|
1950 | n/a | self.assertEqual(mailbox_list.all_mailboxes[0].display_name, |
---|
1951 | n/a | 'Roy A. Bear') |
---|
1952 | n/a | self.assertEqual(mailbox_list.all_mailboxes[0].token_type, |
---|
1953 | n/a | 'invalid-mailbox') |
---|
1954 | n/a | self.assertIs(mailbox_list.all_mailboxes[1], |
---|
1955 | n/a | mailbox_list.mailboxes[0]) |
---|
1956 | n/a | self.assertEqual(mailbox_list.mailboxes[0].addr_spec, |
---|
1957 | n/a | 'dinsdale@test.example.com') |
---|
1958 | n/a | self.assertEqual(mailbox_list.mailboxes[0].display_name, |
---|
1959 | n/a | 'Fred Flintstone') |
---|
1960 | n/a | |
---|
1961 | n/a | def test_get_mailbox_list_empty_list_element(self): |
---|
1962 | n/a | mailbox_list = self._test_get_x(parser.get_mailbox_list, |
---|
1963 | n/a | ('"Roy A. Bear" <dinsdale@example.com>, (bird),,' |
---|
1964 | n/a | ' "Fred Flintstone" <dinsdale@test.example.com>'), |
---|
1965 | n/a | ('"Roy A. Bear" <dinsdale@example.com>, (bird),,' |
---|
1966 | n/a | ' "Fred Flintstone" <dinsdale@test.example.com>'), |
---|
1967 | n/a | ('"Roy A. Bear" <dinsdale@example.com>, ,,' |
---|
1968 | n/a | ' "Fred Flintstone" <dinsdale@test.example.com>'), |
---|
1969 | n/a | [errors.ObsoleteHeaderDefect]*2, |
---|
1970 | n/a | '') |
---|
1971 | n/a | self.assertEqual(len(mailbox_list.mailboxes), 2) |
---|
1972 | n/a | self.assertEqual(mailbox_list.all_mailboxes, |
---|
1973 | n/a | mailbox_list.mailboxes) |
---|
1974 | n/a | self.assertEqual(mailbox_list.all_mailboxes[0].addr_spec, |
---|
1975 | n/a | 'dinsdale@example.com') |
---|
1976 | n/a | self.assertEqual(mailbox_list.all_mailboxes[0].display_name, |
---|
1977 | n/a | 'Roy A. Bear') |
---|
1978 | n/a | self.assertEqual(mailbox_list.mailboxes[1].addr_spec, |
---|
1979 | n/a | 'dinsdale@test.example.com') |
---|
1980 | n/a | self.assertEqual(mailbox_list.mailboxes[1].display_name, |
---|
1981 | n/a | 'Fred Flintstone') |
---|
1982 | n/a | |
---|
1983 | n/a | def test_get_mailbox_list_only_empty_elements(self): |
---|
1984 | n/a | mailbox_list = self._test_get_x(parser.get_mailbox_list, |
---|
1985 | n/a | '(foo),, (bar)', |
---|
1986 | n/a | '(foo),, (bar)', |
---|
1987 | n/a | ' ,, ', |
---|
1988 | n/a | [errors.ObsoleteHeaderDefect]*3, |
---|
1989 | n/a | '') |
---|
1990 | n/a | self.assertEqual(len(mailbox_list.mailboxes), 0) |
---|
1991 | n/a | self.assertEqual(mailbox_list.all_mailboxes, |
---|
1992 | n/a | mailbox_list.mailboxes) |
---|
1993 | n/a | |
---|
1994 | n/a | # get_group_list |
---|
1995 | n/a | |
---|
1996 | n/a | def test_get_group_list_cfws_only(self): |
---|
1997 | n/a | group_list = self._test_get_x(parser.get_group_list, |
---|
1998 | n/a | '(hidden);', |
---|
1999 | n/a | '(hidden)', |
---|
2000 | n/a | ' ', |
---|
2001 | n/a | [], |
---|
2002 | n/a | ';') |
---|
2003 | n/a | self.assertEqual(group_list.token_type, 'group-list') |
---|
2004 | n/a | self.assertEqual(len(group_list.mailboxes), 0) |
---|
2005 | n/a | self.assertEqual(group_list.mailboxes, |
---|
2006 | n/a | group_list.all_mailboxes) |
---|
2007 | n/a | |
---|
2008 | n/a | def test_get_group_list_mailbox_list(self): |
---|
2009 | n/a | group_list = self._test_get_x(parser.get_group_list, |
---|
2010 | n/a | 'dinsdale@example.org, "Fred A. Bear" <dinsdale@example.org>', |
---|
2011 | n/a | 'dinsdale@example.org, "Fred A. Bear" <dinsdale@example.org>', |
---|
2012 | n/a | 'dinsdale@example.org, "Fred A. Bear" <dinsdale@example.org>', |
---|
2013 | n/a | [], |
---|
2014 | n/a | '') |
---|
2015 | n/a | self.assertEqual(group_list.token_type, 'group-list') |
---|
2016 | n/a | self.assertEqual(len(group_list.mailboxes), 2) |
---|
2017 | n/a | self.assertEqual(group_list.mailboxes, |
---|
2018 | n/a | group_list.all_mailboxes) |
---|
2019 | n/a | self.assertEqual(group_list.mailboxes[1].display_name, |
---|
2020 | n/a | 'Fred A. Bear') |
---|
2021 | n/a | |
---|
2022 | n/a | def test_get_group_list_obs_group_list(self): |
---|
2023 | n/a | group_list = self._test_get_x(parser.get_group_list, |
---|
2024 | n/a | ', (foo),,(bar)', |
---|
2025 | n/a | ', (foo),,(bar)', |
---|
2026 | n/a | ', ,, ', |
---|
2027 | n/a | [errors.ObsoleteHeaderDefect], |
---|
2028 | n/a | '') |
---|
2029 | n/a | self.assertEqual(group_list.token_type, 'group-list') |
---|
2030 | n/a | self.assertEqual(len(group_list.mailboxes), 0) |
---|
2031 | n/a | self.assertEqual(group_list.mailboxes, |
---|
2032 | n/a | group_list.all_mailboxes) |
---|
2033 | n/a | |
---|
2034 | n/a | def test_get_group_list_comment_only_invalid(self): |
---|
2035 | n/a | group_list = self._test_get_x(parser.get_group_list, |
---|
2036 | n/a | '(bar)', |
---|
2037 | n/a | '(bar)', |
---|
2038 | n/a | ' ', |
---|
2039 | n/a | [errors.InvalidHeaderDefect], |
---|
2040 | n/a | '') |
---|
2041 | n/a | self.assertEqual(group_list.token_type, 'group-list') |
---|
2042 | n/a | self.assertEqual(len(group_list.mailboxes), 0) |
---|
2043 | n/a | self.assertEqual(group_list.mailboxes, |
---|
2044 | n/a | group_list.all_mailboxes) |
---|
2045 | n/a | |
---|
2046 | n/a | # get_group |
---|
2047 | n/a | |
---|
2048 | n/a | def test_get_group_empty(self): |
---|
2049 | n/a | group = self._test_get_x(parser.get_group, |
---|
2050 | n/a | 'Monty Python:;', |
---|
2051 | n/a | 'Monty Python:;', |
---|
2052 | n/a | 'Monty Python:;', |
---|
2053 | n/a | [], |
---|
2054 | n/a | '') |
---|
2055 | n/a | self.assertEqual(group.token_type, 'group') |
---|
2056 | n/a | self.assertEqual(group.display_name, 'Monty Python') |
---|
2057 | n/a | self.assertEqual(len(group.mailboxes), 0) |
---|
2058 | n/a | self.assertEqual(group.mailboxes, |
---|
2059 | n/a | group.all_mailboxes) |
---|
2060 | n/a | |
---|
2061 | n/a | def test_get_group_null_addr_spec(self): |
---|
2062 | n/a | group = self._test_get_x(parser.get_group, |
---|
2063 | n/a | 'foo: <>;', |
---|
2064 | n/a | 'foo: <>;', |
---|
2065 | n/a | 'foo: <>;', |
---|
2066 | n/a | [errors.InvalidHeaderDefect], |
---|
2067 | n/a | '') |
---|
2068 | n/a | self.assertEqual(group.display_name, 'foo') |
---|
2069 | n/a | self.assertEqual(len(group.mailboxes), 0) |
---|
2070 | n/a | self.assertEqual(len(group.all_mailboxes), 1) |
---|
2071 | n/a | self.assertEqual(group.all_mailboxes[0].value, '<>') |
---|
2072 | n/a | |
---|
2073 | n/a | def test_get_group_cfws_only(self): |
---|
2074 | n/a | group = self._test_get_x(parser.get_group, |
---|
2075 | n/a | 'Monty Python: (hidden);', |
---|
2076 | n/a | 'Monty Python: (hidden);', |
---|
2077 | n/a | 'Monty Python: ;', |
---|
2078 | n/a | [], |
---|
2079 | n/a | '') |
---|
2080 | n/a | self.assertEqual(group.token_type, 'group') |
---|
2081 | n/a | self.assertEqual(group.display_name, 'Monty Python') |
---|
2082 | n/a | self.assertEqual(len(group.mailboxes), 0) |
---|
2083 | n/a | self.assertEqual(group.mailboxes, |
---|
2084 | n/a | group.all_mailboxes) |
---|
2085 | n/a | |
---|
2086 | n/a | def test_get_group_single_mailbox(self): |
---|
2087 | n/a | group = self._test_get_x(parser.get_group, |
---|
2088 | n/a | 'Monty Python: "Fred A. Bear" <dinsdale@example.com>;', |
---|
2089 | n/a | 'Monty Python: "Fred A. Bear" <dinsdale@example.com>;', |
---|
2090 | n/a | 'Monty Python: "Fred A. Bear" <dinsdale@example.com>;', |
---|
2091 | n/a | [], |
---|
2092 | n/a | '') |
---|
2093 | n/a | self.assertEqual(group.token_type, 'group') |
---|
2094 | n/a | self.assertEqual(group.display_name, 'Monty Python') |
---|
2095 | n/a | self.assertEqual(len(group.mailboxes), 1) |
---|
2096 | n/a | self.assertEqual(group.mailboxes, |
---|
2097 | n/a | group.all_mailboxes) |
---|
2098 | n/a | self.assertEqual(group.mailboxes[0].addr_spec, |
---|
2099 | n/a | 'dinsdale@example.com') |
---|
2100 | n/a | |
---|
2101 | n/a | def test_get_group_mixed_list(self): |
---|
2102 | n/a | group = self._test_get_x(parser.get_group, |
---|
2103 | n/a | ('Monty Python: "Fred A. Bear" <dinsdale@example.com>,' |
---|
2104 | n/a | '(foo) Roger <ping@exampele.com>, x@test.example.com;'), |
---|
2105 | n/a | ('Monty Python: "Fred A. Bear" <dinsdale@example.com>,' |
---|
2106 | n/a | '(foo) Roger <ping@exampele.com>, x@test.example.com;'), |
---|
2107 | n/a | ('Monty Python: "Fred A. Bear" <dinsdale@example.com>,' |
---|
2108 | n/a | ' Roger <ping@exampele.com>, x@test.example.com;'), |
---|
2109 | n/a | [], |
---|
2110 | n/a | '') |
---|
2111 | n/a | self.assertEqual(group.token_type, 'group') |
---|
2112 | n/a | self.assertEqual(group.display_name, 'Monty Python') |
---|
2113 | n/a | self.assertEqual(len(group.mailboxes), 3) |
---|
2114 | n/a | self.assertEqual(group.mailboxes, |
---|
2115 | n/a | group.all_mailboxes) |
---|
2116 | n/a | self.assertEqual(group.mailboxes[0].display_name, |
---|
2117 | n/a | 'Fred A. Bear') |
---|
2118 | n/a | self.assertEqual(group.mailboxes[1].display_name, |
---|
2119 | n/a | 'Roger') |
---|
2120 | n/a | self.assertEqual(group.mailboxes[2].local_part, 'x') |
---|
2121 | n/a | |
---|
2122 | n/a | def test_get_group_one_invalid(self): |
---|
2123 | n/a | group = self._test_get_x(parser.get_group, |
---|
2124 | n/a | ('Monty Python: "Fred A. Bear" <dinsdale@example.com>,' |
---|
2125 | n/a | '(foo) Roger ping@exampele.com, x@test.example.com;'), |
---|
2126 | n/a | ('Monty Python: "Fred A. Bear" <dinsdale@example.com>,' |
---|
2127 | n/a | '(foo) Roger ping@exampele.com, x@test.example.com;'), |
---|
2128 | n/a | ('Monty Python: "Fred A. Bear" <dinsdale@example.com>,' |
---|
2129 | n/a | ' Roger ping@exampele.com, x@test.example.com;'), |
---|
2130 | n/a | [errors.InvalidHeaderDefect, # non-angle addr makes local part invalid |
---|
2131 | n/a | errors.InvalidHeaderDefect], # and its not obs-local either: no dots. |
---|
2132 | n/a | '') |
---|
2133 | n/a | self.assertEqual(group.token_type, 'group') |
---|
2134 | n/a | self.assertEqual(group.display_name, 'Monty Python') |
---|
2135 | n/a | self.assertEqual(len(group.mailboxes), 2) |
---|
2136 | n/a | self.assertEqual(len(group.all_mailboxes), 3) |
---|
2137 | n/a | self.assertEqual(group.mailboxes[0].display_name, |
---|
2138 | n/a | 'Fred A. Bear') |
---|
2139 | n/a | self.assertEqual(group.mailboxes[1].local_part, 'x') |
---|
2140 | n/a | self.assertIsNone(group.all_mailboxes[1].display_name) |
---|
2141 | n/a | |
---|
2142 | n/a | # get_address |
---|
2143 | n/a | |
---|
2144 | n/a | def test_get_address_simple(self): |
---|
2145 | n/a | address = self._test_get_x(parser.get_address, |
---|
2146 | n/a | 'dinsdale@example.com', |
---|
2147 | n/a | 'dinsdale@example.com', |
---|
2148 | n/a | 'dinsdale@example.com', |
---|
2149 | n/a | [], |
---|
2150 | n/a | '') |
---|
2151 | n/a | self.assertEqual(address.token_type, 'address') |
---|
2152 | n/a | self.assertEqual(len(address.mailboxes), 1) |
---|
2153 | n/a | self.assertEqual(address.mailboxes, |
---|
2154 | n/a | address.all_mailboxes) |
---|
2155 | n/a | self.assertEqual(address.mailboxes[0].domain, |
---|
2156 | n/a | 'example.com') |
---|
2157 | n/a | self.assertEqual(address[0].token_type, |
---|
2158 | n/a | 'mailbox') |
---|
2159 | n/a | |
---|
2160 | n/a | def test_get_address_complex(self): |
---|
2161 | n/a | address = self._test_get_x(parser.get_address, |
---|
2162 | n/a | '(foo) "Fred A. Bear" <(bird)dinsdale@example.com>', |
---|
2163 | n/a | '(foo) "Fred A. Bear" <(bird)dinsdale@example.com>', |
---|
2164 | n/a | ' "Fred A. Bear" < dinsdale@example.com>', |
---|
2165 | n/a | [], |
---|
2166 | n/a | '') |
---|
2167 | n/a | self.assertEqual(address.token_type, 'address') |
---|
2168 | n/a | self.assertEqual(len(address.mailboxes), 1) |
---|
2169 | n/a | self.assertEqual(address.mailboxes, |
---|
2170 | n/a | address.all_mailboxes) |
---|
2171 | n/a | self.assertEqual(address.mailboxes[0].display_name, |
---|
2172 | n/a | 'Fred A. Bear') |
---|
2173 | n/a | self.assertEqual(address[0].token_type, |
---|
2174 | n/a | 'mailbox') |
---|
2175 | n/a | |
---|
2176 | n/a | def test_get_address_rfc2047_display_name(self): |
---|
2177 | n/a | address = self._test_get_x(parser.get_address, |
---|
2178 | n/a | '=?utf-8?q?=C3=89ric?= <foo@example.com>', |
---|
2179 | n/a | 'Ãric <foo@example.com>', |
---|
2180 | n/a | 'Ãric <foo@example.com>', |
---|
2181 | n/a | [], |
---|
2182 | n/a | '') |
---|
2183 | n/a | self.assertEqual(address.token_type, 'address') |
---|
2184 | n/a | self.assertEqual(len(address.mailboxes), 1) |
---|
2185 | n/a | self.assertEqual(address.mailboxes, |
---|
2186 | n/a | address.all_mailboxes) |
---|
2187 | n/a | self.assertEqual(address.mailboxes[0].display_name, |
---|
2188 | n/a | 'Ãric') |
---|
2189 | n/a | self.assertEqual(address[0].token_type, |
---|
2190 | n/a | 'mailbox') |
---|
2191 | n/a | |
---|
2192 | n/a | def test_get_address_empty_group(self): |
---|
2193 | n/a | address = self._test_get_x(parser.get_address, |
---|
2194 | n/a | 'Monty Python:;', |
---|
2195 | n/a | 'Monty Python:;', |
---|
2196 | n/a | 'Monty Python:;', |
---|
2197 | n/a | [], |
---|
2198 | n/a | '') |
---|
2199 | n/a | self.assertEqual(address.token_type, 'address') |
---|
2200 | n/a | self.assertEqual(len(address.mailboxes), 0) |
---|
2201 | n/a | self.assertEqual(address.mailboxes, |
---|
2202 | n/a | address.all_mailboxes) |
---|
2203 | n/a | self.assertEqual(address[0].token_type, |
---|
2204 | n/a | 'group') |
---|
2205 | n/a | self.assertEqual(address[0].display_name, |
---|
2206 | n/a | 'Monty Python') |
---|
2207 | n/a | |
---|
2208 | n/a | def test_get_address_group(self): |
---|
2209 | n/a | address = self._test_get_x(parser.get_address, |
---|
2210 | n/a | 'Monty Python: x@example.com, y@example.com;', |
---|
2211 | n/a | 'Monty Python: x@example.com, y@example.com;', |
---|
2212 | n/a | 'Monty Python: x@example.com, y@example.com;', |
---|
2213 | n/a | [], |
---|
2214 | n/a | '') |
---|
2215 | n/a | self.assertEqual(address.token_type, 'address') |
---|
2216 | n/a | self.assertEqual(len(address.mailboxes), 2) |
---|
2217 | n/a | self.assertEqual(address.mailboxes, |
---|
2218 | n/a | address.all_mailboxes) |
---|
2219 | n/a | self.assertEqual(address[0].token_type, |
---|
2220 | n/a | 'group') |
---|
2221 | n/a | self.assertEqual(address[0].display_name, |
---|
2222 | n/a | 'Monty Python') |
---|
2223 | n/a | self.assertEqual(address.mailboxes[0].local_part, 'x') |
---|
2224 | n/a | |
---|
2225 | n/a | def test_get_address_quoted_local_part(self): |
---|
2226 | n/a | address = self._test_get_x(parser.get_address, |
---|
2227 | n/a | '"foo bar"@example.com', |
---|
2228 | n/a | '"foo bar"@example.com', |
---|
2229 | n/a | '"foo bar"@example.com', |
---|
2230 | n/a | [], |
---|
2231 | n/a | '') |
---|
2232 | n/a | self.assertEqual(address.token_type, 'address') |
---|
2233 | n/a | self.assertEqual(len(address.mailboxes), 1) |
---|
2234 | n/a | self.assertEqual(address.mailboxes, |
---|
2235 | n/a | address.all_mailboxes) |
---|
2236 | n/a | self.assertEqual(address.mailboxes[0].domain, |
---|
2237 | n/a | 'example.com') |
---|
2238 | n/a | self.assertEqual(address.mailboxes[0].local_part, |
---|
2239 | n/a | 'foo bar') |
---|
2240 | n/a | self.assertEqual(address[0].token_type, 'mailbox') |
---|
2241 | n/a | |
---|
2242 | n/a | def test_get_address_ends_at_special(self): |
---|
2243 | n/a | address = self._test_get_x(parser.get_address, |
---|
2244 | n/a | 'dinsdale@example.com, next', |
---|
2245 | n/a | 'dinsdale@example.com', |
---|
2246 | n/a | 'dinsdale@example.com', |
---|
2247 | n/a | [], |
---|
2248 | n/a | ', next') |
---|
2249 | n/a | self.assertEqual(address.token_type, 'address') |
---|
2250 | n/a | self.assertEqual(len(address.mailboxes), 1) |
---|
2251 | n/a | self.assertEqual(address.mailboxes, |
---|
2252 | n/a | address.all_mailboxes) |
---|
2253 | n/a | self.assertEqual(address.mailboxes[0].domain, |
---|
2254 | n/a | 'example.com') |
---|
2255 | n/a | self.assertEqual(address[0].token_type, 'mailbox') |
---|
2256 | n/a | |
---|
2257 | n/a | def test_get_address_invalid_mailbox_invalid(self): |
---|
2258 | n/a | address = self._test_get_x(parser.get_address, |
---|
2259 | n/a | 'ping example.com, next', |
---|
2260 | n/a | 'ping example.com', |
---|
2261 | n/a | 'ping example.com', |
---|
2262 | n/a | [errors.InvalidHeaderDefect, # addr-spec with no domain |
---|
2263 | n/a | errors.InvalidHeaderDefect, # invalid local-part |
---|
2264 | n/a | errors.InvalidHeaderDefect, # missing .s in local-part |
---|
2265 | n/a | ], |
---|
2266 | n/a | ', next') |
---|
2267 | n/a | self.assertEqual(address.token_type, 'address') |
---|
2268 | n/a | self.assertEqual(len(address.mailboxes), 0) |
---|
2269 | n/a | self.assertEqual(len(address.all_mailboxes), 1) |
---|
2270 | n/a | self.assertIsNone(address.all_mailboxes[0].domain) |
---|
2271 | n/a | self.assertEqual(address.all_mailboxes[0].local_part, 'ping example.com') |
---|
2272 | n/a | self.assertEqual(address[0].token_type, 'invalid-mailbox') |
---|
2273 | n/a | |
---|
2274 | n/a | def test_get_address_quoted_strings_in_atom_list(self): |
---|
2275 | n/a | address = self._test_get_x(parser.get_address, |
---|
2276 | n/a | '""example" example"@example.com', |
---|
2277 | n/a | '""example" example"@example.com', |
---|
2278 | n/a | 'example example@example.com', |
---|
2279 | n/a | [errors.InvalidHeaderDefect]*3, |
---|
2280 | n/a | '') |
---|
2281 | n/a | self.assertEqual(address.all_mailboxes[0].local_part, 'example example') |
---|
2282 | n/a | self.assertEqual(address.all_mailboxes[0].domain, 'example.com') |
---|
2283 | n/a | self.assertEqual(address.all_mailboxes[0].addr_spec, '"example example"@example.com') |
---|
2284 | n/a | |
---|
2285 | n/a | |
---|
2286 | n/a | # get_address_list |
---|
2287 | n/a | |
---|
2288 | n/a | def test_get_address_list_mailboxes_simple(self): |
---|
2289 | n/a | address_list = self._test_get_x(parser.get_address_list, |
---|
2290 | n/a | 'dinsdale@example.com', |
---|
2291 | n/a | 'dinsdale@example.com', |
---|
2292 | n/a | 'dinsdale@example.com', |
---|
2293 | n/a | [], |
---|
2294 | n/a | '') |
---|
2295 | n/a | self.assertEqual(address_list.token_type, 'address-list') |
---|
2296 | n/a | self.assertEqual(len(address_list.mailboxes), 1) |
---|
2297 | n/a | self.assertEqual(address_list.mailboxes, |
---|
2298 | n/a | address_list.all_mailboxes) |
---|
2299 | n/a | self.assertEqual([str(x) for x in address_list.mailboxes], |
---|
2300 | n/a | [str(x) for x in address_list.addresses]) |
---|
2301 | n/a | self.assertEqual(address_list.mailboxes[0].domain, 'example.com') |
---|
2302 | n/a | self.assertEqual(address_list[0].token_type, 'address') |
---|
2303 | n/a | self.assertIsNone(address_list[0].display_name) |
---|
2304 | n/a | |
---|
2305 | n/a | def test_get_address_list_mailboxes_two_simple(self): |
---|
2306 | n/a | address_list = self._test_get_x(parser.get_address_list, |
---|
2307 | n/a | 'foo@example.com, "Fred A. Bar" <bar@example.com>', |
---|
2308 | n/a | 'foo@example.com, "Fred A. Bar" <bar@example.com>', |
---|
2309 | n/a | 'foo@example.com, "Fred A. Bar" <bar@example.com>', |
---|
2310 | n/a | [], |
---|
2311 | n/a | '') |
---|
2312 | n/a | self.assertEqual(address_list.token_type, 'address-list') |
---|
2313 | n/a | self.assertEqual(len(address_list.mailboxes), 2) |
---|
2314 | n/a | self.assertEqual(address_list.mailboxes, |
---|
2315 | n/a | address_list.all_mailboxes) |
---|
2316 | n/a | self.assertEqual([str(x) for x in address_list.mailboxes], |
---|
2317 | n/a | [str(x) for x in address_list.addresses]) |
---|
2318 | n/a | self.assertEqual(address_list.mailboxes[0].local_part, 'foo') |
---|
2319 | n/a | self.assertEqual(address_list.mailboxes[1].display_name, "Fred A. Bar") |
---|
2320 | n/a | |
---|
2321 | n/a | def test_get_address_list_mailboxes_complex(self): |
---|
2322 | n/a | address_list = self._test_get_x(parser.get_address_list, |
---|
2323 | n/a | ('"Roy A. Bear" <dinsdale@example.com>, ' |
---|
2324 | n/a | '(ping) Foo <x@example.com>,' |
---|
2325 | n/a | 'Nobody Is. Special <y@(bird)example.(bad)com>'), |
---|
2326 | n/a | ('"Roy A. Bear" <dinsdale@example.com>, ' |
---|
2327 | n/a | '(ping) Foo <x@example.com>,' |
---|
2328 | n/a | 'Nobody Is. Special <y@(bird)example.(bad)com>'), |
---|
2329 | n/a | ('"Roy A. Bear" <dinsdale@example.com>, ' |
---|
2330 | n/a | 'Foo <x@example.com>,' |
---|
2331 | n/a | '"Nobody Is. Special" <y@example. com>'), |
---|
2332 | n/a | [errors.ObsoleteHeaderDefect, # period in Is. |
---|
2333 | n/a | errors.ObsoleteHeaderDefect], # cfws in domain |
---|
2334 | n/a | '') |
---|
2335 | n/a | self.assertEqual(address_list.token_type, 'address-list') |
---|
2336 | n/a | self.assertEqual(len(address_list.mailboxes), 3) |
---|
2337 | n/a | self.assertEqual(address_list.mailboxes, |
---|
2338 | n/a | address_list.all_mailboxes) |
---|
2339 | n/a | self.assertEqual([str(x) for x in address_list.mailboxes], |
---|
2340 | n/a | [str(x) for x in address_list.addresses]) |
---|
2341 | n/a | self.assertEqual(address_list.mailboxes[0].domain, 'example.com') |
---|
2342 | n/a | self.assertEqual(address_list.mailboxes[0].token_type, 'mailbox') |
---|
2343 | n/a | self.assertEqual(address_list.addresses[0].token_type, 'address') |
---|
2344 | n/a | self.assertEqual(address_list.mailboxes[1].local_part, 'x') |
---|
2345 | n/a | self.assertEqual(address_list.mailboxes[2].display_name, |
---|
2346 | n/a | 'Nobody Is. Special') |
---|
2347 | n/a | |
---|
2348 | n/a | def test_get_address_list_mailboxes_invalid_addresses(self): |
---|
2349 | n/a | address_list = self._test_get_x(parser.get_address_list, |
---|
2350 | n/a | ('"Roy A. Bear" <dinsdale@example.com>, ' |
---|
2351 | n/a | '(ping) Foo x@example.com[],' |
---|
2352 | n/a | 'Nobody Is. Special <(bird)example.(bad)com>'), |
---|
2353 | n/a | ('"Roy A. Bear" <dinsdale@example.com>, ' |
---|
2354 | n/a | '(ping) Foo x@example.com[],' |
---|
2355 | n/a | 'Nobody Is. Special <(bird)example.(bad)com>'), |
---|
2356 | n/a | ('"Roy A. Bear" <dinsdale@example.com>, ' |
---|
2357 | n/a | 'Foo x@example.com[],' |
---|
2358 | n/a | '"Nobody Is. Special" < example. com>'), |
---|
2359 | n/a | [errors.InvalidHeaderDefect, # invalid address in list |
---|
2360 | n/a | errors.InvalidHeaderDefect, # 'Foo x' local part invalid. |
---|
2361 | n/a | errors.InvalidHeaderDefect, # Missing . in 'Foo x' local part |
---|
2362 | n/a | errors.ObsoleteHeaderDefect, # period in 'Is.' disp-name phrase |
---|
2363 | n/a | errors.InvalidHeaderDefect, # no domain part in addr-spec |
---|
2364 | n/a | errors.ObsoleteHeaderDefect], # addr-spec has comment in it |
---|
2365 | n/a | '') |
---|
2366 | n/a | self.assertEqual(address_list.token_type, 'address-list') |
---|
2367 | n/a | self.assertEqual(len(address_list.mailboxes), 1) |
---|
2368 | n/a | self.assertEqual(len(address_list.all_mailboxes), 3) |
---|
2369 | n/a | self.assertEqual([str(x) for x in address_list.all_mailboxes], |
---|
2370 | n/a | [str(x) for x in address_list.addresses]) |
---|
2371 | n/a | self.assertEqual(address_list.mailboxes[0].domain, 'example.com') |
---|
2372 | n/a | self.assertEqual(address_list.mailboxes[0].token_type, 'mailbox') |
---|
2373 | n/a | self.assertEqual(address_list.addresses[0].token_type, 'address') |
---|
2374 | n/a | self.assertEqual(address_list.addresses[1].token_type, 'address') |
---|
2375 | n/a | self.assertEqual(len(address_list.addresses[0].mailboxes), 1) |
---|
2376 | n/a | self.assertEqual(len(address_list.addresses[1].mailboxes), 0) |
---|
2377 | n/a | self.assertEqual(len(address_list.addresses[1].mailboxes), 0) |
---|
2378 | n/a | self.assertEqual( |
---|
2379 | n/a | address_list.addresses[1].all_mailboxes[0].local_part, 'Foo x') |
---|
2380 | n/a | self.assertEqual( |
---|
2381 | n/a | address_list.addresses[2].all_mailboxes[0].display_name, |
---|
2382 | n/a | "Nobody Is. Special") |
---|
2383 | n/a | |
---|
2384 | n/a | def test_get_address_list_group_empty(self): |
---|
2385 | n/a | address_list = self._test_get_x(parser.get_address_list, |
---|
2386 | n/a | 'Monty Python: ;', |
---|
2387 | n/a | 'Monty Python: ;', |
---|
2388 | n/a | 'Monty Python: ;', |
---|
2389 | n/a | [], |
---|
2390 | n/a | '') |
---|
2391 | n/a | self.assertEqual(address_list.token_type, 'address-list') |
---|
2392 | n/a | self.assertEqual(len(address_list.mailboxes), 0) |
---|
2393 | n/a | self.assertEqual(address_list.mailboxes, |
---|
2394 | n/a | address_list.all_mailboxes) |
---|
2395 | n/a | self.assertEqual(len(address_list.addresses), 1) |
---|
2396 | n/a | self.assertEqual(address_list.addresses[0].token_type, 'address') |
---|
2397 | n/a | self.assertEqual(address_list.addresses[0].display_name, 'Monty Python') |
---|
2398 | n/a | self.assertEqual(len(address_list.addresses[0].mailboxes), 0) |
---|
2399 | n/a | |
---|
2400 | n/a | def test_get_address_list_group_simple(self): |
---|
2401 | n/a | address_list = self._test_get_x(parser.get_address_list, |
---|
2402 | n/a | 'Monty Python: dinsdale@example.com;', |
---|
2403 | n/a | 'Monty Python: dinsdale@example.com;', |
---|
2404 | n/a | 'Monty Python: dinsdale@example.com;', |
---|
2405 | n/a | [], |
---|
2406 | n/a | '') |
---|
2407 | n/a | self.assertEqual(address_list.token_type, 'address-list') |
---|
2408 | n/a | self.assertEqual(len(address_list.mailboxes), 1) |
---|
2409 | n/a | self.assertEqual(address_list.mailboxes, |
---|
2410 | n/a | address_list.all_mailboxes) |
---|
2411 | n/a | self.assertEqual(address_list.mailboxes[0].domain, 'example.com') |
---|
2412 | n/a | self.assertEqual(address_list.addresses[0].display_name, |
---|
2413 | n/a | 'Monty Python') |
---|
2414 | n/a | self.assertEqual(address_list.addresses[0].mailboxes[0].domain, |
---|
2415 | n/a | 'example.com') |
---|
2416 | n/a | |
---|
2417 | n/a | def test_get_address_list_group_and_mailboxes(self): |
---|
2418 | n/a | address_list = self._test_get_x(parser.get_address_list, |
---|
2419 | n/a | ('Monty Python: dinsdale@example.com, "Fred" <flint@example.com>;, ' |
---|
2420 | n/a | 'Abe <x@example.com>, Bee <y@example.com>'), |
---|
2421 | n/a | ('Monty Python: dinsdale@example.com, "Fred" <flint@example.com>;, ' |
---|
2422 | n/a | 'Abe <x@example.com>, Bee <y@example.com>'), |
---|
2423 | n/a | ('Monty Python: dinsdale@example.com, "Fred" <flint@example.com>;, ' |
---|
2424 | n/a | 'Abe <x@example.com>, Bee <y@example.com>'), |
---|
2425 | n/a | [], |
---|
2426 | n/a | '') |
---|
2427 | n/a | self.assertEqual(address_list.token_type, 'address-list') |
---|
2428 | n/a | self.assertEqual(len(address_list.mailboxes), 4) |
---|
2429 | n/a | self.assertEqual(address_list.mailboxes, |
---|
2430 | n/a | address_list.all_mailboxes) |
---|
2431 | n/a | self.assertEqual(len(address_list.addresses), 3) |
---|
2432 | n/a | self.assertEqual(address_list.mailboxes[0].local_part, 'dinsdale') |
---|
2433 | n/a | self.assertEqual(address_list.addresses[0].display_name, |
---|
2434 | n/a | 'Monty Python') |
---|
2435 | n/a | self.assertEqual(address_list.addresses[0].mailboxes[0].domain, |
---|
2436 | n/a | 'example.com') |
---|
2437 | n/a | self.assertEqual(address_list.addresses[0].mailboxes[1].local_part, |
---|
2438 | n/a | 'flint') |
---|
2439 | n/a | self.assertEqual(address_list.addresses[1].mailboxes[0].local_part, |
---|
2440 | n/a | 'x') |
---|
2441 | n/a | self.assertEqual(address_list.addresses[2].mailboxes[0].local_part, |
---|
2442 | n/a | 'y') |
---|
2443 | n/a | self.assertEqual(str(address_list.addresses[1]), |
---|
2444 | n/a | str(address_list.mailboxes[2])) |
---|
2445 | n/a | |
---|
2446 | n/a | def test_invalid_content_disposition(self): |
---|
2447 | n/a | content_disp = self._test_parse_x( |
---|
2448 | n/a | parser.parse_content_disposition_header, |
---|
2449 | n/a | ";attachment", "; attachment", ";attachment", |
---|
2450 | n/a | [errors.InvalidHeaderDefect]*2 |
---|
2451 | n/a | ) |
---|
2452 | n/a | |
---|
2453 | n/a | def test_invalid_content_transfer_encoding(self): |
---|
2454 | n/a | cte = self._test_parse_x( |
---|
2455 | n/a | parser.parse_content_transfer_encoding_header, |
---|
2456 | n/a | ";foo", ";foo", ";foo", [errors.InvalidHeaderDefect]*3 |
---|
2457 | n/a | ) |
---|
2458 | n/a | |
---|
2459 | n/a | |
---|
2460 | n/a | @parameterize |
---|
2461 | n/a | class Test_parse_mime_parameters(TestParserMixin, TestEmailBase): |
---|
2462 | n/a | |
---|
2463 | n/a | def mime_parameters_as_value(self, |
---|
2464 | n/a | value, |
---|
2465 | n/a | tl_str, |
---|
2466 | n/a | tl_value, |
---|
2467 | n/a | params, |
---|
2468 | n/a | defects): |
---|
2469 | n/a | mime_parameters = self._test_parse_x(parser.parse_mime_parameters, |
---|
2470 | n/a | value, tl_str, tl_value, defects) |
---|
2471 | n/a | self.assertEqual(mime_parameters.token_type, 'mime-parameters') |
---|
2472 | n/a | self.assertEqual(list(mime_parameters.params), params) |
---|
2473 | n/a | |
---|
2474 | n/a | |
---|
2475 | n/a | mime_parameters_params = { |
---|
2476 | n/a | |
---|
2477 | n/a | 'simple': ( |
---|
2478 | n/a | 'filename="abc.py"', |
---|
2479 | n/a | ' filename="abc.py"', |
---|
2480 | n/a | 'filename=abc.py', |
---|
2481 | n/a | [('filename', 'abc.py')], |
---|
2482 | n/a | []), |
---|
2483 | n/a | |
---|
2484 | n/a | 'multiple_keys': ( |
---|
2485 | n/a | 'filename="abc.py"; xyz=abc', |
---|
2486 | n/a | ' filename="abc.py"; xyz="abc"', |
---|
2487 | n/a | 'filename=abc.py; xyz=abc', |
---|
2488 | n/a | [('filename', 'abc.py'), ('xyz', 'abc')], |
---|
2489 | n/a | []), |
---|
2490 | n/a | |
---|
2491 | n/a | 'split_value': ( |
---|
2492 | n/a | "filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66", |
---|
2493 | n/a | ' filename="201.tif"', |
---|
2494 | n/a | "filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66", |
---|
2495 | n/a | [('filename', '201.tif')], |
---|
2496 | n/a | []), |
---|
2497 | n/a | |
---|
2498 | n/a | # Note that it is undefined what we should do for error recovery when |
---|
2499 | n/a | # there are duplicate parameter names or duplicate parts in a split |
---|
2500 | n/a | # part. We choose to ignore all duplicate parameters after the first |
---|
2501 | n/a | # and to take duplicate or missing rfc 2231 parts in appearance order. |
---|
2502 | n/a | # This is backward compatible with get_param's behavior, but the |
---|
2503 | n/a | # decisions are arbitrary. |
---|
2504 | n/a | |
---|
2505 | n/a | 'duplicate_key': ( |
---|
2506 | n/a | 'filename=abc.gif; filename=def.tiff', |
---|
2507 | n/a | ' filename="abc.gif"', |
---|
2508 | n/a | "filename=abc.gif; filename=def.tiff", |
---|
2509 | n/a | [('filename', 'abc.gif')], |
---|
2510 | n/a | [errors.InvalidHeaderDefect]), |
---|
2511 | n/a | |
---|
2512 | n/a | 'duplicate_key_with_split_value': ( |
---|
2513 | n/a | "filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66;" |
---|
2514 | n/a | " filename=abc.gif", |
---|
2515 | n/a | ' filename="201.tif"', |
---|
2516 | n/a | "filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66;" |
---|
2517 | n/a | " filename=abc.gif", |
---|
2518 | n/a | [('filename', '201.tif')], |
---|
2519 | n/a | [errors.InvalidHeaderDefect]), |
---|
2520 | n/a | |
---|
2521 | n/a | 'duplicate_key_with_split_value_other_order': ( |
---|
2522 | n/a | "filename=abc.gif; " |
---|
2523 | n/a | " filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66", |
---|
2524 | n/a | ' filename="abc.gif"', |
---|
2525 | n/a | "filename=abc.gif;" |
---|
2526 | n/a | " filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66", |
---|
2527 | n/a | [('filename', 'abc.gif')], |
---|
2528 | n/a | [errors.InvalidHeaderDefect]), |
---|
2529 | n/a | |
---|
2530 | n/a | 'duplicate_in_split_value': ( |
---|
2531 | n/a | "filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66;" |
---|
2532 | n/a | " filename*1*=abc.gif", |
---|
2533 | n/a | ' filename="201.tifabc.gif"', |
---|
2534 | n/a | "filename*0*=iso-8859-1''%32%30%31%2E; filename*1*=%74%69%66;" |
---|
2535 | n/a | " filename*1*=abc.gif", |
---|
2536 | n/a | [('filename', '201.tifabc.gif')], |
---|
2537 | n/a | [errors.InvalidHeaderDefect]), |
---|
2538 | n/a | |
---|
2539 | n/a | 'missing_split_value': ( |
---|
2540 | n/a | "filename*0*=iso-8859-1''%32%30%31%2E; filename*3*=%74%69%66;", |
---|
2541 | n/a | ' filename="201.tif"', |
---|
2542 | n/a | "filename*0*=iso-8859-1''%32%30%31%2E; filename*3*=%74%69%66;", |
---|
2543 | n/a | [('filename', '201.tif')], |
---|
2544 | n/a | [errors.InvalidHeaderDefect]), |
---|
2545 | n/a | |
---|
2546 | n/a | 'duplicate_and_missing_split_value': ( |
---|
2547 | n/a | "filename*0*=iso-8859-1''%32%30%31%2E; filename*3*=%74%69%66;" |
---|
2548 | n/a | " filename*3*=abc.gif", |
---|
2549 | n/a | ' filename="201.tifabc.gif"', |
---|
2550 | n/a | "filename*0*=iso-8859-1''%32%30%31%2E; filename*3*=%74%69%66;" |
---|
2551 | n/a | " filename*3*=abc.gif", |
---|
2552 | n/a | [('filename', '201.tifabc.gif')], |
---|
2553 | n/a | [errors.InvalidHeaderDefect]*2), |
---|
2554 | n/a | |
---|
2555 | n/a | # Here we depart from get_param and assume the *0* was missing. |
---|
2556 | n/a | 'duplicate_with_broken_split_value': ( |
---|
2557 | n/a | "filename=abc.gif; " |
---|
2558 | n/a | " filename*2*=iso-8859-1''%32%30%31%2E; filename*3*=%74%69%66", |
---|
2559 | n/a | ' filename="abc.gif201.tif"', |
---|
2560 | n/a | "filename=abc.gif;" |
---|
2561 | n/a | " filename*2*=iso-8859-1''%32%30%31%2E; filename*3*=%74%69%66", |
---|
2562 | n/a | [('filename', 'abc.gif201.tif')], |
---|
2563 | n/a | # Defects are apparent missing *0*, and two 'out of sequence'. |
---|
2564 | n/a | [errors.InvalidHeaderDefect]*3), |
---|
2565 | n/a | |
---|
2566 | n/a | } |
---|
2567 | n/a | |
---|
2568 | n/a | @parameterize |
---|
2569 | n/a | class Test_parse_mime_version(TestParserMixin, TestEmailBase): |
---|
2570 | n/a | |
---|
2571 | n/a | def mime_version_as_value(self, |
---|
2572 | n/a | value, |
---|
2573 | n/a | tl_str, |
---|
2574 | n/a | tl_value, |
---|
2575 | n/a | major, |
---|
2576 | n/a | minor, |
---|
2577 | n/a | defects): |
---|
2578 | n/a | mime_version = self._test_parse_x(parser.parse_mime_version, |
---|
2579 | n/a | value, tl_str, tl_value, defects) |
---|
2580 | n/a | self.assertEqual(mime_version.major, major) |
---|
2581 | n/a | self.assertEqual(mime_version.minor, minor) |
---|
2582 | n/a | |
---|
2583 | n/a | mime_version_params = { |
---|
2584 | n/a | |
---|
2585 | n/a | 'rfc_2045_1': ( |
---|
2586 | n/a | '1.0', |
---|
2587 | n/a | '1.0', |
---|
2588 | n/a | '1.0', |
---|
2589 | n/a | 1, |
---|
2590 | n/a | 0, |
---|
2591 | n/a | []), |
---|
2592 | n/a | |
---|
2593 | n/a | 'RFC_2045_2': ( |
---|
2594 | n/a | '1.0 (produced by MetaSend Vx.x)', |
---|
2595 | n/a | '1.0 (produced by MetaSend Vx.x)', |
---|
2596 | n/a | '1.0 ', |
---|
2597 | n/a | 1, |
---|
2598 | n/a | 0, |
---|
2599 | n/a | []), |
---|
2600 | n/a | |
---|
2601 | n/a | 'RFC_2045_3': ( |
---|
2602 | n/a | '(produced by MetaSend Vx.x) 1.0', |
---|
2603 | n/a | '(produced by MetaSend Vx.x) 1.0', |
---|
2604 | n/a | ' 1.0', |
---|
2605 | n/a | 1, |
---|
2606 | n/a | 0, |
---|
2607 | n/a | []), |
---|
2608 | n/a | |
---|
2609 | n/a | 'RFC_2045_4': ( |
---|
2610 | n/a | '1.(produced by MetaSend Vx.x)0', |
---|
2611 | n/a | '1.(produced by MetaSend Vx.x)0', |
---|
2612 | n/a | '1. 0', |
---|
2613 | n/a | 1, |
---|
2614 | n/a | 0, |
---|
2615 | n/a | []), |
---|
2616 | n/a | |
---|
2617 | n/a | 'empty': ( |
---|
2618 | n/a | '', |
---|
2619 | n/a | '', |
---|
2620 | n/a | '', |
---|
2621 | n/a | None, |
---|
2622 | n/a | None, |
---|
2623 | n/a | [errors.HeaderMissingRequiredValue]), |
---|
2624 | n/a | |
---|
2625 | n/a | } |
---|
2626 | n/a | |
---|
2627 | n/a | |
---|
2628 | n/a | |
---|
2629 | n/a | class TestFolding(TestEmailBase): |
---|
2630 | n/a | |
---|
2631 | n/a | policy = policy.default |
---|
2632 | n/a | |
---|
2633 | n/a | def _test(self, tl, folded, policy=policy): |
---|
2634 | n/a | self.assertEqual(tl.fold(policy=policy), folded, tl.ppstr()) |
---|
2635 | n/a | |
---|
2636 | n/a | def test_simple_unstructured_no_folds(self): |
---|
2637 | n/a | self._test(parser.get_unstructured("This is a test"), |
---|
2638 | n/a | "This is a test\n") |
---|
2639 | n/a | |
---|
2640 | n/a | def test_simple_unstructured_folded(self): |
---|
2641 | n/a | self._test(parser.get_unstructured("This is also a test, but this " |
---|
2642 | n/a | "time there are enough words (and even some " |
---|
2643 | n/a | "symbols) to make it wrap; at least in theory."), |
---|
2644 | n/a | "This is also a test, but this time there are enough " |
---|
2645 | n/a | "words (and even some\n" |
---|
2646 | n/a | " symbols) to make it wrap; at least in theory.\n") |
---|
2647 | n/a | |
---|
2648 | n/a | def test_unstructured_with_unicode_no_folds(self): |
---|
2649 | n/a | self._test(parser.get_unstructured("hübsch kleiner beiÃt"), |
---|
2650 | n/a | "=?utf-8?q?h=C3=BCbsch_kleiner_bei=C3=9Ft?=\n") |
---|
2651 | n/a | |
---|
2652 | n/a | def test_one_ew_on_each_of_two_wrapped_lines(self): |
---|
2653 | n/a | self._test(parser.get_unstructured("Mein kleiner Kaktus ist sehr " |
---|
2654 | n/a | "hübsch. Es hat viele Stacheln " |
---|
2655 | n/a | "und oft beiÃt mich."), |
---|
2656 | n/a | "Mein kleiner Kaktus ist sehr =?utf-8?q?h=C3=BCbsch=2E?= " |
---|
2657 | n/a | "Es hat viele Stacheln\n" |
---|
2658 | n/a | " und oft =?utf-8?q?bei=C3=9Ft?= mich.\n") |
---|
2659 | n/a | |
---|
2660 | n/a | def test_ews_combined_before_wrap(self): |
---|
2661 | n/a | self._test(parser.get_unstructured("Mein Kaktus ist hübsch. " |
---|
2662 | n/a | "Es beiÃt mich. " |
---|
2663 | n/a | "And that's all I'm sayin."), |
---|
2664 | n/a | "Mein Kaktus ist =?utf-8?q?h=C3=BCbsch=2E__Es_bei=C3=9Ft?= " |
---|
2665 | n/a | "mich. And that's\n" |
---|
2666 | n/a | " all I'm sayin.\n") |
---|
2667 | n/a | |
---|
2668 | n/a | # XXX Need test of an encoded word so long that it needs to be wrapped |
---|
2669 | n/a | |
---|
2670 | n/a | def test_simple_address(self): |
---|
2671 | n/a | self._test(parser.get_address_list("abc <xyz@example.com>")[0], |
---|
2672 | n/a | "abc <xyz@example.com>\n") |
---|
2673 | n/a | |
---|
2674 | n/a | def test_address_list_folding_at_commas(self): |
---|
2675 | n/a | self._test(parser.get_address_list('abc <xyz@example.com>, ' |
---|
2676 | n/a | '"Fred Blunt" <sharp@example.com>, ' |
---|
2677 | n/a | '"J.P.Cool" <hot@example.com>, ' |
---|
2678 | n/a | '"K<>y" <key@example.com>, ' |
---|
2679 | n/a | 'Firesale <cheap@example.com>, ' |
---|
2680 | n/a | '<end@example.com>')[0], |
---|
2681 | n/a | 'abc <xyz@example.com>, "Fred Blunt" <sharp@example.com>,\n' |
---|
2682 | n/a | ' "J.P.Cool" <hot@example.com>, "K<>y" <key@example.com>,\n' |
---|
2683 | n/a | ' Firesale <cheap@example.com>, <end@example.com>\n') |
---|
2684 | n/a | |
---|
2685 | n/a | def test_address_list_with_unicode_names(self): |
---|
2686 | n/a | self._test(parser.get_address_list( |
---|
2687 | n/a | 'Hübsch Kaktus <beautiful@example.com>, ' |
---|
2688 | n/a | 'beiÃt beiÃt <biter@example.com>')[0], |
---|
2689 | n/a | '=?utf-8?q?H=C3=BCbsch?= Kaktus <beautiful@example.com>,\n' |
---|
2690 | n/a | ' =?utf-8?q?bei=C3=9Ft_bei=C3=9Ft?= <biter@example.com>\n') |
---|
2691 | n/a | |
---|
2692 | n/a | def test_address_list_with_unicode_names_in_quotes(self): |
---|
2693 | n/a | self._test(parser.get_address_list( |
---|
2694 | n/a | '"Hübsch Kaktus" <beautiful@example.com>, ' |
---|
2695 | n/a | '"beiÃt" beiÃt <biter@example.com>')[0], |
---|
2696 | n/a | '=?utf-8?q?H=C3=BCbsch?= Kaktus <beautiful@example.com>,\n' |
---|
2697 | n/a | ' =?utf-8?q?bei=C3=9Ft_bei=C3=9Ft?= <biter@example.com>\n') |
---|
2698 | n/a | |
---|
2699 | n/a | # XXX Need tests with comments on various sides of a unicode token, |
---|
2700 | n/a | # and with unicode tokens in the comments. Spaces inside the quotes |
---|
2701 | n/a | # currently don't do the right thing. |
---|
2702 | n/a | |
---|
2703 | n/a | def test_initial_whitespace_splitting(self): |
---|
2704 | n/a | body = parser.get_unstructured(' ' + 'x'*77) |
---|
2705 | n/a | header = parser.Header([ |
---|
2706 | n/a | parser.HeaderLabel([parser.ValueTerminal('test:', 'atext')]), |
---|
2707 | n/a | parser.CFWSList([parser.WhiteSpaceTerminal(' ', 'fws')]), body]) |
---|
2708 | n/a | self._test(header, 'test: \n ' + 'x'*77 + '\n') |
---|
2709 | n/a | |
---|
2710 | n/a | def test_whitespace_splitting(self): |
---|
2711 | n/a | self._test(parser.get_unstructured('xxx ' + 'y'*77), |
---|
2712 | n/a | 'xxx \n ' + 'y'*77 + '\n') |
---|
2713 | n/a | |
---|
2714 | n/a | if __name__ == '__main__': |
---|
2715 | n/a | unittest.main() |
---|