Fix encoding issues on windows.
locale.getpreferredencoding(False) returns cp1252 on Windows, which is unable to parse our nice unicode arrows. Therefore, we always need to specify the encoding when using open(). Also we exclude configdata.py from pep257 on Windows because it doesn't detect the encoding correctly... Bug is submitted: https://github.com/GreenSteam/pep257/issues/70
This commit is contained in:
parent
be467d5e50
commit
ae0966a384
@ -394,7 +394,7 @@ class CurCommandDispatcher(QObject):
|
||||
oshandle, filename = mkstemp(text=True)
|
||||
text = elem.evaluateJavaScript('this.value')
|
||||
if text:
|
||||
with open(filename, 'w') as f:
|
||||
with open(filename, 'w', encoding='utf-8') as f:
|
||||
f.write(text)
|
||||
proc = QProcess(self)
|
||||
proc.finished.connect(partial(self.on_editor_closed, elem, oshandle,
|
||||
@ -431,7 +431,7 @@ class CurCommandDispatcher(QObject):
|
||||
if elem.isNull():
|
||||
message.error("Element vanished while editing!")
|
||||
return
|
||||
with open(filename, 'r') as f:
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
text = ''.join(f.readlines())
|
||||
text = webelem.javascript_escape(text)
|
||||
logging.debug("Read back: {}".format(text))
|
||||
|
@ -46,7 +46,7 @@ class ReadConfigParser(ConfigParser):
|
||||
if not os.path.isfile(self._configfile):
|
||||
return
|
||||
logging.debug("Reading config from {}".format(self._configfile))
|
||||
self.read(self._configfile)
|
||||
self.read(self._configfile, encoding='utf-8')
|
||||
|
||||
|
||||
class ReadWriteConfigParser(ReadConfigParser):
|
||||
@ -58,5 +58,5 @@ class ReadWriteConfigParser(ReadConfigParser):
|
||||
if not os.path.exists(self._configdir):
|
||||
os.makedirs(self._configdir, 0o755)
|
||||
logging.debug("Saving config to {}".format(self._configfile))
|
||||
with open(self._configfile, 'w') as f:
|
||||
with open(self._configfile, 'w', encoding='utf-8') as f:
|
||||
self.write(f)
|
||||
|
@ -53,7 +53,7 @@ class LineConfigParser:
|
||||
|
||||
def read(self, filename):
|
||||
"""Read the data from a file."""
|
||||
with open(filename, 'r') as f:
|
||||
with open(filename, 'r', encoding='utf-8') as f:
|
||||
self.data = [line.rstrip('\n') for line in f.readlines()]
|
||||
|
||||
def write(self, fp, limit=-1):
|
||||
@ -82,7 +82,7 @@ class LineConfigParser:
|
||||
if not os.path.exists(self._configdir):
|
||||
os.makedirs(self._configdir, 0o755)
|
||||
logging.debug("Saving config to {}".format(self._configfile))
|
||||
with open(self._configfile, 'w') as f:
|
||||
with open(self._configfile, 'w', encoding='utf-8') as f:
|
||||
self.write(f, limit)
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
|
@ -374,7 +374,7 @@ class ConfigManager(QObject):
|
||||
if not os.path.exists(self._configdir):
|
||||
os.makedirs(self._configdir, 0o755)
|
||||
logging.debug("Saving config to {}".format(self._configfile))
|
||||
with open(self._configfile, 'w') as f:
|
||||
with open(self._configfile, 'w', encoding='utf-8') as f:
|
||||
f.write(str(self))
|
||||
|
||||
def dump_userconfig(self):
|
||||
|
@ -52,6 +52,7 @@ options = {
|
||||
],
|
||||
},
|
||||
'exclude': ['appdirs.py'],
|
||||
'exclude_pep257': [],
|
||||
'other': {
|
||||
'pylint': ['--output-format=colorized', '--reports=no',
|
||||
'--rcfile=.pylintrc'],
|
||||
@ -59,6 +60,10 @@ options = {
|
||||
},
|
||||
}
|
||||
|
||||
if os.name == 'nt':
|
||||
# pep257 uses cp1252 by default on Windows, which can't handle the unicode
|
||||
# arrows in configdata.py
|
||||
options['exclude_pep257'].append('configdata.py')
|
||||
|
||||
def run(name, args=None):
|
||||
"""Run a checker via distutils with optional args.
|
||||
@ -180,7 +185,7 @@ def _get_args(checker):
|
||||
pass
|
||||
try:
|
||||
args += ['--match=(?!{}).*\.py'.format('|'.join(
|
||||
options['exclude']))]
|
||||
options['exclude'] + options['exclude_pep257']))]
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user