473,857 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

nntplib downloads content with extra linebreaks

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)
Jan 6 '07 #1
5 1224
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,

--
Klaus Alexander Seistrup
http://klaus.seistrup.dk/

Jan 6 '07 #2
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.

Jan 6 '07 #3
Rweth wrote:
for aline in buf:
bufHeal.append( aline.replace(' \r\n', '\n'))
What does one single aline look like?
s.body(id,afile )
Does the 'afile' contain a filename or a filepointer?

Cheers,

--
Klaus Alexander Seistrup
http://klaus.seistrup.dk/

Jan 6 '07 #4
Klaus Alexander Seistrup wrote:
Rweth wrote:
> for aline in buf:
bufHeal.append( aline.replace(' \r\n', '\n'))

What does one single aline look like?
>s.body(id,afil e)

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

Cheers,
so afile contains a filename.
One single aline looks like so:
'</rme:SoftwareIde ntity>'
Jan 6 '07 #5
Rweth wrote:
so afile contains a filename.
One single aline looks like so:
'</rme:SoftwareIde ntity>'
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,

--
Klaus Alexander Seistrup
http://klaus.seistrup.dk/

Jan 6 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2276
by: Mechphisto | last post by:
I'm using a textarea to insert some notes into a database. It's inserting the complete result into the mySQL table including the linebreaks...and not as a visible symbol but an actual linebreak. If I select the fireld in mySQL at a command prompt, the results take an inordinate amount of space from all the linebreaks. I tried nl2br() before it goes into the INSERT, but all that does is ADD <br /> to the data but it still have linebreaks...
4
10164
by: Sidharta | last post by:
Hi all, how come this doesn't work????? # convert to unix new lines $text = preg_replace("/\r\n/", "\n", $text); # remove extra new lines $text = preg_replace("/\n+/", "\n", $text); is there better ways to remove extra new lines???
7
14265
by: deko | last post by:
I need to allow users to download files from a directory that is not publicly accessible. To do this, I use a download script: header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=".$filename); readfile($fullpath); I've also tried using header("Content-Type: application/force-download") instead of header("Content-Type: application/octet-stream"), but get the same results - the downloaded...
4
1564
by: Rakesh | last post by:
For a particular application of mine, I need to get the messages from usenet , (and group them by each thread) . My startup python code looks as follows. <--- Startup code to read messages from a newsgroup --> import nntplib, cStringIO, rfc822, sys SRVR = '<my_news_server>' # Your news server newsgroup = 'comp.lang.c' # Group of your choice
2
1309
by: python | last post by:
Hello, How to post a news article with NNTPlib if the news server requires login. I did not find nay login command in nntplib module. Thank you lad.
2
1413
by: Helmut Jarausch | last post by:
Hi I try to regularly extract recent news from some newsgroups. If News is an NNTP object I try (Response,Articles)= News.xover(str(int(Last)+1),'10000000') where 'Last' is the (previously saved) number of the last article read. If there are no new articles I get an Exception Traceback (most recent call last):
1
1525
by: 2Good4You-Veki(Cro) | last post by:
HI, when I want use python nntplib: THEN ERROR IS: Traceback (most recent call last): File "<pyshell#2>", line 1, in -toplevel- s.group('hr.mag.bug') File "C:\Python24\lib\nntplib.py", line 346, in group
2
1153
by: James.Pells | last post by:
So I have established a connection to an nntp server and I am retrieving articles to other articles on the server such as news://newsclip.ap.org/D8L4MFAG0@news.ap.org Now I am wondering how I query for that article based off of the url? I assume D8L4MFAG0 is an id of some sort but when I try and retrieve that article via myNntpObject.article('D8L4MFAG0') I get an error of 423 Bad article number. Which makes sense as all the other...
7
2837
by: =?Utf-8?B?QU9UWCBTYW4gQW50b25pbw==?= | last post by:
Hi, I have been using the code (some of it has been removed for simplicity) below to allow authenticated (using ASP.NET membership database) users to get a file from their archive area. It seems to work fine, however I noticed that no web log entry is added when a successful download occurs (normally a 200 HTTP status code, however, if there is an authorization failure, it gets logged). I have a logging routine that logs a successful...
0
9768
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10808
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10394
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9549
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7940
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5971
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4191
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.