absolute_url / build_url refactoring to avoid potential name clash
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 05 Jun 2009 19:04:20 +0200
changeset 2059 af33833d7571
parent 2058 7ef12c03447c
child 2081 7f906fe1c5b7
absolute_url / build_url refactoring to avoid potential name clash
__init__.py
appobject.py
entity.py
--- a/__init__.py	Fri Jun 05 15:09:20 2009 +0200
+++ b/__init__.py	Fri Jun 05 19:04:20 2009 +0200
@@ -109,11 +109,16 @@
 
     # url generation methods ##################################################
 
-    def build_url(self, method, base_url=None, **kwargs):
+    def build_url(self, *args, **kwargs):
         """return an absolute URL using params dictionary key/values as URL
         parameters. Values are automatically URL quoted, and the
         publishing method to use may be specified or will be guessed.
         """
+        # use *args since we don't want first argument to be "anonymous" to
+        # avoid potential clash with kwargs
+        assert len(args) == 1, 'only 0 or 1 non-named-argument expected'
+        method = args[0]
+        base_url = kwargs.pop('base_url', None)
         if base_url is None:
             base_url = self.base_url()
         if '_restpath' in kwargs:
--- a/appobject.py	Fri Jun 05 15:09:20 2009 +0200
+++ b/appobject.py	Fri Jun 05 19:04:20 2009 +0200
@@ -204,11 +204,18 @@
 
     controller = 'view'
 
-    def build_url(self, method=None, **kwargs):
+    def build_url(self, *args, **kwargs):
         """return an absolute URL using params dictionary key/values as URL
         parameters. Values are automatically URL quoted, and the
         publishing method to use may be specified or will be guessed.
         """
+        # use *args since we don't want first argument to be "anonymous" to
+        # avoid potential clash with kwargs
+        if args:
+            assert len(args) == 1, 'only 0 or 1 non-named-argument expected'
+            method = args[0]
+        else:
+            method = None
         # XXX I (adim) think that if method is passed explicitly, we should
         #     not try to process it and directly call req.build_url()
         if method is None:
--- a/entity.py	Fri Jun 05 15:09:20 2009 +0200
+++ b/entity.py	Fri Jun 05 19:04:20 2009 +0200
@@ -373,8 +373,15 @@
         return self.vreg.render(vid, self.req, rset=self.rset,
                                 row=self.row, col=self.col, **kwargs)
 
-    def absolute_url(self, method=None, **kwargs):
+    def absolute_url(self, *args, **kwargs):
         """return an absolute url to view this entity"""
+        # use *args since we don't want first argument to be "anonymous" to
+        # avoid potential clash with kwargs
+        if args:
+            assert len(args) == 1, 'only 0 or 1 non-named-argument expected'
+            method = args[0]
+        else:
+            method = None
         # in linksearch mode, we don't want external urls else selecting
         # the object for use in the relation is tricky
         # XXX search_state is web specific