Index: Lib/nntplib.py =================================================================== --- Lib/nntplib.py (révision 86129) +++ Lib/nntplib.py (copie de travail) @@ -205,11 +205,13 @@ is_metadata = field_name.startswith(':') if i >= n_defaults and not is_metadata: # Non-default header names are included in full in the response + # (unless the field is totally empty) h = field_name + ":" - if token[:len(h)].lower() != h: + if token and token[:len(h)].lower() != h: raise NNTPDataError("OVER/XOVER response doesn't include " "names of additional headers") token = token[len(h):].lstrip(" ") + token = token or None fields[fmt[i]] = token overview.append((article_number, fields)) return overview Index: Lib/test/test_nntplib.py =================================================================== --- Lib/test/test_nntplib.py (révision 86129) +++ Lib/test/test_nntplib.py (copie de travail) @@ -457,7 +457,7 @@ "\tThu, 22 Jul 2010 09:14:14 -0400" "\t" "\t\t6683\t16" - "\tXref: news.gmane.org gmane.comp.python.authors:58" + "\t" "\n" # An UTF-8 overview line from fr.comp.lang.python "59\tRe: Message d'erreur incompréhensible (par moi)" @@ -824,6 +824,8 @@ ":lines": "16", "xref": "news.gmane.org gmane.comp.python.authors:57" }) + art_num, over = overviews[1] + self.assertEqual(over["xref"], None) art_num, over = overviews[2] self.assertEqual(over["subject"], "Re: Message d'erreur incompréhensible (par moi)") @@ -1028,6 +1030,27 @@ ':lines': '17', 'xref': 'news.example.com misc.test:3000363', }) + # Second example; here the "Xref" field is totally absent (including + # the header name) and will come out as None + lines = [ + '3000234\tI am just a test article\t"Demo User" ' + '\t6 Oct 1998 04:38:40 -0500\t' + '<45223423@example.com>\t<45454@example.net>\t1234\t' + '17\t\t', + ] + overview = nntplib._parse_overview(lines, fmt) + (art_num, fields), = overview + self.assertEqual(art_num, 3000234) + self.assertEqual(fields, { + 'subject': 'I am just a test article', + 'from': '"Demo User" ', + 'date': '6 Oct 1998 04:38:40 -0500', + 'message-id': '<45223423@example.com>', + 'references': '<45454@example.net>', + ':bytes': '1234', + ':lines': '17', + 'xref': None, + }) def test_parse_datetime(self): def gives(a, b, *c):