From fa535af8d439db2e20b34c6e80b2ee86f4255f53 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Tue, 29 Mar 2016 22:22:09 +0000 Subject: rpkic needs to do uid swapping around XML reads too. rpki.irdb.zookeeper.etree_read(), the functions that call it, and the functions that call them, could all use a bit of refactoring. At this point pretty much ever caller is jumping through some hoop or another due to the way the code has evolved, and most of it could be simpler. svn path=/branches/tk705/; revision=6338 --- rpki/irdb/zookeeper.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'rpki/irdb') diff --git a/rpki/irdb/zookeeper.py b/rpki/irdb/zookeeper.py index 9d40263c..bca56926 100644 --- a/rpki/irdb/zookeeper.py +++ b/rpki/irdb/zookeeper.py @@ -150,15 +150,27 @@ class PEM_writer(object): def etree_read(filename_or_etree_wrapper, schema = rpki.relaxng.oob_setup): """ Read an etree from a file, verifying then stripping XML namespace - 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. + 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. + + As a further convenience, we also accept an Element object, + in which case we just validate and return it. + + This function's behavior has changed over time, and the code which + calls it is overdue for refactoring, but the relevant code in + rpki.gui.app.views is a bit complex, so that yak will have to take + a number and wait for its shave, today we have a bug to fix. """ if isinstance(filename_or_etree_wrapper, etree_wrapper): e = copy.deepcopy(filename_or_etree_wrapper.etree) - else: + elif isinstance(filename_or_etree_wrapper, (str, unicode)): e = ElementTree(file = filename_or_etree_wrapper).getroot() + else: + e = filename_or_etree_wrapper schema.assertValid(e) return e -- cgit v1.2.3