wsgi/handler.py
changeset 9402 2c48c091b6a2
parent 9031 6ff29f2879da
parent 9289 9bb7b5dc4214
child 9443 6ff9401c37c1
equal deleted inserted replaced
9127:aff75b69db92 9402:2c48c091b6a2
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """WSGI request handler for cubicweb"""
    18 """WSGI request handler for cubicweb"""
    19 
       
    20 
       
    21 
    19 
    22 __docformat__ = "restructuredtext en"
    20 __docformat__ = "restructuredtext en"
    23 
    21 
    24 from itertools import chain, repeat, izip
    22 from itertools import chain, repeat, izip
    25 
    23 
    90 
    88 
    91     def __iter__(self):
    89     def __iter__(self):
    92         return iter(self.body)
    90         return iter(self.body)
    93 
    91 
    94 
    92 
    95 
       
    96 class CubicWebWSGIApplication(object):
    93 class CubicWebWSGIApplication(object):
    97     """This is the wsgi application which will be called by the
    94     """This is the wsgi application which will be called by the
    98     wsgi server with the WSGI ``environ`` and ``start_response``
    95     wsgi server with the WSGI ``environ`` and ``start_response``
    99     parameters.
    96     parameters.
   100 
       
   101     XXX: missing looping tasks and proper repository shutdown when
       
   102     the application is stopped.
       
   103     NOTE: no pyro
       
   104     """
    97     """
   105 
    98 
   106     def __init__(self, repo, config):
    99     def __init__(self, repo, config):
   107         self.appli = CubicWebPublisher(repo, config)
   100         self.appli = CubicWebPublisher(repo, config)
   108         self.config = config
   101         self.config = config
   109         self.base_url = self.config['base-url']
   102         self.base_url = self.config['base-url']
   110         self.https_url = self.config['https-url']
       
   111         self.url_rewriter = self.appli.vreg['components'].select_or_none('urlrewriter')
   103         self.url_rewriter = self.appli.vreg['components'].select_or_none('urlrewriter')
   112 
   104 
   113     def _render(self, req):
   105     def _render(self, req):
   114         """this function performs the actual rendering
   106         """this function performs the actual rendering
   115         """
   107         """
   116         if self.base_url is None:
       
   117             self.base_url = self.config._base_url = req.base_url()
       
   118         try:
   108         try:
   119             path = req.path
   109             path = req.path
   120             result = self.appli.handle_request(req, path)
   110             result = self.appli.handle_request(req, path)
   121         except DirectResponse as ex:
   111         except DirectResponse as ex:
   122             return ex.response
   112             return ex.response