Fixes BOM ascii problem
Showing
2 changed files
with
9 additions
and
6 deletions
... | @@ -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 | |||
70 | if printit: | 68 | if printit: |
71 | #print "AFTER TEMPLATE:" | ||
72 | #print outputText | ||
73 | print outputText.encode('ascii', 'ignore') | 69 | print outputText.encode('ascii', 'ignore') |
74 | else: | 70 | else: |
75 | f = open(ofile,'w') | 71 | f = open(ofile,'w') |
76 | f.write(outputText.encode('ascii', 'ignore')) | 72 | f.write(outputText.encode('ascii', 'ignore')) |
77 | f.close() | 73 | f.close() |
74 | except UnicodeDecodeError: | ||
75 | if printit: | ||
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 | ... | ... |
-
Please register or sign in to post a comment