mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-19 23:20:57 +01:00
Added toXml.
This commit is contained in:
parent
fbe9460093
commit
bd1dedb8e9
@ -41,6 +41,7 @@ __revision__ = "$Id$"
|
|||||||
import fix
|
import fix
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
import string
|
import string
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
@ -225,6 +226,27 @@ def unAction(msg):
|
|||||||
assert isAction(msg)
|
assert isAction(msg)
|
||||||
return _unactionre.match(msg.args[1]).group(1)
|
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):
|
def prettyPrint(msg, addRecipients=False):
|
||||||
"""Provides a client-friendly string form for messages.
|
"""Provides a client-friendly string form for messages.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user