xpath_sifter.py and sys.exit(1) behaviour

Sam Ruby rubys at intertwingly.net
Thu Oct 19 00:34:09 EST 2006


Harry Fuecks wrote:
> Trying to use the xpath_sifter.py to limit entries from a feed to a
> particular condition;
> 
> [xpath_sifter.py]
> require:
>  //atom:author/atom:name[1][. = 'HarryF']
> 
> (the entry has multiple authors, hence atom:name[1]).

That checks that the first author is HarryF.  If you drop the [1], it 
will check to see if any author is HarryF.

> If I've understood correctly how filtering and xpath_sifter works, at
> the moment on the first entry that fails the condition, spider.py
> ignores the rest of the _feed_, rather than just skipping the entry
> and going on to the next - not sure if that's intended or not but
> looking at spider.py;

No, that is *not* the intended behavior.  Good catch!

> def spiderFeed(feed):
> 
>    # ...
> 
>    for entry in data.entries:
> 
>        # ...
> 
>        for filter in config.filters(feed):
>            output = shell.run(filter, output, mode="filter")
>            if not output: return
> 
> ...it's returning from the function, so the rest of the feed is
> ignored - shouldn't that be something like;
> 
>        try:
>            for filter in config.filters(feed):
>                output = shell.run(filter, output, mode="filter")
>                if not output: raise Exception
>        except: continue
> 
> ...so just the entry is ignored?

I made a small adjustment:

          for filter in config.filters(feed):
              output = shell.run(filter, output, mode="filter")
              if not output: break
          if not output: continue

My reasons are that I want other exceptions to be processed as they were 
(e.g., to be logged as errors).

Once again, thanks!  This could have gone unnoticed for quite a while.

- Sam Ruby


More information about the devel mailing list