From 2e3f880dcf9d29a142e7c274ed127e8815dfc20a Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 22 Dec 2010 21:57:04 -0500 Subject: [PATCH] BF: fixing unicode issue by decoding str into utf8 if unicode(s) fails -- for long_description only atm --- neurodebian/dde.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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) -- 2.39.5