mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 11:42:52 +01:00
Use utf-8 to encode files by default.
Should fix this bug in Seen: Traceback (most recent call last): File "C:\Program Files\Python34\lib\site-packages\supybot\world.py", line 121, in flush f() File "C:\Program Files\Python34\lib\site-packages\supybot\plugins\__init__.py", line 271, in flush writer.writerow(L) File "C:\Program Files\Python34\lib\site-packages\supybot\utils\file.py", line 172, in write return self._fd.write(data) File "C:\Program Files\Python34\lib\encodings\cp1250.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\u25c4' in position 33: character maps to <undefined>
This commit is contained in:
parent
cf52fabe10
commit
49ff291f61
@ -32,6 +32,7 @@ import gc
|
||||
import os
|
||||
import csv
|
||||
import time
|
||||
import codecs
|
||||
import fnmatch
|
||||
import os.path
|
||||
import threading
|
||||
@ -221,7 +222,7 @@ class ChannelUserDB(ChannelUserDictionary):
|
||||
ChannelUserDictionary.__init__(self)
|
||||
self.filename = filename
|
||||
try:
|
||||
fd = open(self.filename)
|
||||
fd = codecs.open(self.filename, encoding='utf8')
|
||||
except EnvironmentError as e:
|
||||
log.warning('Couldn\'t open %s: %s.', self.filename, e)
|
||||
return
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
import os
|
||||
import time
|
||||
import codecs
|
||||
import random
|
||||
import shutil
|
||||
import os.path
|
||||
@ -126,7 +127,8 @@ class AtomicFile(object):
|
||||
makeBackupIfSmaller = True
|
||||
allowEmptyOverwrite = True
|
||||
def __init__(self, filename, mode='w', allowEmptyOverwrite=None,
|
||||
makeBackupIfSmaller=None, tmpDir=None, backupDir=None):
|
||||
makeBackupIfSmaller=None, tmpDir=None, backupDir=None,
|
||||
encoding=None):
|
||||
if tmpDir is None:
|
||||
tmpDir = force(self.default.tmpDir)
|
||||
if backupDir is None:
|
||||
@ -135,6 +137,8 @@ class AtomicFile(object):
|
||||
makeBackupIfSmaller = force(self.default.makeBackupIfSmaller)
|
||||
if allowEmptyOverwrite is None:
|
||||
allowEmptyOverwrite = force(self.default.allowEmptyOverwrite)
|
||||
if encoding is None and 'b' not in mode:
|
||||
encoding = 'utf8'
|
||||
if mode not in ('w', 'wb'):
|
||||
raise ValueError(format('Invalid mode: %q', mode))
|
||||
self.rolledback = False
|
||||
@ -153,7 +157,7 @@ class AtomicFile(object):
|
||||
self.tempFilename = os.path.join(tmpDir, tempFilename)
|
||||
# This doesn't work because of the uncollectable garbage effect.
|
||||
# self.__parent = super(AtomicFile, self)
|
||||
self._fd = open(self.tempFilename, mode)
|
||||
self._fd = codecs.open(self.tempFilename, mode, encoding=encoding)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
Loading…
Reference in New Issue
Block a user