--- a/web/views/urlpublishing.py Tue May 05 17:18:49 2009 +0200
+++ b/web/views/urlpublishing.py Thu May 14 12:48:11 2009 +0200
@@ -18,7 +18,7 @@
because of redirecting instead of direct traversal
:organization: Logilab
-:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
@@ -28,15 +28,15 @@
from cubicweb import RegistryException, typed_eid
from cubicweb.web import NotFound, Redirect
-from cubicweb.web.component import SingletonComponent, Component
+from cubicweb.web.component import Component, Component
class PathDontMatch(Exception):
"""exception used by url evaluators to notify they can't evaluate
a path
"""
-
-class URLPublisherComponent(SingletonComponent):
+
+class URLPublisherComponent(Component):
"""associate url's path to view identifier / rql queries,
by applying a chain of urlpathevaluator components.
@@ -50,33 +50,33 @@
something else than `PathDontMatch` will stop the handlers chain.
"""
id = 'urlpublisher'
-
+
def __init__(self, default_method='view'):
super(URLPublisherComponent, self).__init__()
self.default_method = default_method
- evaluators = []
+ evaluators = []
for evaluatorcls in self.vreg.registry_objects('components',
'urlpathevaluator'):
# instantiation needed
evaluator = evaluatorcls(self)
evaluators.append(evaluator)
self.evaluators = sorted(evaluators, key=lambda x: x.priority)
-
+
def process(self, req, path):
"""given an url (essentialy caracterized by a path on the server,
but additional information may be found in the request object), return
a publishing method identifier (eg controller) and an optional result
set
-
+
:type req: `cubicweb.web.Request`
:param req: the request object
-
+
:type path: str
:param path: the path of the resource to publish
:rtype: tuple(str, `cubicweb.common.utils.ResultSet` or None)
:return: the publishing method identifier and an optional result set
-
+
:raise NotFound: if no handler is able to decode the given path
"""
parts = [part for part in path.split('/')
@@ -97,7 +97,7 @@
pmid = self.default_method
return pmid, rset
-
+
class URLPathEvaluator(Component):
__abstract__ = True
id = 'urlpathevaluator'
@@ -136,7 +136,7 @@
raise NotFound()
return None, rset
-
+
class RestPathEvaluator(URLPathEvaluator):
"""handle path with the form::
@@ -149,7 +149,7 @@
for etype in self.schema.entities():
etype = str(etype)
self.etype_map[etype.lower()] = etype
-
+
def evaluate_path(self, req, parts):
if not (0 < len(parts) < 4):
raise PathDontMatch()
@@ -177,7 +177,7 @@
def cls_rset(self, req, cls):
return req.execute(cls.fetch_rql(req.user))
-
+
def attr_rset(self, req, etype, attrname, value):
rql = u'Any X WHERE X is %s, X %s %%(x)s' % (etype, attrname)
if attrname == 'eid':
@@ -211,7 +211,7 @@
except KeyError:
continue
raise PathDontMatch()
-
+
class ActionPathEvaluator(URLPathEvaluator):
"""handle path with the form::