+def assure_unicode(s):
+ """Assure that argument is unicode
+
+ Necessary if strings are not carrying out Pythonish 'u' prefix to
+ signal UTF8 strings, but are in fact UTF8
+ """
+ if type(s) is unicode:
+ return s
+ elif type(s) is str:
+ # attempt regular unicode call and if fails -- just decode it
+ # into utf8
+ try:
+ return unicode(s)
+ except UnicodeDecodeError, e:
+ return s.decode('utf8')
+ else:
+ return assure_unicode(str(s))
+