[csw-devel] SF.net SVN: gar:[13334] csw/mgar/gar/v2/lib

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Wed Feb 16 17:33:25 CET 2011


Revision: 13334
          http://gar.svn.sourceforge.net/gar/?rev=13334&view=rev
Author:   wahwah
Date:     2011-02-16 16:33:25 +0000 (Wed, 16 Feb 2011)

Log Message:
-----------
pkgdb-web: Return 'null' when package not found

This way, we can distinguish the case of a package not in catalog from a case
of using a wrong URL.

A JSON 'null' translates to Python None, which evaluates as boolean false.
This way we know there's no package.  When a HTTP 404 error is thrown, it
means that the URL used is wrong.

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

Modified: csw/mgar/gar/v2/lib/python/rest.py
===================================================================
--- csw/mgar/gar/v2/lib/python/rest.py	2011-02-16 16:32:03 UTC (rev 13333)
+++ csw/mgar/gar/v2/lib/python/rest.py	2011-02-16 16:33:25 UTC (rev 13334)
@@ -53,9 +53,7 @@
         "/catalogs/%s/%s/%s/catalognames/%s/"
         % (catrel, arch, osrel, catalogname))
     logging.debug("Srv4ByCatalogAndCatalogname(): GET %s", url)
-    try:
-      data = urllib2.urlopen(url).read()
-      return json.loads(data)
-    except urllib2.HTTPError, e:
-      logging.warning("%s -- %s", url, e)
-      return None
+    # The server is no longer returning 404 when the package is absent.  If
+    # a HTTP error code is returned, we're letting the application fail.
+    data = urllib2.urlopen(url).read()
+    return json.loads(data)

Modified: csw/mgar/gar/v2/lib/web/pkgdb_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/pkgdb_web.py	2011-02-16 16:32:03 UTC (rev 13333)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py	2011-02-16 16:33:25 UTC (rev 13334)
@@ -296,10 +296,10 @@
       mimetype, data = srv4.GetRestRepr()
       web.header('Content-type', mimetype)
       return json.dumps(data)
-    except (
-        sqlobject.main.SQLObjectNotFound,
-        sqlobject.dberrors.OperationalError), e:
-      raise web.notfound()
+    except sqlobject.main.SQLObjectNotFound:
+      return json.dumps(None)
+    except sqlobject.dberrors.OperationalError, e:
+      raise web.internalerror(e)
 
 
 web.webapi.internalerror = web.debugerror


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