[Python-checkins] python/dist/src/Lib nntplib.py,1.30,1.31
esr@users.sourceforge.net
esr@users.sourceforge.net
Wed, 13 Nov 2002 15:05:38 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv15513
Modified Files:
nntplib.py
Log Message:
Make nntplib aware of ~/.netrc credentials; now they get used if they are
present and the caller has not specified a name/password pair. This change
makes it less likely that a lazy coder will expose sensitive information in a
word-readable script.
Also, make the test a bit smarter. If NNTPSERVER is defined in the environment
it will go talk to that server rather than look for a possibly nonexistent
local one named 'news'. Maybe the osession initializer ought to look at
NNTPSERVER rather than requiring a host arg? Must look around and see how
universal this convention is first.
Index: nntplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/nntplib.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** nntplib.py 3 Jun 2002 15:58:31 -0000 1.30
--- nntplib.py 13 Nov 2002 23:05:35 -0000 1.31
***************
*** 134,137 ****
--- 134,147 ----
else:
raise
+ # If no login/password was specified, try to get them from ~/.netrc
+ # Presume that if .netc has an entry, NNRP authentication is required.
+ if not user:
+ import netrc
+ credentials = netrc.netrc()
+ auth = credentials.authenticators(host)
+ if auth:
+ user = auth[0]
+ password = auth[2]
+ # Perform NNRP authentication if needed.
if user:
resp = self.shortcmd('authinfo user '+user)
***************
*** 556,562 ****
! def _test():
! """Minimal test function."""
! s = NNTP('news', readermode='reader')
resp, count, first, last, name = s.group('comp.lang.python')
print resp
--- 566,582 ----
! # Test retrieval when rubn as a script.
! # Assumption: if there's a local news server, it's called 'news'.
! # Assumption: if user queries a remote news server, it's named
! # in the environment variable NNTPSERVER (used by slrn and kin)
! # and we want readermode off.
! if __name__ == '__main__':
! import os
! newshost = 'news' and os.environ["NNTPSERVER"]
! if newshost.find('.') == -1:
! mode = 'readermode'
! else:
! mode = None
! s = NNTP(newshost, readermode=mode)
resp, count, first, last, name = s.group('comp.lang.python')
print resp
***************
*** 569,574 ****
print resp
-
- # Run the test when run as a script
- if __name__ == '__main__':
- _test()
--- 589,590 ----