@@ 97-116 (lines=20) @@ | ||
94 | b'<text>' + new_elem.text.encode('utf-8') + b'</text>', elem_as_str |
|
95 | ) |
|
96 | ||
97 | def test_escape_xml_printable_char(self): |
|
98 | text = 'Latin Capital Letter A With Circumflex \xc2 is printable.' |
|
99 | res = escape_ctrl_chars(text) |
|
100 | self.assertEqual( |
|
101 | res, 'Latin Capital Letter A With Circumflex  is printable.' |
|
102 | ) |
|
103 | ||
104 | # Create the element |
|
105 | elem = Element('text') |
|
106 | elem.text = res |
|
107 | self.assertEqual( |
|
108 | tostring(elem), |
|
109 | b'<text>Latin Capital Letter A With Circumflex  is ' |
|
110 | b'printable.</text>', |
|
111 | ) |
|
112 | ||
113 | # The string format of the element does not break the xml |
|
114 | elem_as_str = tostring(elem, encoding='utf-8') |
|
115 | new_elem = fromstring(elem_as_str) |
|
116 | self.assertEqual( |
|
117 | b'<text>' + new_elem.text.encode('utf-8') + b'</text>', elem_as_str |
|
118 | ) |
|
119 | ||
@@ 77-94 (lines=18) @@ | ||
74 | ||
75 | self.assertEqual(text, res) |
|
76 | ||
77 | def test_escape_xml_invalid_char(self): |
|
78 | text = 'End of transmission is not printable \x04.' |
|
79 | res = escape_ctrl_chars(text) |
|
80 | self.assertEqual(res, 'End of transmission is not printable \\x0004.') |
|
81 | ||
82 | # Create element |
|
83 | elem = Element('text') |
|
84 | elem.text = res |
|
85 | self.assertEqual( |
|
86 | tostring(elem), |
|
87 | b'<text>End of transmission is not printable \\x0004.</text>', |
|
88 | ) |
|
89 | ||
90 | # The string format of the element does not break the xml. |
|
91 | elem_as_str = tostring(elem, encoding='utf-8') |
|
92 | new_elem = fromstring(elem_as_str) |
|
93 | self.assertEqual( |
|
94 | b'<text>' + new_elem.text.encode('utf-8') + b'</text>', elem_as_str |
|
95 | ) |
|
96 | ||
97 | def test_escape_xml_printable_char(self): |