diff options
author | cumul <gg6123@naver.com> | 2018-10-31 09:45:30 +0300 |
---|---|---|
committer | cumul0529 <gg6123@naver.com> | 2020-02-23 19:29:37 +0300 |
commit | 247d9cd8870635dd9d065883e7853b86c0c76531 (patch) | |
tree | 07b06cbf05b54d31177db7df7d08c7969bc1c401 | |
parent | d6ef34a03e21f8e8da0bc45d6b7124d50cfc5ec1 (diff) |
Use `io` module instead of `codecs`
See https://mail.python.org/pipermail/python-list/2015-March/687124.html
-rw-r--r-- | certbot-nginx/certbot_nginx/_internal/parser.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/certbot-nginx/certbot_nginx/_internal/parser.py b/certbot-nginx/certbot_nginx/_internal/parser.py index 38c4d63e1..d6182870c 100644 --- a/certbot-nginx/certbot_nginx/_internal/parser.py +++ b/certbot-nginx/certbot_nginx/_internal/parser.py @@ -1,8 +1,8 @@ """NginxParser is a member object of the NginxConfigurator class.""" import copy -import codecs import functools import glob +import io import logging import re @@ -206,12 +206,14 @@ class NginxParser(object): if item in self.parsed and not override: continue try: - with codecs.open(item, "r", "utf-8") as _file: + with io.open(item, "r", encoding="utf-8") as _file: parsed = nginxparser.load(_file) self.parsed[item] = parsed trees.append(parsed) except IOError: logger.warning("Could not open file: %s", item) + except UnicodeDecodeError: + logger.warning("Could not read file: %s due to invalid unicode character. Only UTF-8 encoding is supported.", item) except pyparsing.ParseException as err: logger.debug("Could not parse file: %s due to %s", item, err) return trees @@ -415,10 +417,12 @@ class NginxParser(object): def _parse_ssl_options(ssl_options): if ssl_options is not None: try: - with codecs.open(ssl_options, "r", "utf-8") as _file: + with io.open(ssl_options, "r", encoding="utf-8") as _file: return nginxparser.load(_file) except IOError: logger.warning("Missing NGINX TLS options file: %s", ssl_options) + except UnicodeDecodeError: + logger.warn("Could not read file: %s due to invalid unicode character. Only UTF-8 encoding is supported.", ssl_options) except pyparsing.ParseBaseException as err: logger.debug("Could not parse file: %s due to %s", ssl_options, err) return [] |