+ def parse_driverstring(self, ds):
+ '''Dissects the driver string and returns a tuple consiting of
+ the driver name and the options (as a dictionary).'''
+
+ def parse_option(k, v):
+ '''Parse the value for a single option.'''
+ try:
+ ck = sr.ConfigKey.get_by_identifier(k)
+ except:
+ raise ValueError('No option named "{}".'.format(k))
+
+ try:
+ val = ck.parse_string(v)
+ except:
+ raise ValueError(
+ 'Invalid value "{}" for option "{}"'.format(v, k))
+
+ return (k, val)
+
+ m = re.match('(?P<name>[^:]+)(?P<opts>(:[^:=]+=[^:=]+)*)$', ds)
+ if not m:
+ raise ValueError('"{}" is not a valid driver string.'.format(ds))
+
+ opts = m.group('opts').split(':')[1:]
+ opts = [tuple(kv.split('=')) for kv in opts]
+ opts = [parse_option(k, v) for (k, v) in opts]
+ opts = dict(opts)
+
+ return (m.group('name'), opts)
+