File: xpath_sifter.py

package info (click to toggle)
planet-venus 0~bzr95-2%2Blenny1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,616 kB
  • ctags: 1,981
  • sloc: python: 14,776; xml: 821; makefile: 36; sed: 3
file content (23 lines) | stat: -rw-r--r-- 673 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys, libxml2

# parse options
options = dict(zip(sys.argv[1::2],sys.argv[2::2]))

# parse entry
doc = libxml2.parseDoc(sys.stdin.read())
ctxt = doc.xpathNewContext()
ctxt.xpathRegisterNs('atom','http://www.w3.org/2005/Atom')
ctxt.xpathRegisterNs('xhtml','http://www.w3.org/1999/xhtml')

# process requirements
if options.has_key('--require'):
  for xpath in options['--require'].split('\n'):
     if xpath and not ctxt.xpathEval(xpath): sys.exit(1)

# process exclusions
if options.has_key('--exclude'):
  for xpath in options['--exclude'].split('\n'):
     if xpath and ctxt.xpathEval(xpath): sys.exit(1)

# if we get this far, the feed is to be included
print doc