Explicitly treat all files as UTF-8.

This commit is contained in:
Stefan Rado
2014-02-16 01:47:11 +01:00
parent 1c13225b19
commit 49cc0bd162
4 changed files with 11 additions and 7 deletions

View File

@@ -1,3 +1,4 @@
import codecs
class DokuWikiListingsOutput():
def __init__(self, groups):
@@ -26,5 +27,5 @@ class DokuWikiListingsOutput():
self.output = result
def Save(self, filename):
with open(filename, 'w') as f:
with codecs.open(filename, 'w', 'utf-8') as f:
f.write(self.output)

View File

@@ -1,4 +1,5 @@
from xml.sax.saxutils import escape
import codecs
class DokuWikiTablesOutput():
def __init__(self, groups):
@@ -44,11 +45,11 @@ class DokuWikiTablesOutput():
self.output = result;
def Save(self, filename):
with open(filename, 'w') as f:
with codecs.open(filename, 'w', 'utf-8') as f:
f.write(self.output)
def SaveRpc(self, filename):
with open(filename, 'w') as f:
with codecs.open(filename, 'w', 'utf-8') as f:
f.write("""<?xml version='1.0'?>
<methodCall>
<methodName>wiki.putPage</methodName>

View File

@@ -1,4 +1,5 @@
from xml.dom.minidom import getDOMImplementation
import codecs
class XMLOutput():
def __init__(self, groups):
@@ -18,8 +19,8 @@ class XMLOutput():
xml_param.appendChild(xml_field)
xml_value = xml_document.createTextNode(value)
xml_field.appendChild(xml_value)
self.output = xml_document.toprettyxml(indent=" ", newl="\n", encoding="utf-8")
self.xml_document = xml_document
def Save(self, filename):
with open(filename, 'wb') as f:
f.write(self.output)
with codecs.open(filename, 'w', 'utf-8') as f:
self.xml_document.writexml(f, indent=" ", addindent=" ", newl="\n")

View File

@@ -1,5 +1,6 @@
import os
import re
import codecs
class Scanner(object):
"""
@@ -29,6 +30,6 @@ class Scanner(object):
Scans provided file and passes its contents to the parser using
parser.Parse method.
"""
with open(path, 'r') as f:
with codecs.open(path, 'r', 'utf-8') as f:
contents = f.read()
parser.Parse(contents)