4646STDERR_LINE = '\n Stderr:\n %s'
4747
4848
49- def xml_safe_unicode (base , encoding = 'utf-8' ):
50- """Return a unicode string containing only valid XML characters.
51-
52- encoding - if base is a byte string it is first decoded to unicode
53- using this encoding.
54- """
55- if isinstance (base , six .binary_type ):
56- base = base .decode (encoding )
57- return INVALID_XML_1_0_UNICODE_RE .sub ('' , base )
58-
59-
60- def to_unicode (data ):
49+ def _to_unicode (data ):
6150 """Returns unicode in Python2 and str in Python3"""
6251 if six .PY3 :
6352 return six .text_type (data )
@@ -68,8 +57,17 @@ def to_unicode(data):
6857 return repr (data ).decode ('utf8' , 'replace' )
6958
7059
71- def safe_unicode (data , encoding = None ):
72- return xml_safe_unicode (to_unicode (data ), encoding )
60+ def safe_unicode (data , encoding = 'utf8' ):
61+ """Return a unicode string containing only valid XML characters.
62+
63+ encoding - if data is a byte string it is first decoded to unicode
64+ using this encoding.
65+ """
66+ data = _to_unicode (data )
67+ if isinstance (data , six .binary_type ):
68+ # e.g. IronPython, see #182
69+ data = data .decode (encoding )
70+ return INVALID_XML_1_0_UNICODE_RE .sub ('' , data )
7371
7472
7573def testcase_name (test_method ):
0 commit comments