[IMP] made rml2pdf independant

bzr revid: fp@tinyerp.com-20100301184204-84sq3n5dqvxtpdvh
This commit is contained in:
Fabien Pinckaers 2010-03-01 19:42:04 +01:00
parent 8137150354
commit 4e2afb8853
1 changed files with 7 additions and 10 deletions

View File

@ -40,18 +40,16 @@ import re
import reportlab
from lxml import etree
import copy
import tools
import locale
import netsvc
import traceback, sys
_regex = re.compile('\[\[(.+?)\]\]')
def str2xml(s):
return s.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
return (s or '').replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
def xml2str(s):
return s.replace('&amp;','&').replace('&lt;','<').replace('&gt;','>')
return (s or '').replace('&amp;','&').replace('&lt;','<').replace('&gt;','>')
def _child_get(node, self=None, tagname=None):
for n in node:
@ -106,25 +104,24 @@ def _process_text(self, txt):
sps = _regex.split(txt)
while sps:
# This is a simple text to translate
result += tools.ustr(self.localcontext.get('translate', lambda x:x)(sps.pop(0)))
result += unicode(self.localcontext.get('translate', lambda x:x)(sps.pop(0)))
if sps:
try:
expr = sps.pop(0)
txt = eval(expr,self.localcontext)
if txt and (isinstance(txt, unicode) or isinstance(txt, str)):
txt = tools.ustr(self.localcontext.get('translate', lambda x:x)(txt))
txt = unicode(self.localcontext.get('translate', lambda x:x)(txt))
except Exception,e:
tb_s = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
netsvc.Logger().notifyChannel('report', netsvc.LOG_ERROR,'report :\n%s\n%s\nexpr: %s' % (tb_s, str(e),expr.encode('utf-8')))
if type(txt)==type('') or type(txt)==type(u''):
txt2 = str2xml(txt)
result += tools.ustr(txt2)
result += unicode(txt2)
elif (txt is not None) and (txt is not False):
result += tools.ustr(txt)
result += unicode(txt)
return result
def text_get(node):
return ''.join([tools.ustr(n.text) for n in node])
return ''.join([unicode(n.text) for n in node])
units = [
(re.compile('^(-?[0-9\.]+)\s*in$'), reportlab.lib.units.inch),