5c4a746f by Marcos Cano

Fixes BOM ascii problem

1 parent b0a3872d
...@@ -58,23 +58,26 @@ def engine(ifile,ofile,vars): ...@@ -58,23 +58,26 @@ def engine(ifile,ofile,vars):
58 template_content = open(ifile, "r").read() 58 template_content = open(ifile, "r").read()
59 template= MyTemplate(template_content) 59 template= MyTemplate(template_content)
60 60
61 print 'MATCHES:', template.pattern.findall(template.template) 61 #print 'MATCHES:', template.pattern.findall(template.template)
62 62
63 matches = template.pattern.findall(template.template) 63 matches = template.pattern.findall(template.template)
64 64
65 if len(matches): 65 if len(matches):
66 #print '[ MATCHES ] - ', matches
67 outputText = template.safe_substitute(vars) 66 outputText = template.safe_substitute(vars)
68 #print "[ TEMPLATING ] - %s "%ifile 67 try:
69 68 if printit:
70 if printit: 69 print outputText.encode('ascii', 'ignore')
71 #print "AFTER TEMPLATE:" 70 else:
72 #print outputText 71 f = open(ofile,'w')
73 print outputText.encode('ascii', 'ignore') 72 f.write(outputText.encode('ascii', 'ignore'))
74 else: 73 f.close()
75 f = open(ofile,'w') 74 except UnicodeDecodeError:
76 f.write(outputText.encode('ascii', 'ignore')) 75 if printit:
77 f.close() 76 print str(outputText)
77 else:
78 f = open(ofile,'w')
79 f.write(str(outputText))
80 f.close()
78 81
79 82
80 83
......