mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 19:02:52 +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."""
|
"""NginxParser is a member object of the NginxConfigurator class."""
|
||||||
import copy
|
import copy
|
||||||
import codecs
|
|
||||||
import functools
|
import functools
|
||||||
import glob
|
import glob
|
||||||
|
import io
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -206,12 +206,14 @@ class NginxParser(object):
|
|||||||
if item in self.parsed and not override:
|
if item in self.parsed and not override:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
with codecs.open(item, "r", "utf-8") as _file:
|
with io.open(item, "r", encoding="utf-8") as _file:
|
||||||
parsed = nginxparser.load(_file)
|
parsed = nginxparser.load(_file)
|
||||||
self.parsed[item] = parsed
|
self.parsed[item] = parsed
|
||||||
trees.append(parsed)
|
trees.append(parsed)
|
||||||
except IOError:
|
except IOError:
|
||||||
logger.warning("Could not open file: %s", item)
|
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:
|
except pyparsing.ParseException as err:
|
||||||
logger.debug("Could not parse file: %s due to %s", item, err)
|
logger.debug("Could not parse file: %s due to %s", item, err)
|
||||||
return trees
|
return trees
|
||||||
@@ -415,10 +417,12 @@ class NginxParser(object):
|
|||||||
def _parse_ssl_options(ssl_options):
|
def _parse_ssl_options(ssl_options):
|
||||||
if ssl_options is not None:
|
if ssl_options is not None:
|
||||||
try:
|
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)
|
return nginxparser.load(_file)
|
||||||
except IOError:
|
except IOError:
|
||||||
logger.warning("Missing NGINX TLS options file: %s", ssl_options)
|
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:
|
except pyparsing.ParseBaseException as err:
|
||||||
logger.debug("Could not parse file: %s due to %s", ssl_options, err)
|
logger.debug("Could not parse file: %s due to %s", ssl_options, err)
|
||||||
return []
|
return []
|
||||||
|
|||||||
Reference in New Issue
Block a user