[ADD][IMP]ustr casting macro

This commit is contained in:
Fabien BOURGEOIS 2021-02-22 01:16:16 +01:00
parent 24fc3f4807
commit c18e598dfb
2 changed files with 6 additions and 4 deletions

View File

@ -24,3 +24,7 @@
(if (< (get sys.version_info 0) 3)
python2-form
python3-form))
(defmacro ustr-cast [s]
"If python2, return unicode casting, else str casting"
(if-python2 `(unicode ~s) `(str ~s)))

View File

@ -17,7 +17,7 @@
" XML helpers and macros "
(require [hy-odoo.macros [if-python2]])
(require [hy-odoo.macros [if-python2 ustr-cast]])
(import [collections [namedtuple]]
[functools [partial]]
[os [path]]
@ -42,9 +42,7 @@
(cond [(string? children) (setv (. parent text) children)]
[(instance? XMLDictElement children
(do
(if-python2
(setv attrs (dfor [k v] (.items (. children attrs)) [(unicode k) (unicode v)]))
(setv attrs (dfor [k v] (.items (. children attrs)) [(str k) (str v)])))
(setv attrs (dfor [k v] (.items (. children attrs)) [(ustr-cast k) (ustr-cast v)]))
(setv new-parent (.SubElement ET parent (. children tag) attrs)
subchildren (.children children))
(when subchildren) (xmlchild new-parent subchildren)))]