Mercurial > libervia-web
diff libervia/server/utils.py @ 1216:b2d067339de3
python 3 port:
/!\ Python 3.6+ is now needed to use libervia
/!\ instability may occur and features may not be working anymore, this will improve with time
/!\ TxJSONRPC dependency has been removed
The same procedure as in backend has been applied (check backend commit ab2696e34d29 logs
for details). Removed now deprecated code (Pyjamas compiled browser part, legacy blog,
JSON RPC related code).
Adapted code to work without `html` and `themes` dirs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:12:31 +0200 |
parents | 2af117bfe6cc |
children | 62bf4f87c249 |
line wrap: on
line diff
--- a/libervia/server/utils.py Tue Aug 13 09:39:33 2019 +0200 +++ b/libervia/server/utils.py Tue Aug 13 19:12:31 2019 +0200 @@ -21,14 +21,14 @@ from twisted.internet import defer from sat.core import exceptions from sat.core.log import getLogger -import urllib +import urllib.request, urllib.parse, urllib.error log = getLogger(__name__) def quote(value, safe="@"): """shortcut to quote an unicode value for URL""" - return urllib.quote(value.encode("utf-8"), safe=safe) + return urllib.parse.quote(value.encode("utf-8"), safe=safe) class ProgressHandler(object): @@ -46,27 +46,27 @@ handlers = cls.handlers if profile in handlers and progress_id in handlers[profile]: handler_data = handlers[profile][progress_id] - timeout = handler_data[u"timeout"] + timeout = handler_data["timeout"] if timeout.active(): timeout.cancel() cb = handler_data[name] if cb is not None: cb(data) - if name == u"started": + if name == "started": pass - elif name == u"finished": - handler_data[u"deferred"].callback(data) - handler_data[u"instance"].unregister_handler() - elif name == u"error": - handler_data[u"deferred"].errback(Exception(data)) - handler_data[u"instance"].unregister_handler() + elif name == "finished": + handler_data["deferred"].callback(data) + handler_data["instance"].unregister_handler() + elif name == "error": + handler_data["deferred"].errback(Exception(data)) + handler_data["instance"].unregister_handler() else: - log.error(u"unexpected signal: {name}".format(name=name)) + log.error("unexpected signal: {name}".format(name=name)) def _timeout(self): log.warning( _( - u"No progress received, cancelling handler: {progress_id} [{profile}]" + "No progress received, cancelling handler: {progress_id} [{profile}]" ).format(progress_id=self.progress_id, profile=self.profile) ) @@ -76,7 +76,7 @@ del self.handlers[self.profile][self.progress_id] except KeyError: log.warning( - _(u"Trying to remove unknown handler: {progress_id} [{profile}]").format( + _("Trying to remove unknown handler: {progress_id} [{profile}]").format( progress_id=self.progress_id, profile=self.profile ) ) @@ -100,16 +100,16 @@ ) if handler_data: raise exceptions.ConflictError( - u"There is already one handler for this progression" + "There is already one handler for this progression" ) - handler_data[u"instance"] = self - deferred = handler_data[u"deferred"] = defer.Deferred() - handler_data[u"started"] = started_cb - handler_data[u"finished"] = finished_cb - handler_data[u"error"] = error_cb - handler_data[u"timeout"] = reactor.callLater(timeout, self._timeout) + handler_data["instance"] = self + deferred = handler_data["deferred"] = defer.Deferred() + handler_data["started"] = started_cb + handler_data["finished"] = finished_cb + handler_data["error"] = error_cb + handler_data["timeout"] = reactor.callLater(timeout, self._timeout) return deferred -class SubPage(unicode): +class SubPage(str): """use to mark subpages when generating a page path"""