Use shared util helper for driver name + config extraction

Change-Id: I43465b8f5868e64bdf38d2873417a8a4a403a23b
This commit is contained in:
Joshua Harlow
2015-12-22 17:15:32 -08:00
parent 25a8e4b132
commit c145bef224
3 changed files with 20 additions and 27 deletions

View File

@@ -112,6 +112,19 @@ def countdown_iter(start_at, decr=1):
start_at -= decr
def extract_driver_and_conf(conf, conf_key):
"""Common function to get a driver name and its configuration."""
if isinstance(conf, six.string_types):
conf = {conf_key: conf}
maybe_uri = conf[conf_key]
try:
uri = parse_uri(maybe_uri)
except (TypeError, ValueError):
return (maybe_uri, conf)
else:
return (uri.scheme, merge_uri(uri, conf.copy()))
def reverse_enumerate(items):
"""Like reversed(enumerate(items)) but with less copying/cloning..."""
for i in countdown_iter(len(items)):