from StringIO import StringIO
try :
from xml.etree.ElementTree import XML # Python 2.5 (and greater?)
except ImportError :
from elementtree.ElementTree import XML
from libbe.restconvert import rest_xml
def to_unix(text):
skip_newline = False
for ch in text:
if ch not in ('\r', '\n'):
yield ch
else:
if ch == '\n':
if skip_newline:
continue
else:
skip_newline = True
yield '\n'
def soft_text(text):
first_space = False
translations = {'\n': '
\n', '&': '&', '\x3c': '<',
'\x3e': '>'}
for ch in to_unix(text):
if ch == ' ' and first_space is True:
yield ' '
first_space = ch in (' ')
try:
yield translations[ch]
except KeyError:
yield ch
def soft_pre(text):
return XML('