use new nntp argument usenetrc

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@2207 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2005-01-24 19:31:13 +00:00
parent 93e3da02b2
commit e226131e59
2 changed files with 1 additions and 72 deletions

4
TODO
View file

@ -11,10 +11,6 @@ Possible improvements people could work on:
- [BUGFIX] when an URL is found in the cache and it has a broken anchor,
the broken anchor name is not displayed as a warning
- [OPTIMIZATION] Python 2.4 introduced an "usenetrc" option to ignore
~/.netrc for NNTP. Thus we could get rid of our custom NNTP class that
ignores ~/.netrc completely and use "usenetrc=False" instead.
- [USAGE] make a nice GUI for linkchecker
- [OPTIMIZATION] SF bug #992389 bit me when I wanted to do absolute imports

View file

@ -32,73 +32,6 @@ import linkcheck.log
random.seed()
class NoNetrcNNTP (nntplib.NNTP):
"""
NNTP class ignoring possible entries in ~/.netrc.
"""
def __init__ (self, host, port=nntplib.NNTP_PORT, user=None,
password=None, readermode=None):
"""
Initialize an instance. Arguments:
- host: hostname to connect to
- port: port to connect to (default the standard NNTP port)
- user: username to authenticate with
- password: password to use with username
- readermode: if true, send 'mode reader' command after
connecting.
readermode is sometimes necessary if you are connecting to an
NNTP server on the local machine and intend to call
reader-specific comamnds, such as `group'. If you get
unexpected NNTPPermanentErrors, you might need to set
readermode.
"""
self.host = host
self.port = port
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((self.host, self.port))
self.file = self.sock.makefile('rb')
self.debugging = 0
self.welcome = self.getresp()
# 'mode reader' is sometimes necessary to enable 'reader' mode.
# However, the order in which 'mode reader' and 'authinfo' need to
# arrive differs between some NNTP servers. Try to send
# 'mode reader', and if it fails with an authorization failed
# error, try again after sending authinfo.
readermode_afterauth = 0
if readermode:
try:
self.welcome = self.shortcmd('mode reader')
except nntplib.NNTPPermanentError:
# error 500, probably 'not implemented'
pass
except nntplib.NNTPTemporaryError, e:
if user and e.response[:3] == '480':
# Need authorization before 'mode reader'
readermode_afterauth = 1
else:
raise
# Perform NNRP authentication if needed.
if user:
resp = self.shortcmd('authinfo user '+user)
if resp[:3] == '381':
if not password:
raise nntplib.NNTPReplyError(resp)
else:
resp = self.shortcmd(
'authinfo pass '+password)
if resp[:3] != '281':
raise nntplib.NNTPPermanentError(resp)
if readermode_afterauth:
try:
self.welcome = self.shortcmd('mode reader')
except nntplib.NNTPPermanentError:
# error 500, probably 'not implemented'
pass
class NntpUrl (urlbase.UrlBase):
"""
Url link with NNTP scheme.
@ -141,7 +74,7 @@ class NntpUrl (urlbase.UrlBase):
while tries < 5:
tries += 1
try:
nntp = NoNetrcNNTP(nntpserver)
nntp = NNTP(nntpserver, usenetrc=False)
except nntplib.error_perm:
value = sys.exc_info()[1]
if re.compile("^50[45]").search(str(value)):