Add explicit encoding to open() calls.
This commit is contained in:
parent
fb8ef69a63
commit
17dd4732ae
@ -276,7 +276,7 @@ class Application(QApplication):
|
||||
'crash.log')
|
||||
# First check if an old logfile exists.
|
||||
if os.path.exists(logname):
|
||||
with open(logname, 'r') as f:
|
||||
with open(logname, 'r', encoding='ascii') as f:
|
||||
data = f.read()
|
||||
if data:
|
||||
# Crashlog exists and has data in it, so something crashed
|
||||
@ -309,7 +309,7 @@ class Application(QApplication):
|
||||
"""Start a new logfile and redirect faulthandler to it."""
|
||||
logname = os.path.join(get_standard_dir(QStandardPaths.DataLocation),
|
||||
'crash.log')
|
||||
self._crashlogfile = open(logname, 'w')
|
||||
self._crashlogfile = open(logname, 'w', encoding='ascii')
|
||||
faulthandler.enable(self._crashlogfile)
|
||||
if (hasattr(faulthandler, 'register') and
|
||||
hasattr(signal, 'SIGUSR1')):
|
||||
|
@ -78,7 +78,8 @@ class _BlockingFIFOReader(QObject):
|
||||
# We also use os.open and os.fdopen rather than built-in open so we can
|
||||
# add O_NONBLOCK.
|
||||
fd = os.open(self.filepath, os.O_RDWR |
|
||||
os.O_NONBLOCK) # pylint: disable=no-member
|
||||
os.O_NONBLOCK,
|
||||
encoding='utf-8') # pylint: disable=no-member
|
||||
self.fifo = os.fdopen(fd, 'r')
|
||||
while True:
|
||||
logger.debug("thread loop")
|
||||
@ -279,7 +280,7 @@ class _WindowsUserscriptRunner(_BaseUserscriptRunner):
|
||||
got_cmd: Emitted for every command in the file.
|
||||
"""
|
||||
logger.debug("proc finished")
|
||||
with open(self.filepath, 'r') as f:
|
||||
with open(self.filepath, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
self.got_cmd.emit(line.rstrip())
|
||||
self._cleanup()
|
||||
|
@ -78,7 +78,7 @@ def read_file(filename):
|
||||
if hasattr(sys, 'frozen'):
|
||||
# cx_Freeze doesn't support pkg_resources :(
|
||||
fn = os.path.join(os.path.dirname(sys.executable), filename)
|
||||
with open(fn, 'r', encoding='UTF-8') as f:
|
||||
with open(fn, 'r', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
else:
|
||||
return resource_string(qutebrowser.__name__, filename).decode('UTF-8')
|
||||
@ -193,7 +193,8 @@ def actute_warning():
|
||||
return
|
||||
except ValueError:
|
||||
pass
|
||||
with open('/usr/share/X11/locale/en_US.UTF-8/Compose', 'r') as f:
|
||||
with open('/usr/share/X11/locale/en_US.UTF-8/Compose', 'r',
|
||||
encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if '<dead_actute>' in line:
|
||||
if sys.stdout is not None:
|
||||
|
@ -128,7 +128,7 @@ def _release_info():
|
||||
data = []
|
||||
for fn in glob.glob("/etc/*-release"):
|
||||
try:
|
||||
with open(fn, 'r') as f:
|
||||
with open(fn, 'r', encoding='utf-8') as f:
|
||||
data.append((fn, ''.join(f.readlines())))
|
||||
except IOError as e:
|
||||
logger.warning("Error while reading {}: {}: {}".format(
|
||||
|
@ -35,7 +35,7 @@ BASEDIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||
|
||||
def read_file(name):
|
||||
"""Get the string contained in the file named name."""
|
||||
with open(name, encoding='utf-8') as f:
|
||||
with open(name, 'r', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
@ -87,7 +87,8 @@ def write_git_file():
|
||||
gitstr = _git_str()
|
||||
if gitstr is None:
|
||||
gitstr = ''
|
||||
with open(os.path.join(BASEDIR, 'qutebrowser', 'git-commit-id'), 'w') as f:
|
||||
path = os.path.join(BASEDIR, 'qutebrowser', 'git-commit-id')
|
||||
with open(path, 'w', encoding='utf-8') as f:
|
||||
f.write(gitstr)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user