mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 19:14:54 +02:00
Merge pull request #10084 from atombrella/pyupgrade/up024_oserror
Replace aliased OSError.
This commit is contained in:
@@ -193,7 +193,7 @@ class BaseDualNetworkedServersTest(unittest.TestCase):
|
|||||||
|
|
||||||
from acme.standalone import BaseDualNetworkedServers
|
from acme.standalone import BaseDualNetworkedServers
|
||||||
|
|
||||||
mock_bind.side_effect = socket.error(EADDRINUSE, "Fake addr in use error")
|
mock_bind.side_effect = OSError(EADDRINUSE, "Fake addr in use error")
|
||||||
|
|
||||||
with pytest.raises(socket.error) as exc_info:
|
with pytest.raises(socket.error) as exc_info:
|
||||||
BaseDualNetworkedServers(
|
BaseDualNetworkedServers(
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ class SSLSocket: # pylint: disable=too-few-public-methods
|
|||||||
# in the standard library. This is useful when this object is
|
# in the standard library. This is useful when this object is
|
||||||
# used by code which expects a standard socket such as
|
# used by code which expects a standard socket such as
|
||||||
# socketserver in the standard library.
|
# socketserver in the standard library.
|
||||||
raise socket.error(error)
|
raise OSError(error)
|
||||||
|
|
||||||
def accept(self) -> Tuple[FakeConnection, Any]: # pylint: disable=missing-function-docstring
|
def accept(self) -> Tuple[FakeConnection, Any]: # pylint: disable=missing-function-docstring
|
||||||
sock, addr = self.sock.accept()
|
sock, addr = self.sock.accept()
|
||||||
@@ -158,7 +158,7 @@ class SSLSocket: # pylint: disable=too-few-public-methods
|
|||||||
except SSL.Error as error:
|
except SSL.Error as error:
|
||||||
# _pick_certificate_cb might have returned without
|
# _pick_certificate_cb might have returned without
|
||||||
# creating SSL context (wrong server name)
|
# creating SSL context (wrong server name)
|
||||||
raise socket.error(error)
|
raise OSError(error)
|
||||||
|
|
||||||
return ssl_sock, addr
|
return ssl_sock, addr
|
||||||
except:
|
except:
|
||||||
@@ -206,7 +206,7 @@ def probe_sni(name: bytes, host: bytes, port: int = 443, timeout: int = 300, #
|
|||||||
)
|
)
|
||||||
socket_tuple: Tuple[bytes, int] = (host, port)
|
socket_tuple: Tuple[bytes, int] = (host, port)
|
||||||
sock = socket.create_connection(socket_tuple, **socket_kwargs) # type: ignore[arg-type]
|
sock = socket.create_connection(socket_tuple, **socket_kwargs) # type: ignore[arg-type]
|
||||||
except socket.error as error:
|
except OSError as error:
|
||||||
raise errors.Error(error)
|
raise errors.Error(error)
|
||||||
|
|
||||||
with contextlib.closing(sock) as client:
|
with contextlib.closing(sock) as client:
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class BaseDualNetworkedServers:
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
"Successfully bound to %s:%s using %s", new_address[0],
|
"Successfully bound to %s:%s using %s", new_address[0],
|
||||||
new_address[1], "IPv6" if ip_version else "IPv4")
|
new_address[1], "IPv6" if ip_version else "IPv4")
|
||||||
except socket.error as e:
|
except OSError as e:
|
||||||
last_socket_err = e
|
last_socket_err = e
|
||||||
if self.servers:
|
if self.servers:
|
||||||
# Already bound using IPv6.
|
# Already bound using IPv6.
|
||||||
@@ -121,7 +121,7 @@ class BaseDualNetworkedServers:
|
|||||||
if last_socket_err:
|
if last_socket_err:
|
||||||
raise last_socket_err
|
raise last_socket_err
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
raise socket.error("Could not bind to IPv4 or IPv6.")
|
raise OSError("Could not bind to IPv4 or IPv6.")
|
||||||
|
|
||||||
def serve_forever(self) -> None:
|
def serve_forever(self) -> None:
|
||||||
"""Wraps socketserver.TCPServer.serve_forever"""
|
"""Wraps socketserver.TCPServer.serve_forever"""
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ class ApacheConfigurator(common.Configurator):
|
|||||||
try:
|
try:
|
||||||
with open(ssl_module_location, mode="rb") as f:
|
with open(ssl_module_location, mode="rb") as f:
|
||||||
contents = f.read()
|
contents = f.read()
|
||||||
except IOError as error:
|
except OSError as error:
|
||||||
logger.debug(str(error), exc_info=True)
|
logger.debug(str(error), exc_info=True)
|
||||||
return None
|
return None
|
||||||
return contents
|
return contents
|
||||||
@@ -928,7 +928,7 @@ class ApacheConfigurator(common.Configurator):
|
|||||||
try:
|
try:
|
||||||
socket.inet_aton(addr.get_addr())
|
socket.inet_aton(addr.get_addr())
|
||||||
return socket.gethostbyaddr(addr.get_addr())[0]
|
return socket.gethostbyaddr(addr.get_addr())[0]
|
||||||
except (socket.error, socket.herror, socket.timeout):
|
except (OSError, socket.herror, socket.timeout):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
@@ -1523,7 +1523,7 @@ class ApacheConfigurator(common.Configurator):
|
|||||||
# activation (it's not included as default)
|
# activation (it's not included as default)
|
||||||
if not self.parser.parsed_in_current(ssl_fp):
|
if not self.parser.parsed_in_current(ssl_fp):
|
||||||
self.parser.parse_file(ssl_fp)
|
self.parser.parse_file(ssl_fp)
|
||||||
except IOError:
|
except OSError:
|
||||||
logger.critical("Error writing/reading to file in make_vhost_ssl", exc_info=True)
|
logger.critical("Error writing/reading to file in make_vhost_ssl", exc_info=True)
|
||||||
raise errors.PluginError("Unable to write/read in make_vhost_ssl")
|
raise errors.PluginError("Unable to write/read in make_vhost_ssl")
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ class ApacheParser:
|
|||||||
try:
|
try:
|
||||||
# This is a noop save
|
# This is a noop save
|
||||||
self.aug.save()
|
self.aug.save()
|
||||||
except (RuntimeError, IOError):
|
except (OSError, RuntimeError):
|
||||||
self._log_save_errors(ex_errs)
|
self._log_save_errors(ex_errs)
|
||||||
# Erase Save Notes
|
# Erase Save Notes
|
||||||
self.configurator.save_notes = ""
|
self.configurator.save_notes = ""
|
||||||
@@ -198,7 +198,7 @@ class ApacheParser:
|
|||||||
ex_errs = self.aug.match("/augeas//error")
|
ex_errs = self.aug.match("/augeas//error")
|
||||||
try:
|
try:
|
||||||
self.aug.save()
|
self.aug.save()
|
||||||
except IOError:
|
except OSError:
|
||||||
self._log_save_errors(ex_errs)
|
self._log_save_errors(ex_errs)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|||||||
@@ -686,7 +686,7 @@ class NginxConfigurator(common.Configurator):
|
|||||||
else:
|
else:
|
||||||
socket.inet_pton(socket.AF_INET, host)
|
socket.inet_pton(socket.AF_INET, host)
|
||||||
all_names.add(socket.gethostbyaddr(host)[0])
|
all_names.add(socket.gethostbyaddr(host)[0])
|
||||||
except (socket.error, socket.herror, socket.timeout):
|
except (OSError, socket.herror, socket.timeout):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return util.get_filtered_names(all_names)
|
return util.get_filtered_names(all_names)
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ class NginxParser:
|
|||||||
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 OSError:
|
||||||
logger.warning("Could not open file: %s", item)
|
logger.warning("Could not open file: %s", item)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
logger.warning("Could not read file: %s due to invalid "
|
logger.warning("Could not read file: %s due to invalid "
|
||||||
@@ -258,7 +258,7 @@ class NginxParser:
|
|||||||
with io.open(filename, 'w', encoding='utf-8') as _file:
|
with io.open(filename, 'w', encoding='utf-8') as _file:
|
||||||
_file.write(out)
|
_file.write(out)
|
||||||
|
|
||||||
except IOError:
|
except OSError:
|
||||||
logger.error("Could not open file for writing: %s", filename)
|
logger.error("Could not open file for writing: %s", filename)
|
||||||
|
|
||||||
def parse_server(self, server: UnspacedList) -> Dict[str, Any]:
|
def parse_server(self, server: UnspacedList) -> Dict[str, Any]:
|
||||||
@@ -433,7 +433,7 @@ def _parse_ssl_options(ssl_options: Optional[str]) -> List[UnspacedList]:
|
|||||||
try:
|
try:
|
||||||
with io.open(ssl_options, "r", encoding="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 OSError:
|
||||||
logger.warning("Missing NGINX TLS options file: %s", ssl_options)
|
logger.warning("Missing NGINX TLS options file: %s", ssl_options)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
logger.warning("Could not read file: %s due to invalid character. "
|
logger.warning("Could not read file: %s due to invalid character. "
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ class AccountFileStorage(interfaces.AccountStorage):
|
|||||||
key = jose.JWK.json_loads(key_file.read())
|
key = jose.JWK.json_loads(key_file.read())
|
||||||
with open(self._metadata_path(account_dir_path)) as metadata_file:
|
with open(self._metadata_path(account_dir_path)) as metadata_file:
|
||||||
meta = Account.Meta.json_loads(metadata_file.read())
|
meta = Account.Meta.json_loads(metadata_file.read())
|
||||||
except IOError as error:
|
except OSError as error:
|
||||||
raise errors.AccountStorageError(error)
|
raise errors.AccountStorageError(error)
|
||||||
|
|
||||||
return Account(regr, key, meta)
|
return Account(regr, key, meta)
|
||||||
@@ -243,7 +243,7 @@ class AccountFileStorage(interfaces.AccountStorage):
|
|||||||
self._create(account, dir_path)
|
self._create(account, dir_path)
|
||||||
self._update_meta(account, dir_path)
|
self._update_meta(account, dir_path)
|
||||||
self._update_regr(account, dir_path)
|
self._update_regr(account, dir_path)
|
||||||
except IOError as error:
|
except OSError as error:
|
||||||
raise errors.AccountStorageError(error)
|
raise errors.AccountStorageError(error)
|
||||||
|
|
||||||
def update_regr(self, account: Account) -> None:
|
def update_regr(self, account: Account) -> None:
|
||||||
@@ -255,7 +255,7 @@ class AccountFileStorage(interfaces.AccountStorage):
|
|||||||
try:
|
try:
|
||||||
dir_path = self._prepare(account)
|
dir_path = self._prepare(account)
|
||||||
self._update_regr(account, dir_path)
|
self._update_regr(account, dir_path)
|
||||||
except IOError as error:
|
except OSError as error:
|
||||||
raise errors.AccountStorageError(error)
|
raise errors.AccountStorageError(error)
|
||||||
|
|
||||||
def update_meta(self, account: Account) -> None:
|
def update_meta(self, account: Account) -> None:
|
||||||
@@ -267,7 +267,7 @@ class AccountFileStorage(interfaces.AccountStorage):
|
|||||||
try:
|
try:
|
||||||
dir_path = self._prepare(account)
|
dir_path = self._prepare(account)
|
||||||
self._update_meta(account, dir_path)
|
self._update_meta(account, dir_path)
|
||||||
except IOError as error:
|
except OSError as error:
|
||||||
raise errors.AccountStorageError(error)
|
raise errors.AccountStorageError(error)
|
||||||
|
|
||||||
def delete(self, account_id: str) -> None:
|
def delete(self, account_id: str) -> None:
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ def lineage_for_certname(cli_config: configuration.NamespaceConfig,
|
|||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
return storage.RenewableCert(renewal_file, cli_config)
|
return storage.RenewableCert(renewal_file, cli_config)
|
||||||
except (errors.CertStorageError, IOError):
|
except (OSError, errors.CertStorageError):
|
||||||
logger.debug("Renewal conf file %s is broken.", renewal_file)
|
logger.debug("Renewal conf file %s is broken.", renewal_file)
|
||||||
logger.debug("Traceback was:\n%s", traceback.format_exc())
|
logger.debug("Traceback was:\n%s", traceback.format_exc())
|
||||||
return None
|
return None
|
||||||
@@ -419,7 +419,7 @@ def _search_lineages(cli_config: configuration.NamespaceConfig, func: Callable[.
|
|||||||
for renewal_file in storage.renewal_conf_files(cli_config):
|
for renewal_file in storage.renewal_conf_files(cli_config):
|
||||||
try:
|
try:
|
||||||
candidate_lineage = storage.RenewableCert(renewal_file, cli_config)
|
candidate_lineage = storage.RenewableCert(renewal_file, cli_config)
|
||||||
except (errors.CertStorageError, IOError):
|
except (OSError, errors.CertStorageError):
|
||||||
logger.debug("Renewal conf file %s is broken. Skipping.", renewal_file)
|
logger.debug("Renewal conf file %s is broken. Skipping.", renewal_file)
|
||||||
logger.debug("Traceback was:\n%s", traceback.format_exc())
|
logger.debug("Traceback was:\n%s", traceback.format_exc())
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ def read_file(filename: str, mode: str = "rb") -> Tuple[str, Any]:
|
|||||||
with open(filename, mode) as the_file:
|
with open(filename, mode) as the_file:
|
||||||
contents = the_file.read()
|
contents = the_file.read()
|
||||||
return filename, contents
|
return filename, contents
|
||||||
except IOError as exc:
|
except OSError as exc:
|
||||||
raise argparse.ArgumentTypeError(exc.strerror)
|
raise argparse.ArgumentTypeError(exc.strerror)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class _UnixLockMechanism(_BaseLockMechanism):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
if err.errno in (errno.EACCES, errno.EAGAIN):
|
if err.errno in (errno.EACCES, errno.EAGAIN):
|
||||||
logger.debug('A lock on %s is held by another process.', self._path)
|
logger.debug('A lock on %s is held by another process.', self._path)
|
||||||
raise errors.LockError('Another instance of Certbot is already running.')
|
raise errors.LockError('Another instance of Certbot is already running.')
|
||||||
@@ -210,7 +210,7 @@ class _WindowsLockMechanism(_BaseLockMechanism):
|
|||||||
# are only defined on Windows. See
|
# are only defined on Windows. See
|
||||||
# https://github.com/python/typeshed/blob/16ae4c61201cd8b96b8b22cdfb2ab9e89ba5bcf2/stdlib/msvcrt.pyi.
|
# https://github.com/python/typeshed/blob/16ae4c61201cd8b96b8b22cdfb2ab9e89ba5bcf2/stdlib/msvcrt.pyi.
|
||||||
msvcrt.locking(fd, msvcrt.LK_NBLCK, 1) # type: ignore # pylint: disable=used-before-assignment
|
msvcrt.locking(fd, msvcrt.LK_NBLCK, 1) # type: ignore # pylint: disable=used-before-assignment
|
||||||
except (IOError, OSError) as err:
|
except OSError as err:
|
||||||
if fd:
|
if fd:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
# Anything except EACCES is unexpected. Raise directly the error in that case.
|
# Anything except EACCES is unexpected. Raise directly the error in that case.
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ def setup_log_file_handler(config: configuration.NamespaceConfig, logfile: str,
|
|||||||
handler = logging.handlers.RotatingFileHandler(
|
handler = logging.handlers.RotatingFileHandler(
|
||||||
log_file_path, maxBytes=2 ** 20,
|
log_file_path, maxBytes=2 ** 20,
|
||||||
backupCount=config.max_log_backups)
|
backupCount=config.max_log_backups)
|
||||||
except IOError as error:
|
except OSError as error:
|
||||||
raise errors.Error(util.PERM_ERR_FMT.format(error))
|
raise errors.Error(util.PERM_ERR_FMT.format(error))
|
||||||
# rotate on each invocation, rollover only possible when maxBytes
|
# rotate on each invocation, rollover only possible when maxBytes
|
||||||
# is nonzero and backupCount is nonzero, so we set maxBytes as big
|
# is nonzero and backupCount is nonzero, so we set maxBytes as big
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import collections
|
import collections
|
||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
import socket
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
from typing import DefaultDict
|
from typing import DefaultDict
|
||||||
@@ -78,7 +77,7 @@ class ServerManager:
|
|||||||
try:
|
try:
|
||||||
servers = acme_standalone.HTTP01DualNetworkedServers(
|
servers = acme_standalone.HTTP01DualNetworkedServers(
|
||||||
address, self.http_01_resources)
|
address, self.http_01_resources)
|
||||||
except socket.error as error:
|
except OSError as error:
|
||||||
raise errors.StandaloneBindError(error, port)
|
raise errors.StandaloneBindError(error, port)
|
||||||
|
|
||||||
servers.serve_forever()
|
servers.serve_forever()
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ def reconstitute(config: configuration.NamespaceConfig,
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
renewal_candidate = storage.RenewableCert(full_path, config)
|
renewal_candidate = storage.RenewableCert(full_path, config)
|
||||||
except (errors.CertStorageError, IOError) as error:
|
except (OSError, errors.CertStorageError) as error:
|
||||||
logger.error("Renewal configuration file %s is broken.", full_path)
|
logger.error("Renewal configuration file %s is broken.", full_path)
|
||||||
logger.error("The error was: %s\nSkipping.", str(error))
|
logger.error("The error was: %s\nSkipping.", str(error))
|
||||||
logger.debug("Traceback was:\n%s", traceback.format_exc())
|
logger.debug("Traceback was:\n%s", traceback.format_exc())
|
||||||
|
|||||||
@@ -115,10 +115,10 @@ class LockFileTest(test_util.TempDirTestCase):
|
|||||||
mocked_function = 'certbot._internal.lock.msvcrt.locking'
|
mocked_function = 'certbot._internal.lock.msvcrt.locking'
|
||||||
msg = 'hi there'
|
msg = 'hi there'
|
||||||
with mock.patch(mocked_function) as mock_lock:
|
with mock.patch(mocked_function) as mock_lock:
|
||||||
mock_lock.side_effect = IOError(msg)
|
mock_lock.side_effect = OSError(msg)
|
||||||
try:
|
try:
|
||||||
self._call(self.lock_path)
|
self._call(self.lock_path)
|
||||||
except IOError as err:
|
except OSError as err:
|
||||||
assert msg in str(err)
|
assert msg in str(err)
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
self.fail('IOError not raised')
|
self.fail('IOError not raised')
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class ServerManagerTest(unittest.TestCase):
|
|||||||
maybe_another_server = socket.socket()
|
maybe_another_server = socket.socket()
|
||||||
try:
|
try:
|
||||||
maybe_another_server.bind(("", port))
|
maybe_another_server.bind(("", port))
|
||||||
except socket.error:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
with pytest.raises(errors.StandaloneBindError):
|
with pytest.raises(errors.StandaloneBindError):
|
||||||
self.mgr.run(port,
|
self.mgr.run(port,
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ class AuthenticatorTest(unittest.TestCase):
|
|||||||
with open(permission_canary, "r"):
|
with open(permission_canary, "r"):
|
||||||
pass
|
pass
|
||||||
print("Warning, running tests as root skips permissions tests...")
|
print("Warning, running tests as root skips permissions tests...")
|
||||||
except IOError:
|
except OSError:
|
||||||
# ok, permissions work, test away...
|
# ok, permissions work, test away...
|
||||||
with pytest.raises(errors.PluginError):
|
with pytest.raises(errors.PluginError):
|
||||||
self.auth.perform([])
|
self.auth.perform([])
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class ReverterCheckpointLocalTest(test_util.ConfigTestCase):
|
|||||||
|
|
||||||
def test_add_to_checkpoint_copy_failure(self):
|
def test_add_to_checkpoint_copy_failure(self):
|
||||||
with mock.patch("certbot.reverter.shutil.copy2") as mock_copy2:
|
with mock.patch("certbot.reverter.shutil.copy2") as mock_copy2:
|
||||||
mock_copy2.side_effect = IOError("bad copy")
|
mock_copy2.side_effect = OSError("bad copy")
|
||||||
with pytest.raises(errors.ReverterError):
|
with pytest.raises(errors.ReverterError):
|
||||||
self.reverter.add_to_checkpoint(self.sets[0], "save1")
|
self.reverter.add_to_checkpoint(self.sets[0], "save1")
|
||||||
|
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ def verify_renewable_cert_sig(renewable_cert: interfaces.RenewableCert) -> None:
|
|||||||
assert cert.signature_hash_algorithm # always present for RSA and ECDSA
|
assert cert.signature_hash_algorithm # always present for RSA and ECDSA
|
||||||
verify_signed_payload(pk, cert.signature, cert.tbs_certificate_bytes,
|
verify_signed_payload(pk, cert.signature, cert.tbs_certificate_bytes,
|
||||||
cert.signature_hash_algorithm)
|
cert.signature_hash_algorithm)
|
||||||
except (IOError, ValueError, InvalidSignature) as e:
|
except (OSError, ValueError, InvalidSignature) as e:
|
||||||
error_str = "verifying the signature of the certificate located at {0} has failed. \
|
error_str = "verifying the signature of the certificate located at {0} has failed. \
|
||||||
Details: {1}".format(renewable_cert.cert_path, e)
|
Details: {1}".format(renewable_cert.cert_path, e)
|
||||||
logger.exception(error_str)
|
logger.exception(error_str)
|
||||||
@@ -355,7 +355,7 @@ def verify_cert_matches_priv_key(cert_path: str, key_path: str) -> None:
|
|||||||
context.use_certificate_file(cert_path)
|
context.use_certificate_file(cert_path)
|
||||||
context.use_privatekey_file(key_path)
|
context.use_privatekey_file(key_path)
|
||||||
context.check_privatekey()
|
context.check_privatekey()
|
||||||
except (IOError, SSL.Error) as e:
|
except (OSError, SSL.Error) as e:
|
||||||
error_str = "verifying the certificate located at {0} matches the \
|
error_str = "verifying the certificate located at {0} matches the \
|
||||||
private key located at {1} has failed. \
|
private key located at {1} has failed. \
|
||||||
Details: {2}".format(cert_path,
|
Details: {2}".format(cert_path,
|
||||||
@@ -383,7 +383,7 @@ def verify_fullchain(renewable_cert: interfaces.RenewableCert) -> None:
|
|||||||
error_str = "fullchain does not match cert + chain for {0}!"
|
error_str = "fullchain does not match cert + chain for {0}!"
|
||||||
error_str = error_str.format(renewable_cert.lineagename)
|
error_str = error_str.format(renewable_cert.lineagename)
|
||||||
raise errors.Error(error_str)
|
raise errors.Error(error_str)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
error_str = "reading one of cert, chain, or fullchain has failed: {0}".format(e)
|
error_str = "reading one of cert, chain, or fullchain has failed: {0}".format(e)
|
||||||
logger.exception(error_str)
|
logger.exception(error_str)
|
||||||
raise errors.Error(error_str)
|
raise errors.Error(error_str)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class PluginStorage:
|
|||||||
try:
|
try:
|
||||||
with open(self._storagepath, 'r') as fh:
|
with open(self._storagepath, 'r') as fh:
|
||||||
filedata = fh.read()
|
filedata = fh.read()
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
errmsg = "Could not read PluginStorage data file: {0} : {1}".format(
|
errmsg = "Could not read PluginStorage data file: {0} : {1}".format(
|
||||||
self._storagepath, str(e))
|
self._storagepath, str(e))
|
||||||
if os.path.isfile(self._storagepath):
|
if os.path.isfile(self._storagepath):
|
||||||
@@ -92,7 +92,7 @@ class PluginStorage:
|
|||||||
os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
|
os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
|
||||||
0o600), 'w') as fh:
|
0o600), 'w') as fh:
|
||||||
fh.write(serialized)
|
fh.write(serialized)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
errmsg = "Could not write PluginStorage data to file {0} : {1}".format(
|
errmsg = "Could not write PluginStorage data to file {0} : {1}".format(
|
||||||
self._storagepath, str(e))
|
self._storagepath, str(e))
|
||||||
logger.error(errmsg)
|
logger.error(errmsg)
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ class Reverter:
|
|||||||
cp_dir, os.path.basename(filename) + "_" + str(idx)))
|
cp_dir, os.path.basename(filename) + "_" + str(idx)))
|
||||||
op_fd.write('{0}\n'.format(filename))
|
op_fd.write('{0}\n'.format(filename))
|
||||||
# https://stackoverflow.com/questions/4726260/effective-use-of-python-shutil-copy2
|
# https://stackoverflow.com/questions/4726260/effective-use-of-python-shutil-copy2
|
||||||
except IOError:
|
except OSError:
|
||||||
op_fd.close()
|
op_fd.close()
|
||||||
logger.error(
|
logger.error(
|
||||||
"Unable to add file %s to checkpoint %s",
|
"Unable to add file %s to checkpoint %s",
|
||||||
@@ -238,7 +238,7 @@ class Reverter:
|
|||||||
shutil.copy2(os.path.join(
|
shutil.copy2(os.path.join(
|
||||||
cp_dir,
|
cp_dir,
|
||||||
os.path.basename(path) + "_" + str(idx)), path)
|
os.path.basename(path) + "_" + str(idx)), path)
|
||||||
except (IOError, OSError):
|
except OSError:
|
||||||
# This file is required in all checkpoints.
|
# This file is required in all checkpoints.
|
||||||
logger.error("Unable to recover files from %s", cp_dir)
|
logger.error("Unable to recover files from %s", cp_dir)
|
||||||
raise errors.ReverterError(f"Unable to recover files from {cp_dir}")
|
raise errors.ReverterError(f"Unable to recover files from {cp_dir}")
|
||||||
@@ -327,7 +327,7 @@ class Reverter:
|
|||||||
for path in files:
|
for path in files:
|
||||||
if path not in ex_files:
|
if path not in ex_files:
|
||||||
new_fd.write("{0}\n".format(path))
|
new_fd.write("{0}\n".format(path))
|
||||||
except (IOError, OSError):
|
except OSError:
|
||||||
logger.error("Unable to register file creation(s) - %s", files)
|
logger.error("Unable to register file creation(s) - %s", files)
|
||||||
raise errors.ReverterError(
|
raise errors.ReverterError(
|
||||||
"Unable to register file creation(s) - {0}".format(files))
|
"Unable to register file creation(s) - {0}".format(files))
|
||||||
@@ -360,7 +360,7 @@ class Reverter:
|
|||||||
with open(commands_fp, mode, **kwargs) as f: # type: ignore
|
with open(commands_fp, mode, **kwargs) as f: # type: ignore
|
||||||
csvwriter = csv.writer(f)
|
csvwriter = csv.writer(f)
|
||||||
csvwriter.writerow(command)
|
csvwriter.writerow(command)
|
||||||
except (IOError, OSError):
|
except OSError:
|
||||||
logger.error("Unable to register undo command")
|
logger.error("Unable to register undo command")
|
||||||
raise errors.ReverterError(
|
raise errors.ReverterError(
|
||||||
"Unable to register undo command.")
|
"Unable to register undo command.")
|
||||||
@@ -434,7 +434,7 @@ class Reverter:
|
|||||||
"File: %s - Could not be found to be deleted\n"
|
"File: %s - Could not be found to be deleted\n"
|
||||||
" - Certbot probably shut down unexpectedly",
|
" - Certbot probably shut down unexpectedly",
|
||||||
path)
|
path)
|
||||||
except (IOError, OSError):
|
except OSError:
|
||||||
logger.critical(
|
logger.critical(
|
||||||
"Unable to remove filepaths contained within %s", file_list)
|
"Unable to remove filepaths contained within %s", file_list)
|
||||||
raise errors.ReverterError(
|
raise errors.ReverterError(
|
||||||
@@ -476,7 +476,7 @@ class Reverter:
|
|||||||
|
|
||||||
# Move self.config.in_progress_dir to Backups directory
|
# Move self.config.in_progress_dir to Backups directory
|
||||||
shutil.move(changes_since_tmp_path, changes_since_path)
|
shutil.move(changes_since_tmp_path, changes_since_path)
|
||||||
except (IOError, OSError):
|
except OSError:
|
||||||
logger.error("Unable to finalize checkpoint - adding title")
|
logger.error("Unable to finalize checkpoint - adding title")
|
||||||
logger.debug("Exception was:\n%s", traceback.format_exc())
|
logger.debug("Exception was:\n%s", traceback.format_exc())
|
||||||
raise errors.ReverterError("Unable to add title")
|
raise errors.ReverterError("Unable to add title")
|
||||||
|
|||||||
@@ -665,12 +665,12 @@ def is_ipaddress(address: str) -> bool:
|
|||||||
socket.inet_pton(socket.AF_INET, address)
|
socket.inet_pton(socket.AF_INET, address)
|
||||||
# If this line runs it was ip address (ipv4)
|
# If this line runs it was ip address (ipv4)
|
||||||
return True
|
return True
|
||||||
except socket.error:
|
except OSError:
|
||||||
# It wasn't an IPv4 address, so try ipv6
|
# It wasn't an IPv4 address, so try ipv6
|
||||||
try:
|
try:
|
||||||
socket.inet_pton(socket.AF_INET6, address)
|
socket.inet_pton(socket.AF_INET6, address)
|
||||||
return True
|
return True
|
||||||
except socket.error:
|
except OSError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ def block_until_ssh_open(ipstring, wait_time=10, timeout=120):
|
|||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect((ipstring, 22))
|
sock.connect((ipstring, 22))
|
||||||
reached = True
|
reached = True
|
||||||
except socket.error as err:
|
except OSError as err:
|
||||||
time.sleep(wait_time)
|
time.sleep(wait_time)
|
||||||
t_elapsed += wait_time
|
t_elapsed += wait_time
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user