Added toXml.

This commit is contained in:
Jeremy Fincher 2004-04-22 05:11:20 +00:00
parent fbe9460093
commit bd1dedb8e9
1 changed files with 22 additions and 0 deletions

View File

@ -41,6 +41,7 @@ __revision__ = "$Id$"
import fix
import re
import time
import string
import conf
@ -225,6 +226,27 @@ def unAction(msg):
assert isAction(msg)
return _unactionre.match(msg.args[1]).group(1)
def _escape(s):
s = s.replace('&', '&')
s = s.replace('"', '"')
s = s.replace('<', '&lt;')
s = s.replace('>', '&gt;')
return s
def toXml(msg, pretty=True, includeTime=True):
assert msg.command == _escape(msg.command)
L = []
L.append('<msg command="%s" prefix="%s"'%(msg.command,_escape(msg.prefix)))
if includeTime:
L.append(' time="%s"' % time.time())
L.append('>')
for arg in msg.args:
if pretty:
L.append('\n ')
L.append('<arg>%s</arg>' % _escape(arg))
L.append('</msg>')
return ''.join(L)
def prettyPrint(msg, addRecipients=False):
"""Provides a client-friendly string form for messages.