Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08eeada

Browse files
committed
Issue #10283: Add a group_pattern argument to NNTP.list().
1 parent 99c4830 commit 08eeada

4 files changed

Lines changed: 53 additions & 17 deletions

File tree

Doc/library/nntplib.rst

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,15 @@ response indicates an error, the method raises one of the above exceptions.
182182
This command is frequently disabled by NNTP server administrators.
183183

184184

185-
.. method:: NNTP.list(*, file=None)
185+
.. method:: NNTP.list(group_pattern=None, *, file=None)
186186

187-
Send a ``LIST`` command. Return a pair ``(response, list)`` where *list* is a
188-
list of tuples representing all the groups available from this NNTP server.
189-
Each tuple has the form ``(group, last, first, flag)``, where
190-
*group* is a group name, *last* and *first* are the last and first article
191-
numbers, and *flag* usually takes one of these values:
187+
Send a ``LIST`` or ``LIST ACTIVE`` command. Return a pair
188+
``(response, list)`` where *list* is a list of tuples representing all
189+
the groups available from this NNTP server, optionally matching the
190+
pattern string *group_pattern*. Each tuple has the form
191+
``(group, last, first, flag)``, where *group* is a group name, *last*
192+
and *first* are the last and first article numbers, and *flag* usually
193+
takes one of these values:
192194

193195
* ``y``: Local postings and articles from peers are allowed.
194196
* ``m``: The group is moderated and all postings must be approved.
@@ -200,8 +202,12 @@ response indicates an error, the method raises one of the above exceptions.
200202
If *flag* has another value, then the status of the newsgroup should be
201203
considered unknown.
202204

203-
This command will often return very large results. It is best to cache the
204-
results offline unless you really need to refresh them.
205+
This command can return very large results, especially if *group_pattern*
206+
is not specified. It is best to cache the results offline unless you
207+
really need to refresh them.
208+
209+
.. versionchanged:: 3.2
210+
*group_pattern* was added.
205211

206212

207213
.. method:: NNTP.descriptions(grouppattern)

Lib/nntplib.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,14 +571,19 @@ def newnews(self, group, date, *, file=None):
571571
cmd = 'NEWNEWS {0} {1} {2}'.format(group, date_str, time_str)
572572
return self._longcmdstring(cmd, file)
573573

574-
def list(self, *, file=None):
575-
"""Process a LIST command. Argument:
574+
def list(self, group_pattern=None, *, file=None):
575+
"""Process a LIST or LIST ACTIVE command. Arguments:
576+
- group_pattern: a pattern indicating which groups to query
576577
- file: Filename string or file object to store the result in
577578
Returns:
578579
- resp: server response if successful
579580
- list: list of (group, last, first, flag) (strings)
580581
"""
581-
resp, lines = self._longcmdstring('LIST', file)
582+
if group_pattern is not None:
583+
command = 'LIST ACTIVE ' + group_pattern
584+
else:
585+
command = 'LIST'
586+
resp, lines = self._longcmdstring(command, file)
582587
return resp, self._grouplist(lines)
583588

584589
def _getdescriptions(self, group_pattern, return_all):

Lib/test/test_nntplib.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@ def test_welcome(self):
2222
self.assertEqual(str, type(welcome))
2323

2424
def test_help(self):
25-
resp, list = self.server.help()
25+
resp, lines = self.server.help()
2626
self.assertTrue(resp.startswith("100 "), resp)
27-
for line in list:
27+
for line in lines:
2828
self.assertEqual(str, type(line))
2929

3030
def test_list(self):
31-
resp, list = self.server.list()
32-
if len(list) > 0:
33-
self.assertEqual(GroupInfo, type(list[0]))
34-
self.assertEqual(str, type(list[0].group))
31+
resp, groups = self.server.list()
32+
if len(groups) > 0:
33+
self.assertEqual(GroupInfo, type(groups[0]))
34+
self.assertEqual(str, type(groups[0].group))
35+
36+
def test_list_active(self):
37+
resp, groups = self.server.list(self.GROUP_PAT)
38+
if len(groups) > 0:
39+
self.assertEqual(GroupInfo, type(groups[0]))
40+
self.assertEqual(str, type(groups[0].group))
3541

3642
def test_unknown_command(self):
3743
with self.assertRaises(nntplib.NNTPPermanentError) as cm:
@@ -383,6 +389,17 @@ def handle_LIST(self, action=None, param=None):
383389
free.it.comp.lang.python.learner 0000000000 0000000001 y
384390
tw.bbs.comp.lang.python 0000000304 0000000304 y
385391
.""")
392+
elif action == "ACTIVE":
393+
if param == "*distutils*":
394+
self.push_lit("""\
395+
215 Newsgroups in form "group high low flags"
396+
gmane.comp.python.distutils.devel 0000014104 0000000001 m
397+
gmane.comp.python.distutils.cvs 0000000000 0000000001 m
398+
.""")
399+
else:
400+
self.push_lit("""\
401+
215 Newsgroups in form "group high low flags"
402+
.""")
386403
elif action == "OVERVIEW.FMT":
387404
self.push_lit("""\
388405
215 Order of fields in overview database.
@@ -608,6 +625,12 @@ def test_list(self):
608625
self.assertEqual(g,
609626
GroupInfo("comp.lang.python.announce", "0000001153",
610627
"0000000993", "m"))
628+
resp, groups = self.server.list("*distutils*")
629+
self.assertEqual(len(groups), 2)
630+
g = groups[0]
631+
self.assertEqual(g,
632+
GroupInfo("gmane.comp.python.distutils.devel", "0000014104",
633+
"0000000001", "m"))
611634

612635
def test_stat(self):
613636
resp, art_num, message_id = self.server.stat(3000234)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Core and Builtins
6565
Library
6666
-------
6767

68+
- Issue #10283: Add a ``group_pattern`` argument to NNTP.list().
69+
6870
- Issue #10155: Add IISCGIHandler to wsgiref.handlers to support IIS
6971
CGI environment better, and to correct unicode environment values
7072
for WSGI 1.0.1.

0 commit comments

Comments
 (0)