R propagate registry API changes
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Tue, 11 Aug 2009 13:01:56 +0200
changeset 2770 356e9d7c356d
parent 2769 1800aa0bf396
child 2771 8074dd88e21b
R propagate registry API changes
appobject.py
cwvreg.py
dbapi.py
devtools/testlib.py
etwist/server.py
vregistry.py
web/controller.py
web/facet.py
web/test/unittest_views_navigation.py
web/views/basetemplates.py
web/views/navigation.py
web/views/urlpublishing.py
wsgi/handler.py
--- a/appobject.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/appobject.py	Tue Aug 11 13:01:56 2009 +0200
@@ -377,8 +377,8 @@
         # try to get page boundaries from the navigation component
         # XXX we should probably not have a ref to this component here (eg in
         #     cubicweb.common)
-        nav = self.vreg['components'].select_object('navigation', self.req,
-                                                    rset=self.rset)
+        nav = self.vreg['components'].select_or_none('navigation', self.req,
+                                                     rset=self.rset)
         if nav:
             start, stop = nav.page_boundaries()
             rql = self._limit_offset_rql(stop - start, start)
--- a/cwvreg.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/cwvreg.py	Tue Aug 11 13:01:56 2009 +0200
@@ -69,7 +69,7 @@
         return obj.render(**kwargs)
 
     def select_vobject(self, oid, *args, **kwargs):
-        selected = self.select_object(oid, *args, **kwargs)
+        selected = self.select_or_none(oid, *args, **kwargs)
         if selected and selected.propval('visible'):
             return selected
         return None
@@ -172,7 +172,7 @@
             if vid[0] == '_':
                 continue
             try:
-                view = self.select_best(views, req, rset=rset, **kwargs)
+                view = self._select_best(views, req, rset=rset, **kwargs)
                 if view.linkable():
                     yield view
             except NoSelectableObject:
@@ -389,17 +389,17 @@
     def possible_actions(self, req, rset=None, **kwargs):
         return self["actions"].possible_actions(req, rest=rset, **kwargs)
 
-    @deprecated("use vreg['boxes'].select_object(...)")
+    @deprecated("use vreg['boxes'].select_or_none(...)")
     def select_box(self, oid, *args, **kwargs):
-        return self['boxes'].select_object(oid, *args, **kwargs)
+        return self['boxes'].select_or_none(oid, *args, **kwargs)
 
-    @deprecated("use vreg['components'].select_object(...)")
+    @deprecated("use vreg['components'].select_or_none(...)")
     def select_component(self, cid, *args, **kwargs):
-        return self['components'].select_object(cid, *args, **kwargs)
+        return self['components'].select_or_none(cid, *args, **kwargs)
 
-    @deprecated("use vreg['actions'].select_object(...)")
+    @deprecated("use vreg['actions'].select_or_none(...)")
     def select_action(self, oid, *args, **kwargs):
-        return self['actions'].select_object(oid, *args, **kwargs)
+        return self['actions'].select_or_none(oid, *args, **kwargs)
 
     @deprecated("use vreg['views'].select(...)")
     def select_view(self, __vid, req, rset=None, **kwargs):
--- a/dbapi.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/dbapi.py	Tue Aug 11 13:01:56 2009 +0200
@@ -42,9 +42,9 @@
     registries.
     """
     defaultcls = cwvreg.VRegistry.REGISTRY_FACTORY[None]
-    orig_select_best = defaultcls.orig_select_best = defaultcls.select_best
+    orig_select_best = defaultcls.orig_select_best = defaultcls._select_best
     @monkeypatch(defaultcls)
-    def select_best(self, appobjects, *args, **kwargs):
+    def _select_best(self, appobjects, *args, **kwargs):
         """return an instance of the most specific object according
         to parameters
 
--- a/devtools/testlib.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/devtools/testlib.py	Tue Aug 11 13:01:56 2009 +0200
@@ -284,7 +284,7 @@
                      and not issubclass(view, NotificationView)]
             if views:
                 try:
-                    view = viewsvreg.select_best(views, req, rset=rset)
+                    view = viewsvreg._select_best(views, req, rset=rset)
                     if view.linkable():
                         yield view
                     else:
@@ -392,7 +392,7 @@
         try:
             orig_select_best = reg.__class__.__orig_select_best
         except:
-            orig_select_best = reg.__class__.select_best
+            orig_select_best = reg.__class__._select_best
         def instr_select_best(self, *args, **kwargs):
             selected = orig_select_best(self, *args, **kwargs)
             try:
@@ -402,7 +402,7 @@
             except AttributeError:
                 pass # occurs on reg used to restore database
             return selected
-        reg.__class__.select_best = instr_select_best
+        reg.__class__._select_best = instr_select_best
         reg.__class__.__orig_select_best = orig_select_best
 
 def print_untested_objects(testclass, skipregs=('hooks', 'etypes')):
--- a/etwist/server.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/etwist/server.py	Tue Aug 11 13:01:56 2009 +0200
@@ -116,7 +116,7 @@
         start_task(interval, self.appli.session_handler.clean_sessions)
 
     def set_url_rewriter(self):
-        self.url_rewriter = self.appli.vreg['components'].select_object('urlrewriter')
+        self.url_rewriter = self.appli.vreg['components'].select_or_none('urlrewriter')
 
     def shutdown_event(self):
         """callback fired when the server is shutting down to properly
--- a/vregistry.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/vregistry.py	Tue Aug 11 13:01:56 2009 +0200
@@ -243,12 +243,12 @@
         """
         return self[registry].select(oid, *args, **kwargs)
 
-    @deprecated('use vreg[registry].select_object(oid, *args, **kwargs)')
+    @deprecated('use vreg[registry].select_or_none(oid, *args, **kwargs)')
     def select_object(self, registry, oid, *args, **kwargs):
         """return the most specific object in <registry>.<oid> according to
         the given context, or None if no object apply
         """
-        return self[registry].select_object(oid, *args, **kwargs)
+        return self[registry].select_or_none(oid, *args, **kwargs)
 
     @deprecated('use vreg[registry].possible_objects(*args, **kwargs)')
     def possible_objects(self, registry, *args, **kwargs):
--- a/web/controller.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/web/controller.py	Tue Aug 11 13:01:56 2009 +0200
@@ -93,7 +93,7 @@
             self.ensure_ro_rql(rql)
             if not isinstance(rql, unicode):
                 rql = unicode(rql, self.req.encoding)
-            pp = self.vreg['components'].select_object('magicsearch', self.req)
+            pp = self.vreg['components'].select_or_none('magicsearch', self.req)
             if pp is not None:
                 self.rset = pp.process_query(rql, self.req)
         return self.rset
--- a/web/facet.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/web/facet.py	Tue Aug 11 13:01:56 2009 +0200
@@ -64,8 +64,8 @@
 
 
 def get_facet(req, facetid, rqlst, mainvar):
-    return req.vreg['facets'].object_by_id(facetid, req, rqlst=rqlst,
-                                           filtered_variable=mainvar)
+    return req.vreg['facets'].select(facetid, req, rqlst=rqlst,
+                                     filtered_variable=mainvar)
 
 
 def filter_hiddens(w, **kwargs):
--- a/web/test/unittest_views_navigation.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/web/test/unittest_views_navigation.py	Tue Aug 11 13:01:56 2009 +0200
@@ -40,10 +40,10 @@
     def test_navigation_selection_not_enough(self):
         req = self.request()
         rset = self.execute('Any X,N LIMIT 10 WHERE X name N')
-        navcomp = self.vreg['components'].select_object('navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select_or_none('navigation', req, rset=rset)
         self.assertEquals(navcomp, None)
         req.set_search_state('W:X:Y:Z')
-        navcomp = self.vreg['components'].select_object('navigation', req, rset=rset)
+        navcomp = self.vreg['components'].select_or_none('navigation', req, rset=rset)
         self.assertEquals(navcomp, None)
         req.set_search_state('normal')
 
--- a/web/views/basetemplates.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/web/views/basetemplates.py	Tue Aug 11 13:01:56 2009 +0200
@@ -154,12 +154,11 @@
         w(u'<div id="page"><table width="100%" border="0" id="mainLayout"><tr>\n')
         self.nav_column(view, 'left')
         w(u'<td id="contentcol">\n')
-        rqlcomp = self.vreg['components'].select_object('rqlinput', self.req,
-                                                        rset=self.rset)
+        components = self.vreg['components']
+        rqlcomp = components.select_or_none('rqlinput', self.req, rset=self.rset)
         if rqlcomp:
             rqlcomp.render(w=self.w, view=view)
-        msgcomp = self.vreg['components'].select_object('applmessages',
-                                                        self.req, rset=self.rset)
+        msgcomp = components.select_or_none('applmessages', self.req, rset=self.rset)
         if msgcomp:
             msgcomp.render(w=self.w)
         self.content_header(view)
@@ -299,8 +298,8 @@
             self.req.add_js(jscript, localfile=False)
 
     def alternates(self):
-        urlgetter = self.vreg['components'].select_object('rss_feed_url',
-                                            self.req, rset=self.rset)
+        urlgetter = self.vreg['components'].select_or_none('rss_feed_url',
+                                                           self.req, rset=self.rset)
         if urlgetter is not None:
             self.whead(u'<link rel="alternate" type="application/rss+xml" title="RSS feed" href="%s"/>\n'
                        %  xml_escape(urlgetter.feed_url()))
--- a/web/views/navigation.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/web/views/navigation.py	Tue Aug 11 13:01:56 2009 +0200
@@ -149,8 +149,8 @@
 def limit_rset_using_paged_nav(self, req, rset, w, forcedisplay=False,
                                show_all_option=True, page_size=None):
     if not (forcedisplay or req.form.get('__force_display') is not None):
-        nav = self.vreg['components'].select_object('navigation', req,
-                                      rset=rset, page_size=page_size)
+        nav = self.vreg['components'].select_or_none('navigation', req,
+                                                     rset=rset, page_size=page_size)
         if nav:
             # get boundaries before component rendering
             start, stop = nav.page_boundaries()
--- a/web/views/urlpublishing.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/web/views/urlpublishing.py	Tue Aug 11 13:01:56 2009 +0200
@@ -217,6 +217,7 @@
             raise PathDontMatch()
         # remove last part and see if this is something like an actions
         # if so, call
+        # XXX bad smell: refactor to simpler code
         try:
             actionsreg = self.vreg['actions']
             requested = parts.pop(-1)
@@ -232,7 +233,7 @@
                 continue
             else:
                 try:
-                    action = actionsreg.select_best(actions, req, rset=rset)
+                    action = actionsreg._select_best(actions, req, rset=rset)
                 except RegistryException:
                     continue
                 else:
--- a/wsgi/handler.py	Tue Aug 11 12:42:01 2009 +0200
+++ b/wsgi/handler.py	Tue Aug 11 13:01:56 2009 +0200
@@ -97,7 +97,7 @@
 #         assert self.base_url[-1] == '/'
 #         self.https_url = config['https-url']
 #         assert not self.https_url or self.https_url[-1] == '/'
-        self.url_rewriter = self.appli.vreg.select_object('components', 'urlrewriter')
+        self.url_rewriter = self.appli.vreg['components'].select_or_none('urlrewriter')
 
     def _render(self, req):
         """this function performs the actual rendering