Skip to content

Commit e5a0bae

Browse files
committed
fixes #689
1 parent afe7005 commit e5a0bae

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

fastcore/xml.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ def _to_xml(elm, lvl=0, indent=True, do_escape=True):
208208
# %% ../nbs/09_xml.ipynb
209209
def to_xml(elm, lvl=0, indent=True, do_escape=True):
210210
"Convert `ft` element tree into an XML string"
211-
return Safe(_to_xml(elm, lvl, indent, do_escape=do_escape))
211+
if isinstance(elm, (list,tuple,FT)) or hasattr(elm, '__ft__'):
212+
return Safe(_to_xml(elm, lvl, indent, do_escape=do_escape))
213+
if isinstance(elm, bytes): return elm.decode('utf-8')
214+
return elm or ''
212215

213216
# %% ../nbs/09_xml.ipynb
214217
@patch

nbs/09_xml.ipynb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,10 @@
468468
"#| export\n",
469469
"def to_xml(elm, lvl=0, indent=True, do_escape=True):\n",
470470
" \"Convert `ft` element tree into an XML string\"\n",
471-
" return Safe(_to_xml(elm, lvl, indent, do_escape=do_escape))"
471+
" if isinstance(elm, (list,tuple,FT)) or hasattr(elm, '__ft__'):\n",
472+
" return Safe(_to_xml(elm, lvl, indent, do_escape=do_escape))\n",
473+
" if isinstance(elm, bytes): return elm.decode('utf-8')\n",
474+
" return elm or ''"
472475
]
473476
},
474477
{

0 commit comments

Comments
 (0)