def flags_from_dict(kw):
    """
    This turns a dict with keys that are flags (e.g. for CLOSECIRCUIT,
    CLOSESTREAM) only if the values are true.
    """
    if len(kw) == 0:
        return ''
    flags = ''
    for k, v in kw.items():
        if v:
            flags += ' ' + str(k)
    return flags
