cubicweb/web/application.py
changeset 12567 26744ad37953
parent 12542 85194bd49119
child 12681 42afaaf708d8
equal deleted inserted replaced
12566:6b3523f81f42 12567:26744ad37953
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """CubicWeb web client application object"""
    18 """CubicWeb web client application object"""
    19 
    19 
    20 
    20 
    21 import contextlib
    21 import contextlib
       
    22 import http.client as http_client
    22 import json
    23 import json
    23 import sys
    24 import sys
    24 from time import clock, time
    25 from time import clock, time
    25 from contextlib import contextmanager
    26 from contextlib import contextmanager
    26 
       
    27 from six import text_type, binary_type
       
    28 from six.moves import http_client
       
    29 
    27 
    30 from rql import BadRQLQuery
    28 from rql import BadRQLQuery
    31 
    29 
    32 from cubicweb import set_log_methods
    30 from cubicweb import set_log_methods
    33 from cubicweb import (
    31 from cubicweb import (
   314             # If previous error handling already generated a custom content
   312             # If previous error handling already generated a custom content
   315             # do not overwrite it. This is used by LogOut Except
   313             # do not overwrite it. This is used by LogOut Except
   316             # XXX ensure we don't actually serve content
   314             # XXX ensure we don't actually serve content
   317             if not content:
   315             if not content:
   318                 content = self.need_login_content(req)
   316                 content = self.need_login_content(req)
   319         assert isinstance(content, binary_type)
   317         assert isinstance(content, bytes)
   320         return content
   318         return content
   321 
   319 
   322     def core_handle(self, req):
   320     def core_handle(self, req):
   323         """method called by the main publisher to process <req> relative path
   321         """method called by the main publisher to process <req> relative path
   324 
   322 
   479         if isinstance(ex, PublishException) and ex.status is not None:
   477         if isinstance(ex, PublishException) and ex.status is not None:
   480             status = ex.status
   478             status = ex.status
   481         if req.status_out < 400:
   479         if req.status_out < 400:
   482             # don't overwrite it if it's already set
   480             # don't overwrite it if it's already set
   483             req.status_out = status
   481             req.status_out = status
   484         json_dumper = getattr(ex, 'dumps', lambda: json.dumps({'reason': text_type(ex)}))
   482         json_dumper = getattr(ex, 'dumps', lambda: json.dumps({'reason': str(ex)}))
   485         return json_dumper().encode('utf-8')
   483         return json_dumper().encode('utf-8')
   486 
   484 
   487     # special case handling
   485     # special case handling
   488 
   486 
   489     def need_login_content(self, req):
   487     def need_login_content(self, req):