Re: [Zope] Fighting htmllib in external method
Dieter: Thanks Dieter. > Jason Spisak writes: > > I want to catalog some html files but I want to strip the html tags out. > > htmlparser does a good job of that, but when I try to acces that from an > > external method, I run into trouble. > You may look at > > URL:http://www.dieter.handshake.de/pyprojects/zope/CatalogSupport.html > > It does the same as you want to do, but without the "formatter". > > Alternatively, you may try a "StringIO" instance as a file object. > That's what I ended up doing. > Finally, I can use files in external methods. > You should, however, be careful as several threads can execute > the same external method concurrently. Therefore, your > files are better not global. That's what I was thinking. I'll stay away from a named file. All my best, Jason Spisak ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Fighting htmllib in external method
Jason Spisak writes: > I want to catalog some html files but I want to strip the html tags out. > htmlparser does a good job of that, but when I try to acces that from an > external method, I run into trouble. You may look at URL:http://www.dieter.handshake.de/pyprojects/zope/CatalogSupport.html It does the same as you want to do, but without the "formatter". Alternatively, you may try a "StringIO" instance as a file object. Finally, I can use files in external methods. You should, however, be careful as several threads can execute the same external method concurrently. Therefore, your files are better not global. Dieter ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] Fighting htmllib in external method
Jonothan Farr, Thanks very much! I am new to Python. I coded my first Zope app in entirely DTML, so now I'm moving deeper. That's a handy thing to have. All my best, Jason Spisak [EMAIL PROTECTED] > Try using a StringIO object as your file. > > import htmllib > import formatter > from cStringIO import StringIO > > def index(self, html): > file = StringIO() > fmtr = formatter.AbstractFormatter(formatter.DumbWriter(file)) > p = htmllib.HTMLParser(fmtr) > p.feed(html) > file.seek(0) > return file.read() > > > - Original Message - > From: "Jason Spisak" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Tuesday, October 10, 2000 2:47 AM > Subject: [Zope] Fighting htmllib in external method > > > > Howdy Zopsters, > > > > I want to catalog some html files but I want to strip the html tags out. > > htmlparser does a good job of that, but when I try to acces that from an > > external method, I run into trouble. > > > > import htmllib > > import formatter > > > > def index(self, html): > > fmtr = formatter.AbstractFormatter(formatter.DumbWriter(file)) > > p = htmllib.HTMLParser(fmtr) > > return p.feed(html) > > > > Since the DumbWriter uses stdout, this returns None. When I try to write > > to a temporary file, or pipe I get 'bad file descriptor' errors because of > > the way external method function I guess. Any help would really be > > appreciated. > > > > All my best, > > > > > > Jason Spisak > > [EMAIL PROTECTED] > > > > ___ > > Zope maillist - [EMAIL PROTECTED] > > http://lists.zope.org/mailman/listinfo/zope > > ** No cross posts or HTML encoding! ** > > (Related lists - > > http://lists.zope.org/mailman/listinfo/zope-announce > > http://lists.zope.org/mailman/listinfo/zope-dev ) > > > > > ___ > Zope maillist - [EMAIL PROTECTED] > http://lists.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://lists.zope.org/mailman/listinfo/zope-announce > http://lists.zope.org/mailman/listinfo/zope-dev ) > ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Fighting htmllib in external method
Try using a StringIO object as your file. import htmllib import formatter from cStringIO import StringIO def index(self, html): file = StringIO() fmtr = formatter.AbstractFormatter(formatter.DumbWriter(file)) p = htmllib.HTMLParser(fmtr) p.feed(html) file.seek(0) return file.read() - Original Message - From: "Jason Spisak" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, October 10, 2000 2:47 AM Subject: [Zope] Fighting htmllib in external method > Howdy Zopsters, > > I want to catalog some html files but I want to strip the html tags out. > htmlparser does a good job of that, but when I try to acces that from an > external method, I run into trouble. > > import htmllib > import formatter > > def index(self, html): > fmtr = formatter.AbstractFormatter(formatter.DumbWriter(file)) > p = htmllib.HTMLParser(fmtr) > return p.feed(html) > > Since the DumbWriter uses stdout, this returns None. When I try to write > to a temporary file, or pipe I get 'bad file descriptor' errors because of > the way external method function I guess. Any help would really be > appreciated. > > All my best, > > > Jason Spisak > [EMAIL PROTECTED] > > ___ > Zope maillist - [EMAIL PROTECTED] > http://lists.zope.org/mailman/listinfo/zope > ** No cross posts or HTML encoding! ** > (Related lists - > http://lists.zope.org/mailman/listinfo/zope-announce > http://lists.zope.org/mailman/listinfo/zope-dev ) > ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] Fighting htmllib in external method
Howdy Zopsters, I want to catalog some html files but I want to strip the html tags out. htmlparser does a good job of that, but when I try to acces that from an external method, I run into trouble. import htmllib import formatter def index(self, html): fmtr = formatter.AbstractFormatter(formatter.DumbWriter(file)) p = htmllib.HTMLParser(fmtr) return p.feed(html) Since the DumbWriter uses stdout, this returns None. When I try to write to a temporary file, or pipe I get 'bad file descriptor' errors because of the way external method function I guess. Any help would really be appreciated. All my best, Jason Spisak [EMAIL PROTECTED] ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
[Zope] Fighting htmllib in external method
Howdy Zopsters, I want to catalog some html files but I want to strip the html tags out. htmlparser does a good job of that, but when I try to acces that from an external method, I run into trouble. import htmllib import formatter def index(self, html): fmtr = formatter.AbstractFormatter(formatter.DumbWriter(file)) p = htmllib.HTMLParser(fmtr) return p.feed(html) Since the DumbWriter uses stdout, this returns None. When I try to write to a temporary file, or pipe I get 'bad file descriptor' errors because of the way external method function I guess. Any help would really be appreciated. All my best, Jason Spisak [EMAIL PROTECTED] ___ Zope maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )