Teach PrestHandler to handle bad paths cleanly
authorAaron Bentley <abentley@panoramicfeedback.com>
Wed, 12 Apr 2006 14:38:01 +0000 (10:38 -0400)
committerAaron Bentley <abentley@panoramicfeedback.com>
Wed, 12 Apr 2006 14:38:01 +0000 (10:38 -0400)
Bugs-Everywhere-Web/beweb/prest.py

index e6b7cdfeb4c4dfafdf7166f2b34341c6df97d8e2..9a6505d8b629bd0ca3456fdefdb6d4018bb23c2e 100644 (file)
@@ -1,5 +1,6 @@
 from unittest import TestCase
 import unittest
+from cherrypy import NotFound
 """A pseudo-REST dispatching method in which only the noun comes from the path.
 The action performed will depend on kwargs.
 """
@@ -43,12 +44,20 @@ class PrestHandler(object):
             if len(path) == 0:
                 resource = None
             else:
-                resource = self.instantiate(**data)
+                try:
+                    resource = self.instantiate(**data)
+                except NotImplementedError, e:
+                    if e.args[0] is not PrestHandler.instantiate:
+                        raise NotFound()
+
             return self, resource, data, path[1:] 
         if len(path) > 2:
             data[path[1]] = path[2]
         return getattr(self, path[1]).decode(path[2:], data)
 
+    def instantiate(self, **date):
+        raise NotImplementedError(PrestHandler.instantiate)
+
     def default(self, *args, **kwargs):
         child, resource, data, extra = self.decode([None,] + list(args))
         action = child.get_action(**kwargs)