Ned Deily added the comment:
This question has come up before. See Issue13648 where it was pointed out that
null characters "are forbidden both in raw form *and* in escaped form. So even
if they get escaped, they *still* will lead to errors. So there is no point in
escaping them."
New submission from Devika Sondhi :
As per XML 1.0 and 1.1 specs, the null character is treated as invalid in an
XML doc. (https://en.wikipedia.org/wiki/Valid_characters_in_XML)
Shouldn't invalid xml characters be omitted while escaping?
The current behavior(tested on Python 3.7) is as follows: