Il modulo definisce la classe NNTP che implementa la parte client del protocollo NNTP. Può essere usata per implementare un lettore o un generatore, o un processore automatico di news. Per ulteriori informazioni su NNTP (Network News Transfer Protocol), vedere la Internet RFC 977.
Qui ci sono due piccoli esempi di come può essere usato. Mostra alcune statistiche circa un newsgroup e stampa il soggetto degli ultimi 10 articoli.
>>> s = NNTP('news.cwi.nl')
>>> resp, count, first, last, name = s.group('comp.lang.python')
>>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last
Group comp.lang.python has 59 articles, range 3742 to 3803
>>> resp, subs = s.xhdr('subject', first + '-' + last)
>>> for id, sub in subs[-10:]: print id, sub
...
3792 Re: Removing elements from a list while iterating...
3793 Re: Who likes Info files?
3794 Emacs and doc strings
3795 a few questions about the Mac implementation
3796 Re: executable python scripts
3797 Re: executable python scripts
3798 Re: a few questions about the Mac implementation
3799 Re: PROPOSAL: A Generic Python Object Interface for Python C Modules
3802 Re: executable python scripts
3803 Re: \POSIX{} wait and SIGCHLD
>>> s.quit()
'205 news.cwi.nl closing connection. Goodbye.'
Per postare un articolo da un file (questo assume che l'articolo possieda intestazioni valide):
>>> s = NNTP('news.cwi.nl')
>>> f = open('/tmp/article')
>>> s.post(f)
'240 Article posted successfully.'
>>> s.quit()
'205 news.cwi.nl closing connection. Goodbye.'
Il modulo definisce i seguenti elementi:
| host[, port [, user[, password [, readermode]]]]) |
NNTPPermanentError, è possibile che dobbiate impostare
readermode. Il valore predefinito di readermode è
None.
| ) |
Exception, questa è la classe
di base per tutte le eccezioni sollevate dal modulo nntplib.
| ) |
error_reply è equivalente a questa classe.
| ) |
error_temp è equivalente a questa classe.
| ) |
error_perm è equivalente a questa classe.
| ) |
error_proto è
equivalente a questa classe.
| ) |
error_data è
equivalente a questa classe.