Using nntplib

jb jblazi at hotmail.com
Thu May 30 10:21:55 EDT 2002


Let us assume I send a LIST command to the server. Then I get a short list 
of the newsgroups, the server offers. Getting for example 100,000 lines 
from 'goliath.newsfeeds.com' takes more than a "few minutes", as Outlook, 
that I used to use in my MS-life, puts it.

Now the point is, that nntplib works synchronously(!), that means that the 
thread is waiting on the LIST command until the server sends it's 
terminating '.' and all the time the temporary file the socket has created 
is polled.

(1)
This is a terrible method, but the handling of the sommands should be done 
in another thread, so maybe it is o.k.
(I thought, I should do all this myself and use QSockets, but alas! they are 
not supported by PyQt, however wonderful PyQt is.)

(2)
But I cannot monitor the whole procedure, that is I cannot see, how many 
lines have arrived already.

(3) QUESTION:
How can I do the monitoring I mentioned in (2)? A possibility is to tune the 
file nntplib.py (that is, CHANGING A SYSTEM FILE!). Here is a part of 
nntplib.py:

   def getlongresp(self, file=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(file, types.StringType):
                openedFile = file = open(file, "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 file:
                ############ inserted by J.B. #######
                ### HERE SOMETHING SHOULD BE DONE ###
                #####################################
                    file.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

So what should I do? Rasing an excepton? And should not nntplib di this?

TIA,
-- 
Janos Blazi

"Il n'y a guère dans la vie qu'une préoccupation grave: c'est la mort;" 
(Dumas) 



-----------== Posted via Newsfeeds.Com - Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =-----



More information about the Python-list mailing list