mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +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 os
|
||||||
import csv
|
import csv
|
||||||
import time
|
import time
|
||||||
|
import codecs
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import os.path
|
import os.path
|
||||||
import threading
|
import threading
|
||||||
@ -221,7 +222,7 @@ class ChannelUserDB(ChannelUserDictionary):
|
|||||||
ChannelUserDictionary.__init__(self)
|
ChannelUserDictionary.__init__(self)
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
try:
|
try:
|
||||||
fd = open(self.filename)
|
fd = codecs.open(self.filename, encoding='utf8')
|
||||||
except EnvironmentError as e:
|
except EnvironmentError as e:
|
||||||
log.warning('Couldn\'t open %s: %s.', self.filename, e)
|
log.warning('Couldn\'t open %s: %s.', self.filename, e)
|
||||||
return
|
return
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import codecs
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import os.path
|
import os.path
|
||||||
@ -126,7 +127,8 @@ class AtomicFile(object):
|
|||||||
makeBackupIfSmaller = True
|
makeBackupIfSmaller = True
|
||||||
allowEmptyOverwrite = True
|
allowEmptyOverwrite = True
|
||||||
def __init__(self, filename, mode='w', allowEmptyOverwrite=None,
|
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:
|
if tmpDir is None:
|
||||||
tmpDir = force(self.default.tmpDir)
|
tmpDir = force(self.default.tmpDir)
|
||||||
if backupDir is None:
|
if backupDir is None:
|
||||||
@ -135,6 +137,8 @@ class AtomicFile(object):
|
|||||||
makeBackupIfSmaller = force(self.default.makeBackupIfSmaller)
|
makeBackupIfSmaller = force(self.default.makeBackupIfSmaller)
|
||||||
if allowEmptyOverwrite is None:
|
if allowEmptyOverwrite is None:
|
||||||
allowEmptyOverwrite = force(self.default.allowEmptyOverwrite)
|
allowEmptyOverwrite = force(self.default.allowEmptyOverwrite)
|
||||||
|
if encoding is None and 'b' not in mode:
|
||||||
|
encoding = 'utf8'
|
||||||
if mode not in ('w', 'wb'):
|
if mode not in ('w', 'wb'):
|
||||||
raise ValueError(format('Invalid mode: %q', mode))
|
raise ValueError(format('Invalid mode: %q', mode))
|
||||||
self.rolledback = False
|
self.rolledback = False
|
||||||
@ -153,7 +157,7 @@ class AtomicFile(object):
|
|||||||
self.tempFilename = os.path.join(tmpDir, tempFilename)
|
self.tempFilename = os.path.join(tmpDir, tempFilename)
|
||||||
# This doesn't work because of the uncollectable garbage effect.
|
# This doesn't work because of the uncollectable garbage effect.
|
||||||
# self.__parent = super(AtomicFile, self)
|
# self.__parent = super(AtomicFile, self)
|
||||||
self._fd = open(self.tempFilename, mode)
|
self._fd = codecs.open(self.tempFilename, mode, encoding=encoding)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
Loading…
Reference in New Issue
Block a user