mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added toXml.
This commit is contained in:
parent
fbe9460093
commit
bd1dedb8e9
@ -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('<', '<')
|
||||
s = s.replace('>', '>')
|
||||
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.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user