def to_unicode(data, encoding=u'UTF-8'):
 if isinstance(data, unicode_type):
  return data
 if isinstance(data, bytes_type):
  return unicode_type(data, encoding=encoding)
 if hasattr(data, u'__iter__'):
  try:
   dict(data)
  except TypeError:
   pass
  except ValueError:
   return (to_unicode(i, encoding) for i in data)
  else:
   if hasattr(data, u'items'):
    data = data.items()
   return dict(((to_unicode(k, encoding), to_unicode(v, encoding)) for (k, v) in data))
 return data

def to_unicode ( data , encoding = u'UTF-8' ) : if isinstance ( data , unicode_type ) : return data if isinstance ( data , bytes_type ) : return unicode_type ( data , encoding = encoding ) if hasattr ( data , u'__iter__' ) : try : dict ( data ) except TypeError : pass except ValueError : return ( to_unicode ( i , encoding ) for i in data ) else : if hasattr ( data , u'items' ) : data = data . items ( ) return dict ( ( ( to_unicode ( k , encoding ) , to_unicode ( v , encoding ) ) for ( k , v ) in data ) ) return data
convert strings to unicode objects .