[Python-checkins] CVS: python/dist/src/Lib nntplib.py,1.26,1.27

Guido van Rossum gvanrossum@users.sourceforge.net
2001年10月01日 06:46:57 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv19232
Modified Files:
	nntplib.py 
Log Message:
SF patch #462628 (Travers Naran) NNTPLib supports saving BODY to a file.
 I modified nntplib so the body method can accept an
 optional second parameter pointing to a filehandle or
 filename (string). This way, really long body
 articles can be stored to disk instead of kept in
 memory. The way I made the modification should make
 it easy to extend this functionality to other extended
 return methods.
Index: nntplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/nntplib.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** nntplib.py	2001年02月09日 07:02:17	1.26
--- nntplib.py	2001年10月01日 13:46:55	1.27
***************
*** 32,35 ****
--- 32,36 ----
 import re
 import socket
+ import types
 
 __all__ = ["NNTP","NNTPReplyError","NNTPTemporaryError",
***************
*** 211,228 ****
 return resp
 
! def getlongresp(self):
 """Internal: get a response plus following text from the server.
 Raise various errors if the response indicates an error."""
! resp = self.getresp()
! if resp[:3] not in LONGRESP:
! raise NNTPReplyError(resp)
! list = []
! while 1:
! line = self.getline()
! if line == '.':
! break
! if line[:2] == '..':
! line = line[1:]
! list.append(line)
 return resp, list
 
--- 212,244 ----
 return resp
 
! def getlongresp(self,fileHandle=None):
 """Internal: get a response plus following text from the server.
 Raise various errors if the response indicates an error."""
! 
! openedFile = None
! try:
! # If a string was passed then open a file with that name
! if isinstance(fileHandle, types.StringType):
! openedFile = fileHandle = open(fileHandle, "w")
! 
! resp = self.getresp()
! if resp[:3] not in LONGRESP:
! raise NNTPReplyError(resp)
! list = []
! while 1:
! line = self.getline()
! if line == '.':
! break
! if line[:2] == '..':
! line = line[1:]
! if fileHandle:
! fileHandle.write(line + "\n")
! else:
! list.append(line)
! finally:
! # If this method created the file, then it must close it
! if openedFile:
! openedFile.close()
! 
 return resp, list
 
***************
*** 232,239 ****
 return self.getresp()
 
! def longcmd(self, line):
 """Internal: send a command and get the response plus following text."""
 self.putcmd(line)
! return self.getlongresp()
 
 def newgroups(self, date, time):
--- 248,255 ----
 return self.getresp()
 
! def longcmd(self, line, fileHandle=None):
 """Internal: send a command and get the response plus following text."""
 self.putcmd(line)
! return self.getlongresp(fileHandle)
 
 def newgroups(self, date, time):
***************
*** 340,346 ****
 return self.statcmd('LAST')
 
! def artcmd(self, line):
 """Internal: process a HEAD, BODY or ARTICLE command."""
! resp, list = self.longcmd(line)
 resp, nr, id = self.statparse(resp)
 return resp, nr, id, list
--- 356,362 ----
 return self.statcmd('LAST')
 
! def artcmd(self, line, fileHandle=None):
 """Internal: process a HEAD, BODY or ARTICLE command."""
! resp, list = self.longcmd(line,fileHandle)
 resp, nr, id = self.statparse(resp)
 return resp, nr, id, list
***************
*** 357,370 ****
 return self.artcmd('HEAD ' + id)
 
! def body(self, id):
 """Process a BODY command. Argument:
 - id: article number or message id
 Returns:
 - resp: server response if successful
 - nr: article number
 - id: message id
! - list: the lines of the article's body"""
 
! return self.artcmd('BODY ' + id)
 
 def article(self, id):
--- 373,388 ----
 return self.artcmd('HEAD ' + id)
 
! def body(self, id, fileHandle=None):
 """Process a BODY command. Argument:
 - id: article number or message id
+ - fileHandle: Filename string or file object to store the article in
 Returns:
 - resp: server response if successful
 - nr: article number
 - id: message id
! - list: the lines of the article's body or an empty list
! if fileHandle was used"""
 
! return self.artcmd('BODY ' + id, fileHandle)
 
 def article(self, id):

AltStyle によって変換されたページ (->オリジナル) /