[csw-devel] SF.net SVN: gar:[16035] csw/mgar/gar/v2/lib/web/pkgdb_web.py

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sun Oct 30 10:07:13 CET 2011


Revision: 16035
          http://gar.svn.sourceforge.net/gar/?rev=16035&view=rev
Author:   wahwah
Date:     2011-10-30 09:07:13 +0000 (Sun, 30 Oct 2011)
Log Message:
-----------
pkgdb-web: A temp workaround for pkginfo encoding

Non-utf-8 encoding of strings in pkginfo crashed the exporter.  Handling one
known case before a generic fix is developed.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/web/pkgdb_web.py

Modified: csw/mgar/gar/v2/lib/web/pkgdb_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/pkgdb_web.py	2011-10-30 00:58:34 UTC (rev 16034)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py	2011-10-30 09:07:13 UTC (rev 16035)
@@ -322,6 +322,18 @@
       pkg = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
       data_structure = pkg.GetStatsStruct()
       web.header('Content-type', 'application/x-vnd.opencsw.pkg;type=pkg-stats')
+      # There was a problem with bad utf-8 in the VENDOR field.
+      # This is a workaround.
+      if "VENDOR" in data_structure["pkginfo"]:
+        vendor = data_structure["pkginfo"]["VENDOR"]
+        if type(vendor) != unicode:
+          try:
+            vendor = unicode(vendor, 'utf-8')
+          except UnicodeDecodeError, e:
+            vendor = vendor.decode("utf-8", "ignore")
+          data_structure["pkginfo"]["VENDOR"] = (
+              vendor + " (bad unicode detected)")
+      # The end of the hack.
       return json.dumps(data_structure, cls=PkgStatsEncoder)
     except sqlobject.main.SQLObjectNotFound, e:
       raise web.notfound()

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list