def as_unicode(text, encoding=u'utf-8'):
 if isinstance(text, unicode):
  return text
 elif (text == None):
  return u''
 elif isinstance(text, basestring):
  return unicode(text, encoding)
 else:
  return unicode(text)

def as_unicode ( text , encoding = u'utf-8' ) : if isinstance ( text , unicode ) : return text elif ( text == None ) : return u'' elif isinstance ( text , basestring ) : return unicode ( text , encoding ) else : return unicode ( text )
convert to unicode if required .