From: Yaroslav Halchenko Date: Thu, 23 Dec 2010 02:57:04 +0000 (-0500) Subject: BF: fixing unicode issue by decoding str into utf8 if unicode(s) fails -- for long_de... X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=2e3f880dcf9d29a142e7c274ed127e8815dfc20a;p=neurodebian.git BF: fixing unicode issue by decoding str into utf8 if unicode(s) fails -- for long_description only atm --- diff --git a/neurodebian/dde.py b/neurodebian/dde.py index be008f9..c93814b 100755 --- a/neurodebian/dde.py +++ b/neurodebian/dde.py @@ -547,6 +547,24 @@ def import_dde(cfg, db): return db +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)) + def convert_longdescr(ld): ld = ld.replace('% ', '%% ') @@ -578,7 +596,8 @@ def generate_pkgpage(pkg, cfg, db, template, addenum_dir): page = template.render( pkg=pkg, title=title, - long_description=convert_longdescr(pkgdb['main']['long_description']), + long_description=convert_longdescr( + assure_unicode(pkgdb['main']['long_description'])), cfg=cfg, db=pkgdb, fulldb=db)