comparison libervia/server/pages.py @ 1224:62bf4f87c249

server: some encoding fixes following python 3 port
author Goffi <goffi@goffi.org>
date Sun, 06 Oct 2019 22:21:13 +0200
parents b2d067339de3
children 011147d7a931
comparison
equal deleted inserted replaced
1223:4976eb0f5315 1224:62bf4f87c249
1136 redirect_page = redirect_page.children[subpage] 1136 redirect_page = redirect_page.children[subpage]
1137 else: 1137 else:
1138 redirect_page = redirect_page.original.children[subpage] 1138 redirect_page = redirect_page.original.children[subpage]
1139 1139
1140 if path_args is not None: 1140 if path_args is not None:
1141 args = [quote(a) for a in path_args] 1141 args = [quote(a).encode() for a in path_args]
1142 request.postpath = args + request.postpath 1142 request.postpath = args + request.postpath
1143 1143
1144 if self._do_cache: 1144 if self._do_cache:
1145 # if cache is needed, it will be handled by final page 1145 # if cache is needed, it will be handled by final page
1146 redirect_page._do_cache = self._do_cache 1146 redirect_page._do_cache = self._do_cache
1275 """called if an error is not catched""" 1275 """called if an error is not catched"""
1276 if failure_.check(BridgeException) and failure_.value.condition == 'not-allowed': 1276 if failure_.check(BridgeException) and failure_.value.condition == 'not-allowed':
1277 log.warning("not allowed exception catched") 1277 log.warning("not allowed exception catched")
1278 self.pageError(request, C.HTTP_FORBIDDEN) 1278 self.pageError(request, C.HTTP_FORBIDDEN)
1279 log.error(_("Uncatched error for HTTP request on {url}: {msg}") 1279 log.error(_("Uncatched error for HTTP request on {url}: {msg}")
1280 .format( url=request.URLPath(), msg=failure_)) 1280 .format(url=request.URLPath().decode(), msg=failure_))
1281 self.pageError(request, C.HTTP_INTERNAL_ERROR) 1281 self.pageError(request, C.HTTP_INTERNAL_ERROR)
1282 1282
1283 def _on_data_post_error(self, failure_, request): 1283 def _on_data_post_error(self, failure_, request):
1284 failure_.trap(exceptions.DataError) 1284 failure_.trap(exceptions.DataError)
1285 # something is wrong with the posted data, we re-display the page with a 1285 # something is wrong with the posted data, we re-display the page with a
1559 if request.postpath and not request.postpath[-1]: 1559 if request.postpath and not request.postpath[-1]:
1560 # we don't differenciate URLs finishing with '/' or not 1560 # we don't differenciate URLs finishing with '/' or not
1561 del request.postpath[-1] 1561 del request.postpath[-1]
1562 1562
1563 # i18n 1563 # i18n
1564 if C.KEY_LANG in request.args: 1564 key_lang = C.KEY_LANG.encode()
1565 if key_lang in request.args:
1565 try: 1566 try:
1566 locale = request.args.pop(C.KEY_LANG)[0] 1567 locale = request.args.pop(key_lang)[0].decode()
1567 except IndexError: 1568 except IndexError:
1568 log.warning("empty lang received") 1569 log.warning("empty lang received")
1569 else: 1570 else:
1570 if "/" in locale: 1571 if "/" in locale:
1571 # "/" is refused because locale may sometime be used to access 1572 # "/" is refused because locale may sometime be used to access