nntplib downloads content with extra linebreaks

R

rweth

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

Is there any way to employ this library to strip out these extra
line breaks? I know this may seem trivial but they cause serious
issues when I try and employ the subsequent downloaded xml file
for a series of processes.

When I forward one of these files from Thunderbird (via the newsgroup)
to outlook and open it up, and then select "ignore extra line breaks",
and cut and paste the content .. all is well. The file is "healed".

Apart from being just a plain annoyance (all this manual steps) it
really bothers me something this trivial (the pretty-fication of
content) would throw me out of whack so badly .. also that outlook has
some simple method that magically does what I need and I cannot hack it
for myself. (not to mention how brittle
the xml processing we must have in place is .. )

First I thought it was a call to RFC 977(or below) which I cannot work
out, but which does the deed! But then I though that the content of the
forwarded msg has something in it which outlook can filter ..
because the forwarded msg is encapsulated, and likely cut off from the
news server.
(what do I know these are guesses)
 
K

Klaus Alexander Seistrup

Rweth said:
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,
 
R

rweth

Klaus said:
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.
 
R

rweth

Klaus said:
What does one single aline look like?


Does the 'afile' contain a filename or a filepointer?

Cheers,
so afile contains a filename.
One single aline looks like so:
'</rme:SoftwareIdentity>'
 
K

Klaus Alexander Seistrup

Rweth said:
so afile contains a filename.
One single aline looks like so:
'</rme:SoftwareIdentity>'

Beats me where those empty lines come from, it doesn't seem to
happen in nntplib.

Does the same thing happen if you pass .body() a filepointer?

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top