diff options
author | Rob Austein <sra@hactrn.net> | 2007-07-11 18:15:19 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2007-07-11 18:15:19 +0000 |
commit | 26f34227a333db277f99aa67f038fa7174c6369f (patch) | |
tree | 5f5d5ab9fb1b1ad8f23ea384b71659c48130120c /scripts/rpki/sax_handler.py | |
parent | 3f6558dc3e67768c92b314c95b8fb19d8fb4ab53 (diff) |
Checkpoint
svn path=/scripts/rpki/left_right.py; revision=750
Diffstat (limited to 'scripts/rpki/sax_handler.py')
-rw-r--r-- | scripts/rpki/sax_handler.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/rpki/sax_handler.py b/scripts/rpki/sax_handler.py new file mode 100644 index 00000000..b4259d2a --- /dev/null +++ b/scripts/rpki/sax_handler.py @@ -0,0 +1,38 @@ +# $Id$ + +import xml.sax + +def snarf(obj, attrs, key, func=None): + """ + Utility function to consolidate the steps needed to extract a field + from the SAX XML parse and insert it as an object attribute of the + same name. + """ + + try: + val = attrs.getValue(key).encode("ascii") + if func: + val = func(val) + except KeyError: + val = None + setattr(obj, key, val) + +class handler(xml.sax.handler.ContentHandler): + """ + SAX handler for RPKI protocols. Handles a few tasks + common to all of these protocols, needs to be subtyped + to handle protocol-specific details. + """ + + def __init__(self): + self.text = "" + self.obj = None + + def startElementNS(self, name, qname, attrs): + return self.startElement(name[1], attrs) + + def endElementNS(self, name, qname): + return self.endElement(name[1]) + + def characters(self, content): + self.text += content |