Encode every value of a dict to UTF-8.

    Useful for POSTing requests on the 'data' parameter of urlencode.

def encoded_dict(in_dict):
    """Encode every value of a dict to UTF-8.

    Useful for POSTing requests on the 'data' parameter of urlencode.
    """
    out_dict = {}
    for k, v in in_dict.items():
        if isinstance(v, unicode):
            if sys.version_info < (3, 0):
                v = v.encode('utf8')
        elif isinstance(v, str):
            # Must be encoded in UTF-8
            if sys.version_info < (3, 0):
                v.decode('utf8')
        out_dict[k] = v
    return out_dict