mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 08:45:22 +02:00
Use io module instead of codecs
See https://mail.python.org/pipermail/python-list/2015-March/687124.html
This commit is contained in:
@@ -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 []
|
||||
|
||||
Reference in New Issue
Block a user