Author: tille
Date: Wed Apr 21 20:13:30 2010
New Revision: 2140
URL: http://svn.debian.org/viewsvn/blends?rev=2140&view=rev

Log:
Saver handling of unicode, solves different versions of python-debian as well 
as Taiwanese translations


Added:
   blends/trunk/webtools/blendsunicode.py
Modified:
   blends/trunk/webtools/blendsmarkdown.py
   blends/trunk/webtools/blendstasktools.py
   blends/trunk/webtools/tasks.py

Modified: blends/trunk/webtools/blendsmarkdown.py
URL: 
http://svn.debian.org/viewsvn/blends/blends/trunk/webtools/blendsmarkdown.py?rev=2140&view=diff&r1=2140&r2=2139&p1=blends/trunk/webtools/blendsmarkdown.py&p2=blends/trunk/webtools/blendsmarkdown.py
==============================================================================
--- blends/trunk/webtools/blendsmarkdown.py     (original)
+++ blends/trunk/webtools/blendsmarkdown.py     Wed Apr 21 20:13:30 2010
@@ -74,7 +74,7 @@
             print >>stderr, "Unable to render the following prepared text:\n" 
+ MarkDownInput
             LongDesc = "Problems in rendering description using reST"
     else: # by default use Markdown
-        LongDesc = markdown(unicode(MarkDownInput, 'utf-8'))  ## perhaps 
decoding afterwards might be needed
+        LongDesc = markdown(MarkDownInput)
     return LongDesc
 
 def SplitDescription(description):

Modified: blends/trunk/webtools/blendstasktools.py
URL: 
http://svn.debian.org/viewsvn/blends/blends/trunk/webtools/blendstasktools.py?rev=2140&view=diff&r1=2140&r2=2139&p1=blends/trunk/webtools/blendstasktools.py&p2=blends/trunk/webtools/blendstasktools.py
==============================================================================
--- blends/trunk/webtools/blendstasktools.py    (original)
+++ blends/trunk/webtools/blendstasktools.py    Wed Apr 21 20:13:30 2010
@@ -36,6 +36,7 @@
 from blendsmarkdown import SplitDescription, MarkupString, render_longdesc
 
 from debian_bundle import deb822
+from blendsunicode import to_unicode
 
 # Seems to have problems on 17.04.2009
 # BASEURL  = 'http://ftp.debian.org/debian'
@@ -687,10 +688,10 @@
         for row in RowDictionaries(curs):
             for prop in PROPERTIES:
                 self.properties[prop] = row[prop]
-            self.desc['en']['short'] = 
MarkupString(unicode(row['description'], 'utf-8'), self.pkg, 'ShortDesc')
-            self.desc['en']['long']  = 
Markup(render_longdesc(row['long_description'].splitlines()))
+            self.desc['en']['short'] = 
MarkupString(to_unicode(row['description']), self.pkg, 'ShortDesc')
+            self.desc['en']['long']  = 
Markup(render_longdesc(to_unicode(row['long_description']).splitlines()))
             (_name, _url) = email.Utils.parseaddr(row['maintainer'])
-            self.properties['maintainer'] = unicode(row['maintainer'], 'utf-8')
+            self.properties['maintainer'] = to_unicode(row['maintainer'])
             self.responsible = '<a href="mailto:%s";>%s</a>' % (_url, 
unicode(_name, 'utf-8'))
 
         if self.properties.has_key('source'):
@@ -731,8 +732,8 @@
             for row in RowDictionaries(curs):
                 lang = row['language']
                 self.desc[lang] = {}
-                self.desc[lang]['short'] = 
MarkupString(unicode(row['description'], 'utf-8'), self.pkg, 'ShortDesc - ' + 
lang)
-                self.desc[lang]['long']  = 
Markup(render_longdesc(row['long_description'].splitlines()))
+                self.desc[lang]['short'] = 
MarkupString(to_unicode(row['description']), self.pkg, 'ShortDesc - ' + lang)
+                self.desc[lang]['long']  = 
Markup(render_longdesc(to_unicode(row['long_description']).splitlines()))
 
             query = "EXECUTE query_get_latest_uploader ('%s')" % (self.src)
             curs.execute(query)
@@ -1098,7 +1099,7 @@
             for key in stanza:
                 if key == 'Task':
                     # also the task name might be utf-8 encoded
-                    self.metapkg.PrintedName = unicode(stanza['task'], 'utf-8')
+                    self.metapkg.PrintedName = to_unicode(stanza['task'])
                     continue
                 if key == 'Description':
                     (short, long) = SplitDescription(stanza['description'])
@@ -1138,7 +1139,7 @@
                                                   self.metapkg.PrintedName, 
'taskShortDesc - ' + lang)
 
                             try:
-                                self.metapkg.desc[lang]['long'] = 
Markup(render_longdesc(row['long_description'].splitlines()))
+                                self.metapkg.desc[lang]['long'] = 
Markup(render_longdesc(to_unicode(row['long_description']).splitlines()))
                             except UnicodeDecodeError, err:
                                 print >> stderr, "===> UnicodeDecodeError in 
metapackage long %s (lang='%s'): '%s'; ErrTxt: %s" % \
                                     (self.metapkg.pkg, lang, 
row['long_description'], err)
@@ -1167,7 +1168,7 @@
                         continue
                     if responsible != '':
                         (_name, _url) = email.Utils.parseaddr(responsible)
-                        dep.responsible = '<a href="mailto:%s";>%s</a>' % 
(_url, unicode(_name, 'utf-8'))
+                        dep.responsible = '<a href="mailto:%s";>%s</a>' % 
(_url, to_unicode(_name))
                     continue
 
                 if key in dep_strength_keys:
@@ -1235,7 +1236,7 @@
                     if dep != None:
                         # set Homepage only if not just set via official 
package information
                         if dep.properties['homepage'] == HOMEPAGENONE:
-                            dep.properties['homepage'] = 
unicode(stanza['homepage'], 'utf-8')
+                            dep.properties['homepage'] = 
to_unicode(stanza['homepage'])
                         else:
                             fields_obsolete.append(key)
                     else:
@@ -1327,7 +1328,7 @@
                         if not dep.properties.has_key('published'):
                             dep.properties['published'] = {}
                         ptype = key.replace('Published-','').lower()
-                        dep.properties['published'][ptype] = 
unicode(stanza[key.lower()], 'utf-8')
+                        dep.properties['published'][ptype] = 
to_unicode(stanza[key.lower()])
                     else:
                         print >>stderr, "Dep not initiated before %s %s -> 
something is wrong." \
                               % (key, stanza[key.lower()])
@@ -1362,7 +1363,7 @@
                     else:
                         # Only update use description from task file if not 
known from official package
                         if dep.desc['en'] == {}:
-                            (short, long) = 
SplitDescription(stanza['pkg-description'])
+                            (short, long) = 
SplitDescription(to_unicode(stanza['pkg-description']))
                             # If here would be used
                             #    unicode(long, 'utf-8')
                             # this would lead to TypeError problems - and in 
the end it does not prevent

Added: blends/trunk/webtools/blendsunicode.py
==============================================================================
--- (empty file)
+++ blends/trunk/webtools/blendsunicode.py      Wed Apr 21 20:13:30 2010
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+# Copyright 2010: Andreas Tille <[email protected]>
+# License: GPL
+
+# Handle UTF-8 encoded strings as well as unicode to cope
+# with different versions of python-debian
+#    python-debian <0.15 returns string; >=0.15 returns unicode
+
+def to_unicode(value, encoding='utf-8'):
+    if isinstance(value, str):
+        return value.decode(encoding)
+    else:
+        return unicode(value)
+
+# from types import *
+#def my_unicode(str):
+#    if type(str) is StringType:
+#        return unicode(str, 'utf-8')
+#    elif type(str) is UnicodeType:
+#        return str
+#    else:
+#        print >>stderr, "Unknown type of string:", type(str), "\n", str
+#        return '???'

Modified: blends/trunk/webtools/tasks.py
URL: 
http://svn.debian.org/viewsvn/blends/blends/trunk/webtools/tasks.py?rev=2140&view=diff&r1=2140&r2=2139&p1=blends/trunk/webtools/tasks.py&p2=blends/trunk/webtools/tasks.py
==============================================================================
--- blends/trunk/webtools/tasks.py      (original)
+++ blends/trunk/webtools/tasks.py      Wed Apr 21 20:13:30 2010
@@ -18,6 +18,7 @@
 from genshi.template.eval import UndefinedError
 
 from blendstasktools import Tasks, GetDependencies2Use, pkgstatus, 
pkgstatus_sortedkeys
+from blendsunicode import to_unicode
 
 # The keys of the following dictionary are used to address the translation 
files of DDTP
 # The values contain dictionaries in turn with the following meaning:
@@ -111,30 +112,30 @@
        l10nstring[lang].install()
        _ = l10nstring[lang].ugettext
        data['lang']              = lang
-       data['license']           = _('License')
-       data['version']           = _('Version')
-        data['summary']           = _('Summary')
-       data['updatetimestamp']   = _('Last update:') + ' ' + 
formatdate(time.mktime(t.timetuple()))
-        data['nopkgavail']        = _('Debian package not available')
+       data['license']           = to_unicode(_('License'))
+       data['version']           = to_unicode(_('Version'))
+        data['summary']           = to_unicode(_('Summary'))
+       data['updatetimestamp']   = to_unicode(_('Last update:')) + ' ' + 
formatdate(time.mktime(t.timetuple()))
+        data['nopkgavail']        = to_unicode(_('Debian package not 
available'))
        # Description of package in specific packges (same for Depends, 
Recommends, Suggests)
-        data['legend']            = _("For a better overview of the project's 
availability as a Debian package, each head row has a color code according to 
this scheme:")
-        data['discovery']         = Markup(_("""If you discover a project 
which looks like a good candidate for %s
+        data['legend']            = to_unicode(_("For a better overview of the 
project's availability as a Debian package, each head row has a color code 
according to this scheme:"))
+        data['discovery']         = Markup(to_unicode(_("""If you discover a 
project which looks like a good candidate for %s
                               to you, or if you have prepared an unofficial 
Debian package, please do not hesitate to
                               send a description of that project to the <a 
href="mailto:%s";>%s mailing list</a>""") % \
-                                  (data['projectname'], data['projectlist'], 
data['projectname']))
-        data['description']       = _("The list to the right includes various 
software projects which are of some interest to the %s Project. Currently, only 
a few of them are available as Debian packages. It is our goal, however, to 
include all software in %s which can sensibly add to a high quality Debian Pure 
Blend.") % (data['projectname'], data['projectname'])
-       data['gtstrTasksPage']     = _('Tasks page')
-       data['gtstrProject']       = _('Project')
-       data['gtstrThisIsAList']   = _('This is a list of the Tasks %s is made 
of:') % data['projectname']
-       data['langavail']          = _('This page is also available in the 
following languages:')
-       data['howtosetlang']       = _('How to set <a href="%s">the default 
document language</a>')
-       data['howtosetlang']       = Markup(data['howtosetlang'] % 
('http://www.debian.org/intro/cn.%s.html' % lang))
-       data['nohomepage']         = _('Homepage not available')
-       data['translatedesc']      = _('Translate description')
-       data['fixtranslation']     = _('Fix translated description')
-       data['popconexplanation']  = _('Popularitycontest results: number of 
people who use this package regularly (number of people who upgraded this 
package recently) out of')
-       data['tableofcontents']    = _('Table of contents')
-       data['packagelist']        = _('complete packagelist')
+                                  (data['projectname'], data['projectlist'], 
data['projectname'])))
+        data['description']       = to_unicode(_("The list to the right 
includes various software projects which are of some interest to the %s 
Project. Currently, only a few of them are available as Debian packages. It is 
our goal, however, to include all software in %s which can sensibly add to a 
high quality Debian Pure Blend.") % (data['projectname'], data['projectname']))
+       data['gtstrTasksPage']     = to_unicode(_('Tasks page'))
+       data['gtstrProject']       = to_unicode(_('Project'))
+       data['gtstrThisIsAList']   = to_unicode(_('This is a list of the Tasks 
%s is made of:') % data['projectname'])
+       data['langavail']          = to_unicode(_('This page is also available 
in the following languages:'))
+       data['howtosetlang']       = to_unicode(_('How to set <a href="%s">the 
default document language</a>'))
+       data['howtosetlang']       = Markup(to_unicode(data['howtosetlang'] % 
('http://www.debian.org/intro/cn.%s.html' % lang)))
+       data['nohomepage']         = to_unicode(_('Homepage not available'))
+       data['translatedesc']      = to_unicode(_('Translate description'))
+       data['fixtranslation']     = to_unicode(_('Fix translated description'))
+       data['popconexplanation']  = to_unicode(_('Popularitycontest results: 
number of people who use this package regularly (number of people who upgraded 
this package recently) out of'))
+       data['tableofcontents']    = to_unicode(_('Table of contents'))
+       data['packagelist']        = to_unicode(_('complete packagelist'))
        if data['advertising'] != None:
                # If data['advertising'] is enclosed in _() gettext tries to 
ask for translations of 'advertising'
                # which makes no sense.  That's why this is masked by an extra 
string variable
@@ -142,37 +143,37 @@
                ##data['projectadvertising'] = _(advertising) # Hopefully 
translation will work this way ...
                # Genshi needs explicite information that it is dealing with an 
UTF-8 string which should not be changed
                advertising = _(advertising)
-               data['projectadvertising'] = Markup(unicode(advertising))# , 
'utf-8'))
+               data['projectadvertising'] = Markup(to_unicode(advertising))
        else:
                data['projectadvertising'] = None
 
-        data['packages']          = _('Packages')
-       data['idxsummary']        = _("""A %sDebian Pure Blend%s is a Debian 
internal project which assembles
+        data['packages']          = to_unicode(_('Packages'))
+       data['idxsummary']        = to_unicode(_("""A %sDebian Pure Blend%s is 
a Debian internal project which assembles
 a set of packages that might help users to solve certain tasks of their work.  
The list on
 the right shows the tasks of %s.""" ) \
-                                      % ('<a 
href="http://blends.alioth.debian.org/blends/";>', '</a>', data['projectname'])
-       data['idxsummary']        = Markup(data['idxsummary'])
+                                      % ('<a 
href="http://blends.alioth.debian.org/blends/";>', '</a>', data['projectname']))
+       data['idxsummary']        = Markup(to_unicode(data['idxsummary']))
 
 
-       pkgstatus['official_high']['headline']    = _('Official Debian packages 
with high relevance')
+       pkgstatus['official_high']['headline']    = to_unicode(_('Official 
Debian packages with high relevance'))
        # before fiddling around with unicode() read
        # 
http://www.red-mercury.com/blog/eclectic-tech/python-unicode-fixing-utf-8-encoded-as-latin-1-iso-8859-1/
-       pkgstatus['official_high']['pdolinkname'] = _('Official Debian package')
-       pkgstatus['official_low'] ['headline']    = _('Official Debian packages 
with lower relevance')
+       pkgstatus['official_high']['pdolinkname'] = to_unicode(_('Official 
Debian package'))
+       pkgstatus['official_low'] ['headline']    = to_unicode(_('Official 
Debian packages with lower relevance'))
        pkgstatus['official_low'] ['pdolinkname'] = 
pkgstatus['official_high']['pdolinkname']
-       pkgstatus['non-free']     ['headline']    = _('Debian packages in 
contrib or non-free')
-       pkgstatus['non-free']     ['pdolinkname'] = _('Debian package in 
contrib/non-free')
-       pkgstatus['experimental'] ['headline']    = _('Debian packages in 
experimental')
-       pkgstatus['experimental'] ['pdolinkname'] = _('Debian package in 
experimental')
-       pkgstatus['new']          ['headline']    = _('Debian packages in New 
queue (hopefully available soon)')
-       pkgstatus['new']          ['pdolinkname'] = _('New Debian package')
-       pkgstatus['pkgvcs']       ['headline']    = _('Packaging has started 
and developers might try the packaging code in VCS')
-       pkgstatus['pkgvcs']       ['pdolinkname'] = _('Unofficial Debian 
package')
-       pkgstatus['unofficial']   ['headline']    = _('Unofficial packages 
built by somebody else')
+       pkgstatus['non-free']     ['headline']    = to_unicode(_('Debian 
packages in contrib or non-free'))
+       pkgstatus['non-free']     ['pdolinkname'] = to_unicode(_('Debian 
package in contrib/non-free'))
+       pkgstatus['experimental'] ['headline']    = to_unicode(_('Debian 
packages in experimental'))
+       pkgstatus['experimental'] ['pdolinkname'] = to_unicode(_('Debian 
package in experimental'))
+       pkgstatus['new']          ['headline']    = to_unicode(_('Debian 
packages in New queue (hopefully available soon)'))
+       pkgstatus['new']          ['pdolinkname'] = to_unicode(_('New Debian 
package'))
+       pkgstatus['pkgvcs']       ['headline']    = to_unicode(_('Packaging has 
started and developers might try the packaging code in VCS'))
+       pkgstatus['pkgvcs']       ['pdolinkname'] = to_unicode(_('Unofficial 
Debian package'))
+       pkgstatus['unofficial']   ['headline']    = to_unicode(_('Unofficial 
packages built by somebody else'))
        pkgstatus['unofficial']   ['pdolinkname'] = 
pkgstatus['pkgvcs']['pdolinkname']
-       pkgstatus['prospective']  ['headline']    = _('No known packages 
available')
-       pkgstatus['prospective']  ['pdolinkname'] = _('Debian package not 
available')
-       pkgstatus['wnpp']         ['headline']    = _('No known packages 
available but some record of interest (WNPP bug)')
+       pkgstatus['prospective']  ['headline']    = to_unicode(_('No known 
packages available'))
+       pkgstatus['prospective']  ['pdolinkname'] = to_unicode(_('Debian 
package not available'))
+       pkgstatus['wnpp']         ['headline']    = to_unicode(_('No known 
packages available but some record of interest (WNPP bug)'))
        pkgstatus['wnpp']         ['pdolinkname'] = 
pkgstatus['prospective']['pdolinkname']
        # Ignore/Avoid is only relevant for blends-dev, not webtools
        pkgstatus['ignore']       ['headline']    = 'Should not show up here'
@@ -218,12 +219,12 @@
 
        # I18n for headlines, link description, maintainer
        for status in use_dependencystatus:
-               data['headline'][status]   = 
Markup(pkgstatus[status]['headline'])
-               data['pdolinkname'][status]= 
Markup(pkgstatus[status]['pdolinkname'])
+               data['headline'][status]   = 
Markup(to_unicode(pkgstatus[status]['headline']))
+               data['pdolinkname'][status]= 
Markup(to_unicode(pkgstatus[status]['pdolinkname']))
                if pkgstatus[status]['order'] <= 
pkgstatus['experimental']['order']:
-                       data['maintainer'][status] = _('Maintainer')
+                       data['maintainer'][status] = to_unicode(_('Maintainer'))
                else:
-                       data['maintainer'][status] = _('Responsible')
+                       data['maintainer'][status] = 
to_unicode(_('Responsible'))
 
        for task in data['taskskeys']:
                data['task']               = task

_______________________________________________
Blends-commit mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/blends-commit

Reply via email to