nntplib downloads content with extra linebreaks

rweth rweth at cisco.com
Sat Jan 6 20:37:55 CET 2007


Klaus Alexander Seistrup wrote:
> Rweth wrote:
> 
>> I am using nntplib to download archived xml messages from our 
>> internal newsgroup. This is working fine except the download 
>> of files  to the connected server, has extra embedded lines in 
>> them (all over the place), from the
>>    s.body(id,afile)  # body method
> 
> The 'linebreaks' are probably '\r\n' pairs, so you could do a
> 
> 	buf.replace('\r\n', '\n')
> 
> to convert all such pairs to single LFs (buf being the buffer or 
> string that holds the text with 'linebreaks').
> 
> Cheers,
> 
Well Klaus I tried it .. sadly no joy.
Lets see if I did it the way you would have:
   buf = s.body(id)[3]
   # indexes 0 .. 2 contain disjoint portions but the big part is in
   # [3] so  .. i only did it for 3 for simplification
   bufHeal = []
   for aline in buf:
      bufHeal.append(aline.replace('\r\n', '\n'))

   fn = "c:/boing.xml"
   fh = open(fn.'w')
   for aline in bufHeal:
     fh.write(aline)
   fh.close()

This is giving me a file with no line breaks .. in fact
when I look at the elements in buf .. they don't have \r\n or \n at the 
end of them .. I think the s.body(id,afile) .. does a variety of magic 
to the contents of the buffer .. along with applying "some
magic template directive like an xsd file" again just guessing here.






More information about the Python-list mailing list