'Transform \'token;key=val\' to (\'token\', {\'key\': \'val\'}).'

def parse(elementstr):

    atoms = [x.strip() for x in elementstr.split(';') if x.strip()]
    if (not atoms):
        initial_value = ''
    else:
        initial_value = atoms.pop(0).strip()
    params = {}
    for atom in atoms:
        atom = [x.strip() for x in atom.split('=', 1) if x.strip()]
        key = atom.pop(0)
        if atom:
            val = atom[0]
        else:
            val = ''
        params[key] = val
    return (initial_value, params)
