Mercurial > libervia-backend
diff sat_frontends/jp/output_template.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 003b8b4b56a7 |
children | 9d0df638c8b4 |
line wrap: on
line diff
--- a/sat_frontends/jp/output_template.py Wed Jul 31 11:31:22 2019 +0200 +++ b/sat_frontends/jp/output_template.py Tue Aug 13 19:08:41 2019 +0200 @@ -30,8 +30,8 @@ import os.path __outputs__ = ["Template"] -TEMPLATE = u"template" -OPTIONS = {u"template", u"browser", u"inline-css"} +TEMPLATE = "template" +OPTIONS = {"template", "browser", "inline-css"} class Template(object): @@ -43,14 +43,14 @@ def _front_url_tmp_dir(self, ctx, relative_url, tmp_dir): """Get front URL for temporary directory""" - template_data = ctx[u'template_data'] - return u"file://" + os.path.join(tmp_dir, template_data.theme, relative_url) + template_data = ctx['template_data'] + return "file://" + os.path.join(tmp_dir, template_data.theme, relative_url) def _do_render(self, template_path, css_inline, **kwargs): try: return self.renderer.render(template_path, css_inline=css_inline, **kwargs) except template.TemplateNotFound: - self.host.disp(_(u"Can't find requested template: {template_path}") + self.host.disp(_("Can't find requested template: {template_path}") .format(template_path=template_path), error=True) self.host.quit(C.EXIT_NOT_FOUND) @@ -72,8 +72,8 @@ except AttributeError: if not "template" in cmd.args.output_opts: self.host.disp(_( - u"no default template set for this command, you need to specify a " - u"template using --oo template=[path/to/template.html]"), + "no default template set for this command, you need to specify a " + "template using --oo template=[path/to/template.html]"), error=True, ) self.host.quit(C.EXIT_BAD_ARG) @@ -86,7 +86,7 @@ # template is not specified, we use default one pass if template_path is None: - self.host.disp(_(u"Can't parse template, please check its syntax"), + self.host.disp(_("Can't parse template, please check its syntax"), error=True) self.host.quit(C.EXIT_BAD_ARG) @@ -97,7 +97,7 @@ else: kwargs = mapping_cb(data) - css_inline = u"inline-css" in options + css_inline = "inline-css" in options if "browser" in options: template_name = os.path.basename(template_path) @@ -107,9 +107,9 @@ self.host, front_url_filter=front_url_filter, trusted=True) rendered = self._do_render(template_path, css_inline=css_inline, **kwargs) self.host.disp(_( - u"Browser opening requested.\n" - u"Temporary files are put in the following directory, you'll have to " - u"delete it yourself once finished viewing: {}").format(tmp_dir)) + "Browser opening requested.\n" + "Temporary files are put in the following directory, you'll have to " + "delete it yourself once finished viewing: {}").format(tmp_dir)) tmp_file = os.path.join(tmp_dir, template_name) with open(tmp_file, "w") as f: f.write(rendered.encode("utf-8")) @@ -129,7 +129,7 @@ else: # FIXME: Q&D way to disable template logging # logs are overcomplicated, and need to be reworked - template_logger = log.getLogger(u"sat.tools.common.template") + template_logger = log.getLogger("sat.tools.common.template") template_logger.log = lambda *args: None logging.disable(logging.WARNING)