@@ -42,15 +42,15 @@ def xml_io_factory(typoid, typio, c = compose):
4242 )
4343else :
4444 # New etree tostring API.
45- def xml_pack (xml , encoding ,
45+ def xml_pack (xml , encoding , encoder ,
4646 tostr = etree .tostring , et = etree .ElementTree ,
4747 str = str , isinstance = isinstance , tuple = tuple ,
4848 ):
4949 if isinstance (xml , bytes ):
5050 return xml
5151 if isinstance (xml , str ):
5252 # If it's a string, encode and return.
53- return xml . encode ( encoding )
53+ return encoder ( xml )
5454 elif isinstance (xml , tuple ):
5555 # If it's a tuple, encode and return the joined items.
5656 # We do not accept lists here--emphasizing lists being used for ARRAY
@@ -59,7 +59,7 @@ def xml_pack(xml, encoding,
5959 # 3.2
6060 # XXX: tostring doesn't include declaration with utf-8?
6161 x = b'' .join (
62- x .encode (encoding ) if isinstance (x , str ) else
62+ x .encode ('utf-8' ) if isinstance (x , str ) else
6363 tostr (x , encoding = "utf-8" )
6464 for x in xml
6565 )
@@ -71,11 +71,11 @@ def xml_pack(xml, encoding,
7171 if encoding in ('utf8' ,'utf-8' ):
7272 return x
7373 else :
74- return x .decode ('utf-8' ). encode ( encoding )
74+ return encoder ( x .decode ('utf-8' ))
7575
7676 def xml_io_factory (typoid , typio , c = compose ):
77- def local_xml_pack (x , typio = typio , xml_pack = xml_pack ):
78- return xml_pack (x , typio .encoding )
77+ def local_xml_pack (x , encoder = typio . encode , typio = typio , xml_pack = xml_pack ):
78+ return xml_pack (x , typio .encoding , encoder )
7979 return (local_xml_pack , c ((typio .decode , xml_unpack )), etree .ElementTree ,)
8080
8181oid_to_io = {
0 commit comments