diff options
| author | 2020-02-24 15:24:39 +0000 | |
|---|---|---|
| committer | 2020-02-24 15:24:39 +0000 | |
| commit | 175c0a285c0eba508fd4b93b3d858e73985339e6 (patch) | |
| tree | 783e22ccfe51c3bd92c1b53d741e683c13298545 | |
| parent | use "latin-1" consitently (not "iso-8859-1") (diff) | |
| signature | ||
open possibly-utf8 files with forced utf8
| -rw-r--r-- | modules/channel_log.py | 2 | ||||
| -rw-r--r-- | src/Config.py | 5 | ||||
| -rw-r--r-- | src/utils/__init__.py | 2 | ||||
| -rw-r--r-- | src/utils/io.py | 4 | ||||
| -rw-r--r-- | src/utils/parse/__init__.py | 6 |
5 files changed, 12 insertions, 7 deletions
diff --git a/modules/channel_log.py b/modules/channel_log.py index 28de5e1c..d4b677c6 100644 --- a/modules/channel_log.py +++ b/modules/channel_log.py @@ -28,7 +28,7 @@ class Module(ModuleManager.BaseModule): channel.__log_file.write("%s\n" % line) def _write(self, channel, filename, key, line): if not hasattr(channel, "__log_file"): - channel.__log_file = open(filename, "a") + channel.__log_file = utils.io.open(filename, "a") channel.__log_rsa = None channel.__log_aes = None diff --git a/src/Config.py b/src/Config.py index 06926dbb..e2449cc5 100644 --- a/src/Config.py +++ b/src/Config.py @@ -1,4 +1,5 @@ import collections, configparser, os, typing +from src import utils class Config(object): def __init__(self, name: str, location: str): @@ -11,7 +12,7 @@ class Config(object): def load(self): if os.path.isfile(self.location): - with open(self.location) as config_file: + with utils.io.open(self.location, "r") as config_file: parser = self._parser() parser.read_string(config_file.read()) self._config.clear() @@ -20,7 +21,7 @@ class Config(object): self._config[k] = v def save(self): - with open(self.location, "w") as config_file: + with utils.io.open(self.location, "w") as config_file: parser = self._parser() parser[self._name] = self._config.copy() parser.write(config_file) diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 55129137..3a4b71c0 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -1,6 +1,6 @@ import contextlib, enum, ipaddress, multiprocessing, os.path, queue, signal import threading, typing -from . import cli, consts, datetime, decorators, irc, http, parse, security +from . import cli, consts, datetime, decorators, io, irc, http, parse, security from .decorators import export, hook, kwarg, spec from .settings import (BoolSetting, FunctionSetting, IntRangeSetting, diff --git a/src/utils/io.py b/src/utils/io.py new file mode 100644 index 00000000..ff565849 --- /dev/null +++ b/src/utils/io.py @@ -0,0 +1,4 @@ +import io + +def open(path: str, mode: str): + return io.open(path, mode=mode, encoding="utf8") diff --git a/src/utils/parse/__init__.py b/src/utils/parse/__init__.py index 28f074c2..262edf4a 100644 --- a/src/utils/parse/__init__.py +++ b/src/utils/parse/__init__.py @@ -1,5 +1,5 @@ -import decimal, io, re, typing -from src.utils import datetime, errors +import decimal, re, typing +from src.utils import datetime, errors, io from .spec import * from .time import duration @@ -10,7 +10,7 @@ COMMENT_TYPES = ["#", "//"] def hashflags(filename: str ) -> typing.List[typing.Tuple[str, typing.Optional[str]]]: hashflags = [] # type: typing.List[typing.Tuple[str, typing.Optional[str]]] - with io.open(filename, mode="r", encoding="utf8") as f: + with io.open(filename, "r") as f: for line in f: line = line.strip("\n") found = False |
