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) -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding a directory to the Python System Path - Edit the registry?
[EMAIL PROTECTED] wrote: > Thanks Martin. > > I'll take a look at the documentation you pointed out. > > Scott > > Martin P. Hellwig wrote: >> [EMAIL PROTECTED] wrote: >>> I have been trying to find a way to add a directory to Python's sytem >>> path on my MS Windows XP computer. I did some searching online, but the >>> only solution I found involved editing the MS Windows Registry. That >>> seemed a little to hard core. Is there another easier way to do this? >>> >>> Thanks, >>> >>> Scott Huey >>> >> Take a look at: >> http://docs.python.org/tut/node8.html >> >> Specifically 6.1.1 and 6.2, perhaps that might answer your question. >> >> Cheers >> >> -- >> mph > There is a file you can use to extend your system path on my windows box it is here: C:\Python24\Lib\site-packages\package.pth Inside the package.pth I have added: C:\\QA\\bin I think I needed to do this in linux as well (and it worked). Find your installation path to ../Lib/site-packages and if that file does not exist create it and add your paths in their own lines no separators needed. -- http://mail.python.org/mailman/listinfo/python-list
Re: nntplib downloads content with extra linebreaks
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. -- http://mail.python.org/mailman/listinfo/python-list
Re: search mail by date with imaplib
[EMAIL PROTECTED] wrote: > Hi > I am looking for a code sample which searches mail by date with imaplib > > example: > get email from 01.01.2007 to now > > how can I change imaplib search parameters? > So I had to do the same thing a few years back. I love python but seriously every author spends less than 1/10 of 1% on doc ! Well So do I .. so take it with a grain of salt. Here is what I did, MANY YEARS AGO .. I don't even have a IMAP account anymore t,data = M.uid("SEARCH",None,'(FROM blahblah)') luid = string.split(data[0]) for uid in luid: t,d = M.uid("FETCH",uid,"(BODY[HEADER.FIELDS (DATE SUBJECT TO)])") date = d[0][1] This will get you the dates .. and you can write your own filter off that .. it's trivial. What isn't so great is getting every piece of mail and then searching for the needle's in the haystack. So I guess this is plan c (just in case you don't get a better answer). I will watch this one for a "plan a | b" answer. -- http://mail.python.org/mailman/listinfo/python-list
Re: nntplib downloads content with extra linebreaks
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,afile) > > Does the 'afile' contain a filename or a filepointer? > > Cheers, > so afile contains a filename. One single aline looks like so: '' -- http://mail.python.org/mailman/listinfo/python-list
Re: File Closing Problem in 2.3 and 2.4, Not in 2.5
Martin v. Löwis wrote: > Carroll, Barry schrieb: >> What I want to know is: >> >> * has anyone else encountered a problem like this, * how was the >> problem corrected, * can the fix be retro-fitted to 2.5 and 2.4? > > From your description, I suspect an error in your code. Your description > indicates that you don't expect to have more than five files open > simultaneously. Yet, the error message "Too many open files" occurs when > you open many more files (in the order of hundreds of files). > > It is very unlikely that there is a bug in Python where it would fail to > close a file when .close() is explicitly invoked on it (as your > description suggests that you do), so if you get that error message, it > can only mean that you fail to close some files. > > Notice that you may have other files open, as well, and that those also > count towards the limit. > > As a debugging utility, you can use Sysinternal's process explorer. > Make the program halt (not exit) when the exception occurs (e.g. by > having it sleep(1) in a loop), then view all open handles in the > process explorer (check the menu if it doesn't display them initially). > > Regards, > Martin I agree with Martin .. this code to close is solid. Make certain you are really closing the files when you think you should. I am pretty sure you are not. Look at the code that closes the files closely. Put a print statement in the block that is supposed to close the files (may bee even a raw_input("closing file" + afile) statement). My guess is that you won't see the print statements trigger when you though they should .. they may be out of "the loop" you thought that they were in. -- http://mail.python.org/mailman/listinfo/python-list
Re: search mail by date with imaplib
Jean-Paul Calderone wrote: > On Sat, 06 Jan 2007 11:49:17 -0800, rweth <[EMAIL PROTECTED]> wrote: >> [EMAIL PROTECTED] wrote: >>> Hi >>> I am looking for a code sample which searches mail by date with imaplib >>> >>> example: >>> get email from 01.01.2007 to now >>> >>> how can I change imaplib search parameters? >>> >> So I had to do the same thing a few years back. I love python but >> seriously every author spends less than 1/10 of 1% on doc ! >> >> Well So do I .. so take it with a grain of salt. Here is what I did, >> MANY YEARS AGO .. I don't even have a IMAP account anymore >> >> t,data = M.uid("SEARCH",None,'(FROM blahblah)') >> luid = string.split(data[0]) >> for uid in luid: >> t,d = M.uid("FETCH",uid,"(BODY[HEADER.FIELDS (DATE SUBJECT TO)])") >> date = d[0][1] >> >> This will get you the dates .. and you can write your own >> filter off that .. it's trivial. What isn't so great is >> getting every piece of mail and then searching for the needle's in >> the haystack. >> >> So I guess this is plan c (just in case you don't get a better answer). >> I will watch this one for a "plan a | b" answer. >> > > The SEARCH command supports quite a few kinds of criteria. Several which > may be relevant here are BEFORE, SINCE, SENTBEFORE, and SENTSINCE. Using > Twisted's IMAP4 code, you can format a query like this: > >>>> from twisted.mail.imap4 import Query >>>> Query(after='01-Jan-2007') >'(AFTER "01-Jan-2007")' >>>> > > Since documentation was brought up, I'll point out Query's docs too, since > that might help shed some further light on what's possible. > > http://twistedmatrix.com/documents/current/api/twisted.mail.imap4.html#twisted.mail.imap4.Query > > > > Jean-Paul Wow looks like twisted took Imap4 and made it better! I think I had better read up on twisted .. this looks quite good (Plan A for sure). -- http://mail.python.org/mailman/listinfo/python-list
Re: How to invoke parent's method?
many_years_after wrote: > Hi, pythoners: > > My wxPython program includes a panel whose parent is a frame. The > panel has a button. When I click the button , I want to let the frame > destroy. How to implement it? Could the panel invoke the frame's > method? > Thanks. > I think it "could" if what I read recently in: http://www.python.org/download/releases/2.2/descrintro/#cooperation Is applicable. Look at the link "Cooperative methods and super" Write a subclass of panel where the target method of it's parent is targX (that parent method of Frame that you want to call) class myPanel (Panel): def dadsX (self): Frame.targX(self) I think you are forced to invoke this within a method of the Class itself, as opposed to doing so with an instance. Good luck! -- http://mail.python.org/mailman/listinfo/python-list
Re: How to invoke parent's method?
rweth wrote: > many_years_after wrote: >> Hi, pythoners: >> >> My wxPython program includes a panel whose parent is a frame. The >> panel has a button. When I click the button , I want to let the frame >> destroy. How to implement it? Could the panel invoke the frame's >> method? >> Thanks. >> > I think it "could" if what I read recently in: >http://www.python.org/download/releases/2.2/descrintro/#cooperation > Is applicable. > >Look at the link "Cooperative methods and super" >Write a subclass of panel where the target method of it's parent >is targX (that parent method of Frame that you want to call) > > class myPanel (Panel): >def dadsX (self): > Frame.targX(self) > > > I think you are forced to invoke this within a method of the Class > itself, as opposed to doing so with an instance. > > Good luck! > > You know I just tried a code fragment and got the parent method to work with an instance .. so maybe you don't have to subclass. Here is a transcript illustrating the idea: >>> class DAD: ... def methodx(self): ... print "DAD-methodx" ... >>> class SON(DAD): ... def methodx(self): ... print "SON-methodx" ... >>> >>> >>> billy = SON() >>> billy.methodx() SON-methodx >>> DAD.methodx(billy) DAD-methodx >>> So you can invoke the DAD.methodx via the billy instance of the object .. without subclassing. Now I wonder if this will actually work? -- http://mail.python.org/mailman/listinfo/python-list
Re: Cant access http://cheeseshop.python.org/ or wiki
cyb wrote: > For some reason I can ping these two sites fine, but when I try to go to > them I cannot get to them. Normal python.org homepage works just fine. > This is preventing me from getting setuptools and using pyOpenGL =( > > I'm using COmcast in savannah, GA "It's the finest cheese shop in these parts sir" "And what leads you to that conclusion" "well it's so clean sir" "well it's certainly uncontaminated by cheese!" http://www.youtube.com/watch?v=pDat9zdw7Gs Prey out of curiosity .. any idea where the spiders came from? I too noticed an issue downloading mechanize last night. -- http://mail.python.org/mailman/listinfo/python-list
Re: defining functions
Andre P.S Duarte wrote: > How do I define a function, then import it, without having to save it > in lib; like "C:\python25\lib". ? > The best way I have found (in windows ) for permanently extending your search path for modules is to create the file: package.pth and put your path/s in a line by line format: c:\qa\PythonLibs c:\qa\PythonUtils The file needs to be in a location in your install under the site-packages .. in windows for my system thats: C:\Python25\Lib\site-packages\package.pth After you do that you can put your modules in the paths you define in the package.pth file and sys,path will pick up your modules automatically. -- http://mail.python.org/mailman/listinfo/python-list