def keywords_encode(d):
    """ Takes a dictionary of keywords and encodes them into a somewhat
    readable url query format.

    For example:

        {
            'color': ['blue', 'red'],
            'weight': ['normal']
        }

    Results in

        '+color:blue+color:red+weight:normal'

    Instead of a dictionary we can also use any kind of object
    which has a 'keywords' property returning the expected dictionary.

    Note that that object won't be recreated during decode however.

    """

    if not d:
        return ''

    if hasattr(d, 'keywords'):
        d = d.keywords

    return '+'.join('{}:{}'.format(k, v) for k in d for v in d[k])