aboutsummaryrefslogtreecommitdiff
path: root/rpki/irdb/zookeeper.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2015-10-15 12:45:25 +0000
committerRob Austein <sra@hactrn.net>2015-10-15 12:45:25 +0000
commit11dc3020ea0e91326599d45289fc003adb145443 (patch)
treea04253598b41fe1242d25d8a531c5952ca86e8a2 /rpki/irdb/zookeeper.py
parent693283f75648b06bc927405ea3af1686a376d87b (diff)
Extend rpki.irdb.zookeeper.etree_read() to support reading directly
from an etree_wrapper object, bypassing the filesystem entirely. svn path=/branches/tk705/; revision=6117
Diffstat (limited to 'rpki/irdb/zookeeper.py')
-rw-r--r--rpki/irdb/zookeeper.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/rpki/irdb/zookeeper.py b/rpki/irdb/zookeeper.py
index e23d5483..854ed9e9 100644
--- a/rpki/irdb/zookeeper.py
+++ b/rpki/irdb/zookeeper.py
@@ -128,13 +128,18 @@ class PEM_writer(object):
self.wrote.add(filename)
-def etree_read(filename):
+def etree_read(filename_or_etree_wrapper):
"""
Read an etree from a file, verifying then stripping XML namespace
- cruft.
+ cruft. As a convenience, we also accept an etree_wrapper object in
+ place of a filename, in which case we deepcopy the etree directly
+ from the etree_wrapper and there's no need for a file.
"""
- e = ElementTree(file = filename).getroot()
+ if isinstance(filename_or_etree_wrapper, etree_wrapper):
+ e = copy.deepcopy(filename_or_etree_wrapper.etree)
+ else:
+ e = ElementTree(file = filename_or_etree_wrapper).getroot()
rpki.relaxng.myrpki.assertValid(e)
for i in e.getiterator():
if i.tag.startswith(myrpki_xmlns):