def to_utf8(x):
    """
    Tries to utf-8 encode x when possible 

    If x is a string returns it encoded, otherwise tries to iter x and 
    encode utf-8 all strings it contains, returning a list.
    """
    if isinstance(x, basestring): 
        return x.encode('utf-8') if isinstance(x, unicode) else x
    try:
        l = iter(x)
    except __HOLE__:
        return x
    return [to_utf8(i) for i in l]
dataset/ETHPy150Open maraujop/requests-oauth/oauth_hook/auth.py/to_utf8