summaryrefslogtreecommitdiffstats
path: root/custodia
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2015-04-01 14:14:44 -0400
committerSimo Sorce <simo@redhat.com>2015-04-01 20:21:43 -0400
commit13f91045b2481710763e7bf58ac542f19f349bd4 (patch)
tree6633e9c23c51a23c032fdba251a286b41884ba10 /custodia
parentce33244e99c311856b405aa36acbd7f35db393ab (diff)
downloadcustodia-13f91045b2481710763e7bf58ac542f19f349bd4.tar.gz
custodia-13f91045b2481710763e7bf58ac542f19f349bd4.tar.xz
custodia-13f91045b2481710763e7bf58ac542f19f349bd4.zip
Consumers can define entire subtrees
Each "page" is added to a parent consumer by callin add_sub() on the desired parent and provide a "page name" and the consumer class that handles it.
Diffstat (limited to 'custodia')
-rw-r--r--custodia/httpd/consumer.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/custodia/httpd/consumer.py b/custodia/httpd/consumer.py
index 700c4f8..8f86ebf 100644
--- a/custodia/httpd/consumer.py
+++ b/custodia/httpd/consumer.py
@@ -13,13 +13,36 @@ class HTTPConsumer(object):
self.store_name = None
if config and 'store' in config:
self.store_name = config['store']
+ self.store = None
+ self.subs = dict()
+ self.root = self
- def handle(self, request):
+ def add_sub(self, name, sub):
+ self.subs[name] = sub
+ if hasattr(sub, 'root'):
+ sub.root = self.root
+
+ def _find_handler(self, request):
+ base = self
command = request.get('command', 'GET')
- if not hasattr(self, command):
+ trail = request.get('trail', None)
+ if trail is not None:
+ for comp in trail:
+ subs = getattr(base, 'subs', {})
+ if comp in subs:
+ base = subs[comp]
+ trail.pop(0)
+ else:
+ break
+
+ handler = getattr(base, command)
+ if handler is None:
raise HTTPError(400)
- handler = getattr(self, command)
+ return handler
+
+ def handle(self, request):
+ handler = self._find_handler(request)
response = {'headers': dict()}
# Handle request