[webconfig] cleanup base_url management
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 29 Apr 2010 14:21:59 +0200
changeset 5443 f299ee54d7e0
parent 5442 3ed8afbbdf70
child 5444 f7fdb5dd82f6
[webconfig] cleanup base_url management
dbapi.py
devtools/fake.py
etwist/request.py
req.py
server/session.py
web/webconfig.py
--- a/dbapi.py	Thu Apr 29 14:21:57 2010 +0200
+++ b/dbapi.py	Thu Apr 29 14:21:59 2010 +0200
@@ -253,9 +253,6 @@
             self.session = None
             self.cnx = self.user = _NeedAuthAccessMock()
 
-    def base_url(self):
-        return self.vreg.config['base-url']
-
     def from_controller(self):
         return 'view'
 
--- a/devtools/fake.py	Thu Apr 29 14:21:57 2010 +0200
+++ b/devtools/fake.py	Thu Apr 29 14:21:59 2010 +0200
@@ -66,10 +66,6 @@
     def header_if_modified_since(self):
         return None
 
-    def base_url(self):
-        """return the root url of the instance"""
-        return BASE_URL
-
     def relative_path(self, includeparams=True):
         """return the normalized path of the request (ie at least relative
         to the instance's root, but some other normalization may be needed
--- a/etwist/request.py	Thu Apr 29 14:21:57 2010 +0200
+++ b/etwist/request.py	Thu Apr 29 14:21:59 2010 +0200
@@ -15,9 +15,8 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""Twisted request handler for CubicWeb
+"""Twisted request handler for CubicWeb"""
 
-"""
 __docformat__ = "restructuredtext en"
 
 from datetime import datetime
@@ -55,9 +54,9 @@
         return self._twreq.method
 
     def relative_path(self, includeparams=True):
-        """return the normalized path of the request (ie at least relative
-        to the instance's root, but some other normalization may be needed
-        so that the returned path may be used to compare to generated urls
+        """return the normalized path of the request (ie at least relative to
+        the instance's root, but some other normalization may be needed so that
+        the returned path may be used to compare to generated urls
 
         :param includeparams:
            boolean indicating if GET form parameters should be kept in the path
@@ -68,8 +67,8 @@
         return path
 
     def get_header(self, header, default=None, raw=True):
-        """return the value associated with the given input header,
-        raise KeyError if the header is not set
+        """return the value associated with the given input header, raise
+        KeyError if the header is not set
         """
         if raw:
             return self._headers_in.getRawHeaders(header, [default])[0]
--- a/req.py	Thu Apr 29 14:21:57 2010 +0200
+++ b/req.py	Thu Apr 29 14:21:59 2010 +0200
@@ -374,11 +374,11 @@
             raise ValueError(self._('can\'t parse %(value)r (expected %(format)s)')
                              % {'value': value, 'format': format})
 
-    # abstract methods to override according to the web front-end #############
-
     def base_url(self):
         """return the root url of the instance"""
-        raise NotImplementedError
+        return self.vreg.config['base-url']
+
+    # abstract methods to override according to the web front-end #############
 
     def describe(self, eid):
         """return a tuple (type, sourceuri, extid) for the entity with id <eid>"""
--- a/server/session.py	Thu Apr 29 14:21:57 2010 +0200
+++ b/server/session.py	Thu Apr 29 14:21:59 2010 +0200
@@ -626,16 +626,6 @@
         else:
             del self.transaction_data['ecache'][eid]
 
-    def base_url(self):
-        url = self.repo.config['base-url']
-        if not url:
-            try:
-                url = self.repo.config.default_base_url()
-            except AttributeError: # default_base_url() might not be available
-                self.warning('missing base-url definition in server config')
-                url = u''
-        return url
-
     def from_controller(self):
         """return the id (string) of the controller issuing the request (no
         sense here, always return 'view')
--- a/web/webconfig.py	Thu Apr 29 14:21:57 2010 +0200
+++ b/web/webconfig.py	Thu Apr 29 14:21:59 2010 +0200
@@ -309,8 +309,8 @@
         """load instance's configuration files"""
         super(WebConfiguration, self).load_configuration()
         # load external resources definition
+        self._init_base_url()
         self._build_ext_resources()
-        self._init_base_url()
 
     def _init_base_url(self):
         # normalize base url(s)