2727
2828
2929def remove_invalid_xml_bytes (b ):
30+ """
31+ Remove characters that aren't allowed in xml.
32+ """
3033 try :
3134 # Dropping chars that cannot be parsed later on. The
3235 # translate() function was benchmarked to be the fastest way
@@ -37,7 +40,8 @@ def remove_invalid_xml_bytes(b):
3740 # unit tests)
3841 return INVALID_XML_RE .sub ('' , b )
3942
40- def xml_esc (v ):
43+ # only python2, which is not covered by coverage tests
44+ def xml_esc (v ): # pragma: no cover
4145 "Escape string or unicode object v for xml output"
4246
4347 # Use is_unicode() instead of is_string() because in python 2, str is
@@ -73,9 +77,9 @@ def __init__(self, indent_atom = None):
7377 # Call the super class constructor so that we have the type map
7478 super (LLSDXMLFormatter , self ).__init__ ()
7579 self .py2 = PY2
76-
80+
7781 def _LLSD (self , v ):
78- raise LLSDSerializationError ("We should never end up here" )
82+ raise LLSDSerializationError ("We should never end up here" ) # pragma: no cover
7983 def _UNDEF (self , _v ):
8084 return b'<undef/>'
8185 def _BOOLEAN (self , v ):
@@ -89,26 +93,23 @@ def _REAL(self, v):
8993 def _UUID (self , v ):
9094 if v .int == 0 :
9195 return b'<uuid/>'
92- else :
93- return b'<uuid>' + str (v ).encode ('utf-8' ) + b'</uuid>'
96+ return b'<uuid>' + str (v ).encode ('utf-8' ) + b'</uuid>'
9497 def _BINARY (self , v ):
9598 return b'<binary>' + base64 .b64encode (v ).strip () + b'</binary>'
9699 def _STRING (self , v ):
97- if self .py2 :
100+ if self .py2 : # pragma: no cover
98101 return b'<string>' + _str_to_bytes (xml_esc (v )) + b'</string>'
99- else :
100- return b'<string>' + v .translate (XML_ESC_TRANS ).encode ('utf-8' ) + b'</string>'
102+ return b'<string>' + v .translate (XML_ESC_TRANS ).encode ('utf-8' ) + b'</string>'
101103 def _URI (self , v ):
102- if self .py2 :
104+ if self .py2 : # pragma: no cover
103105 return b'<uri>' + _str_to_bytes (xml_esc (v )) + b'</uri>'
104- else :
105- return b'<uri>' + UnicodeType (v ).translate (XML_ESC_TRANS ).encode ('utf-8' ) + b'</uri>'
106+ return b'<uri>' + UnicodeType (v ).translate (XML_ESC_TRANS ).encode ('utf-8' ) + b'</uri>'
106107 def _DATE (self , v ):
107108 return b'<date>' + _format_datestr (v ) + b'</date>'
108109 def _ARRAY (self , v ):
109- raise LLSDSerializationError ("We should never end up here" )
110+ raise LLSDSerializationError ("We should never end up here" ) # pragma: no cover
110111 def _MAP (self , v ):
111- raise LLSDSerializationError ("We should never end up here" )
112+ raise LLSDSerializationError ("We should never end up here" ) # pragma: no cover
112113
113114 def _write (self , something ):
114115 """
@@ -126,7 +127,7 @@ def _write(self, something):
126127 item = next (cur_iter )
127128 if iter_type == b"map" :
128129
129- if self .py2 :
130+ if self .py2 : # pragma: no cover
130131 self .stream .write (b'<key>' +
131132 _str_to_bytes (xml_esc (UnicodeType (item ))) +
132133 b'</key>' )
@@ -211,7 +212,7 @@ def _write(self, something):
211212 item = next (cur_iter )
212213 if iter_type == b"map" :
213214 self ._indent ()
214- if self .py2 :
215+ if self .py2 : # pragma: no cover
215216 self .stream .write (b'<key>' +
216217 _str_to_bytes (xml_esc (UnicodeType (item ))) +
217218 b'</key>' )
0 commit comments