Browse Source

properly encode stuff for the XML output

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
73c01b3547
  1. 24
      pyweb/mumble/mmobjects.py
  2. 1
      pyweb/mumble/views.py

24
pyweb/mumble/mmobjects.py

@ -163,7 +163,15 @@ class mmChannel( object ):
from xml.etree.cElementTree import SubElement from xml.etree.cElementTree import SubElement
me = SubElement( parentnode, "channel" ) me = SubElement( parentnode, "channel" )
for key in self.channel_obj.__dict__: 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 ) me.set( "x-connecturl", self.connecturl )
@ -290,9 +298,17 @@ class mmPlayer( object ):
from xml.etree.cElementTree import SubElement from xml.etree.cElementTree import SubElement
me = SubElement( parentnode, "user" ) me = SubElement( parentnode, "user" )
for key in self.player_obj.__dict__: 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:
if self.mumbleuser.hasTexture(): if self.mumbleuser.hasTexture():

1
pyweb/mumble/views.py

@ -403,6 +403,7 @@ def cvp_xml( request, server ):
from xml.etree.cElementTree import tostring as xml_to_string from xml.etree.cElementTree import tostring as xml_to_string
srv = get_object_or_404( Mumble, id=int(server) ) srv = get_object_or_404( Mumble, id=int(server) )
return HttpResponse( return HttpResponse(
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+\
xml_to_string( srv.asXml(), encoding='utf-8' ), xml_to_string( srv.asXml(), encoding='utf-8' ),
mimetype='text/xml' mimetype='text/xml'
) )

Loading…
Cancel
Save