aboutsummaryrefslogtreecommitdiff
path: root/scripts/rpki/sax_utils.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-07-12 01:18:31 +0000
committerRob Austein <sra@hactrn.net>2007-07-12 01:18:31 +0000
commit0c615497e477b40d1a7b68b5575ae5d0b1ed6b80 (patch)
tree683b0faec0ab193a6f9083b9c2ecd1c2e1704911 /scripts/rpki/sax_utils.py
parent2702e7702442df3f44d8f70d11add746d6b94fd1 (diff)
Checkpoint
svn path=/docs/left-right-xml; revision=753
Diffstat (limited to 'scripts/rpki/sax_utils.py')
-rw-r--r--scripts/rpki/sax_utils.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/scripts/rpki/sax_utils.py b/scripts/rpki/sax_utils.py
index 6497699a..4d47f24a 100644
--- a/scripts/rpki/sax_utils.py
+++ b/scripts/rpki/sax_utils.py
@@ -2,20 +2,24 @@
import xml.sax
-def snarf(obj, attrs, key, func=None):
+def snarf_attribute(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)
+ if isinstance(key, list) or isinstance(key, tuple):
+ for k in key:
+ snarf_attribute(obj, attrs, k, func)
+ else:
+ 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):
"""
@@ -38,7 +42,7 @@ class handler(xml.sax.handler.ContentHandler):
self.text += content
def get_text(self):
- val = self.text
+ val = self.text.encode("ascii")
self.text = ""
return val