From 68f6c686960860b88b5608f2b7f4b49a38d3f84a Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Wed, 18 Sep 2019 09:26:07 +0200 Subject: [PATCH] [FIX]Hy Base : handle python2 case --- odoo.hy | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/odoo.hy b/odoo.hy index 6c0594b..50af04e 100644 --- a/odoo.hy +++ b/odoo.hy @@ -19,6 +19,13 @@ (require [odoo.addons.hy_base.xml [*]]) +(defmacro if-python2 [python2-form python3-form] + "If running on python2, execute python2-form, else, execute python3-form" + (import sys) + (if (< (get sys.version_info 0) 3) + python2-form + python3-form)) + (defmacro ox-odoo [&rest args] `(xmlr "odoo" ~@args)) (defmacro ox-data [&rest args] `(xmlnc "data" ~@args)) (defmacro ox-record [&rest args] `(xmlnc "record" ~@args)) @@ -63,7 +70,9 @@ "Write XML file according to filename and given tree" `(do (import [os [path]]) - (setv ~g!output-xml (.tostring ET ~tree) - ~g!output-path (.dirname path (.abspath path __file__)) + (if-python2 + (setv ~g!output-xml (.tostring ET ~tree)) + (setv ~g!output-xml (.decode (.tostring ET ~tree) "utf-8"))) + (setv ~g!output-path (.dirname path (.abspath path __file__)) ~g!fpath (+ ~g!output-path "/" ~filename)) (with [f (open ~g!fpath "w")] (.write f ~g!output-xml))))