human
Complete this python program:
def _encode_metadata(metadata):
assistant
#Here is the Python code you requested.

    """UTF8 encode any unicode keys or values in given metadata dict.
    :param metadata: a dict
    """
    def encode_str(item):
        if isinstance(item, six.text_type):
            return item.encode('utf8')
        return item
    return dict(((encode_str(k), encode_str(v)) for (k, v) in metadata.items()))