From 73c01b3547b73f0115b745f0b7a9c5fd2b6b42e7 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Tue, 11 May 2010 15:59:54 +0200 Subject: [PATCH] properly encode stuff for the XML output --- pyweb/mumble/mmobjects.py | 24 ++++++++++++++++++++---- pyweb/mumble/views.py | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pyweb/mumble/mmobjects.py b/pyweb/mumble/mmobjects.py index 41b1aed..eca2cab 100644 --- a/pyweb/mumble/mmobjects.py +++ b/pyweb/mumble/mmobjects.py @@ -163,7 +163,15 @@ class mmChannel( object ): from xml.etree.cElementTree import SubElement me = SubElement( parentnode, "channel" ) for key in self.channel_obj.__dict__: - me.set( key, unicode( getattr( self.channel_obj, key ) ) ) + val = getattr( self.channel_obj, key ) + if isinstance( val, bool ): + me.set( key, unicode(val).lower() ) + elif isinstance( val, list ) or isinstance( val, tuple ): + me.set( key, ','.join( ( unicode(elem) for elem in val ) ) ) + elif isinstance( val, str ): + me.set( key, unicode(val, "utf8").lower() ) + else: + me.set( key, unicode(val) ) me.set( "x-connecturl", self.connecturl ) @@ -290,9 +298,17 @@ class mmPlayer( object ): from xml.etree.cElementTree import SubElement me = SubElement( parentnode, "user" ) for key in self.player_obj.__dict__: - me.set( key, unicode( getattr( self.player_obj, key ) ) ) - - me.set("x-addrstring", self.ipaddress ) + val = getattr( self.player_obj, key ) + if isinstance( val, bool ): + me.set( key, unicode(val).lower() ) + elif isinstance( val, list ) or isinstance( val, tuple ): + me.set( key, ','.join( ( unicode(elem) for elem in val ) ) ) + elif isinstance( val, str ): + me.set( key, unicode(val, "utf8").lower() ) + else: + me.set( key, unicode(val) ) + + me.set( "x-addrstring", self.ipaddress ) if self.mumbleuser: if self.mumbleuser.hasTexture(): diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 3ac0fbf..79bac31 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -403,6 +403,7 @@ def cvp_xml( request, server ): from xml.etree.cElementTree import tostring as xml_to_string srv = get_object_or_404( Mumble, id=int(server) ) return HttpResponse( + ''+\ xml_to_string( srv.asXml(), encoding='utf-8' ), mimetype='text/xml' )