From 9c28364477eda6841a4d8881922ef320250f6c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roy=20Wellington=20=E2=85=A3?= Date: Sat, 30 Jan 2016 19:53:50 -0800 Subject: [PATCH 1/2] Make exception syntax Python 3 compatible. Translate all except and raise statements that are in the old form to the Python 3 compatible format. --- .../letsencrypt_apache/display_ops.py | 4 ++-- .../letsencrypt_apache/tests/display_ops_test.py | 2 +- letsencrypt/cli.py | 8 ++++---- letsencrypt/client.py | 2 +- letsencrypt/display/ops.py | 13 +++++++------ letsencrypt/display/util.py | 2 +- letsencrypt/tests/cli_test.py | 2 +- tests/letstest/multitester.py | 2 +- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/letsencrypt-apache/letsencrypt_apache/display_ops.py b/letsencrypt-apache/letsencrypt_apache/display_ops.py index ef09ef6b4..6a2308d73 100644 --- a/letsencrypt-apache/letsencrypt_apache/display_ops.py +++ b/letsencrypt-apache/letsencrypt_apache/display_ops.py @@ -85,12 +85,12 @@ def _vhost_menu(domain, vhosts): "or Address of {0}.{1}Which virtual host would you " "like to choose?".format(domain, os.linesep), choices, help_label="More Info", ok_label="Select") - except errors.MissingCommandlineFlag, e: + except errors.MissingCommandlineFlag as e: msg = ("Failed to run Apache plugin non-interactively{1}{0}{1}" "(The best solution is to add ServerName or ServerAlias " "entries to the VirtualHost directives of your apache " "configuration files.)".format(e, os.linesep)) - raise errors.MissingCommandlineFlag, msg + raise errors.MissingCommandlineFlag(msg) return code, tag diff --git a/letsencrypt-apache/letsencrypt_apache/tests/display_ops_test.py b/letsencrypt-apache/letsencrypt_apache/tests/display_ops_test.py index 590144372..f7fbac947 100644 --- a/letsencrypt-apache/letsencrypt_apache/tests/display_ops_test.py +++ b/letsencrypt-apache/letsencrypt_apache/tests/display_ops_test.py @@ -37,7 +37,7 @@ class SelectVhostTest(unittest.TestCase): mock_util().menu.side_effect = errors.MissingCommandlineFlag("no vhost default") try: self._call(self.vhosts) - except errors.MissingCommandlineFlag, e: + except errors.MissingCommandlineFlag as e: self.assertTrue("VirtualHost directives" in e.message) @mock.patch("letsencrypt_apache.display_ops.zope.component.getUtility") diff --git a/letsencrypt/cli.py b/letsencrypt/cli.py index dc095a42e..2da82412d 100644 --- a/letsencrypt/cli.py +++ b/letsencrypt/cli.py @@ -543,7 +543,7 @@ def choose_configurator_plugins(args, config, plugins, verb): '{1} and "--help plugins" for more information.)'.format( req_auth, os.linesep, cli_command)) - raise errors.MissingCommandlineFlag, msg + raise errors.MissingCommandlineFlag(msg) else: need_inst = need_auth = False if verb == "certonly": @@ -591,7 +591,7 @@ def run(args, config, plugins): # pylint: disable=too-many-branches,too-many-lo """Obtain a certificate and install.""" try: installer, authenticator = choose_configurator_plugins(args, config, plugins, "run") - except errors.PluginSelectionError, e: + except errors.PluginSelectionError as e: return e.message domains = _find_domains(config, installer) @@ -626,7 +626,7 @@ def obtain_cert(args, config, plugins): try: # installers are used in auth mode to determine domain names installer, authenticator = choose_configurator_plugins(args, config, plugins, "certonly") - except errors.PluginSelectionError, e: + except errors.PluginSelectionError as e: return e.message # TODO: Handle errors from _init_le_client? @@ -655,7 +655,7 @@ def install(args, config, plugins): try: installer, _ = choose_configurator_plugins(args, config, plugins, "install") - except errors.PluginSelectionError, e: + except errors.PluginSelectionError as e: return e.message domains = _find_domains(config, installer) diff --git a/letsencrypt/client.py b/letsencrypt/client.py index c2dfca1bf..1ef7954e8 100644 --- a/letsencrypt/client.py +++ b/letsencrypt/client.py @@ -146,7 +146,7 @@ def perform_registration(acme, config): """ try: return acme.register(messages.NewRegistration.from_data(email=config.email)) - except messages.Error, e: + except messages.Error as e: err = repr(e) if "MX record" in err or "Validation of contact mailto" in err: config.namespace.email = display_ops.get_email(more=True, invalid=True) diff --git a/letsencrypt/display/ops.py b/letsencrypt/display/ops.py index 59e116c75..c9b5c9fa1 100644 --- a/letsencrypt/display/ops.py +++ b/letsencrypt/display/ops.py @@ -78,11 +78,12 @@ def pick_plugin(config, default, plugins, question, ifaces): # it's really bad to auto-select the single available plugin in # non-interactive mode, because an update could later add a second # available plugin - raise errors.MissingCommandlineFlag, ("Missing command line flags. For non-interactive " - "execution, you will need to specify a plugin on the command line. Run with " - "'--help plugins' to see a list of options, and see " - " https://eff.org/letsencrypt-plugins for more detail on what the plugins " - "do and how to use them.") + raise errors.MissingCommandlineFlag( + "Missing command line flags. For non-interactive execution, " + "you will need to specify a plugin on the command line. Run " + "with '--help plugins' to see a list of options, and see " + " https://eff.org/letsencrypt-plugins for more detail on what " + "the plugins do and how to use them.") filtered = plugins.visible().ifaces(ifaces) @@ -158,7 +159,7 @@ def get_email(more=False, invalid=False): except errors.MissingCommandlineFlag: msg = ("You should register before running non-interactively, or provide --agree-tos" " and --email flags") - raise errors.MissingCommandlineFlag, msg + raise errors.MissingCommandlineFlag(msg) if code == display_util.OK: if le_util.safe_email(email): diff --git a/letsencrypt/display/util.py b/letsencrypt/display/util.py index 12c32ff05..93b8f6d91 100644 --- a/letsencrypt/display/util.py +++ b/letsencrypt/display/util.py @@ -428,7 +428,7 @@ class NoninteractiveDisplay(object): msg += "\n" + extra if cli_flag: msg += "\n\n(You can set this with the {0} flag)".format(cli_flag) - raise errors.MissingCommandlineFlag, msg + raise errors.MissingCommandlineFlag(msg) def notification(self, message, height=10, pause=False): # pylint: disable=unused-argument diff --git a/letsencrypt/tests/cli_test.py b/letsencrypt/tests/cli_test.py index f316fe2e8..43127dc8a 100644 --- a/letsencrypt/tests/cli_test.py +++ b/letsencrypt/tests/cli_test.py @@ -138,7 +138,7 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods try: with mock.patch('letsencrypt.cli.sys.stderr'): cli.main(self.standard_args + args[:]) # NOTE: parser can alter its args! - except errors.MissingCommandlineFlag, exc: + except errors.MissingCommandlineFlag as exc: self.assertTrue(message in str(exc)) self.assertTrue(exc is not None) diff --git a/tests/letstest/multitester.py b/tests/letstest/multitester.py index 19a6aad1a..378670071 100644 --- a/tests/letstest/multitester.py +++ b/tests/letstest/multitester.py @@ -141,7 +141,7 @@ def make_instance(instance_name, # give instance a name try: new_instance.create_tags(Tags=[{'Key': 'Name', 'Value': instance_name}]) - except botocore.exceptions.ClientError, e: + except botocore.exceptions.ClientError as e: if "InvalidInstanceID.NotFound" in str(e): # This seems to be ephemeral... retry time.sleep(1) From 44585f3c4de7ae2c6f0c7f1fc4db79ca6c6a8e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roy=20Wellington=20=E2=85=A3?= Date: Sat, 30 Jan 2016 19:55:16 -0800 Subject: [PATCH 2/2] Remove a double space before this URL. --- letsencrypt/display/ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/letsencrypt/display/ops.py b/letsencrypt/display/ops.py index c9b5c9fa1..b3c057301 100644 --- a/letsencrypt/display/ops.py +++ b/letsencrypt/display/ops.py @@ -82,7 +82,7 @@ def pick_plugin(config, default, plugins, question, ifaces): "Missing command line flags. For non-interactive execution, " "you will need to specify a plugin on the command line. Run " "with '--help plugins' to see a list of options, and see " - " https://eff.org/letsencrypt-plugins for more detail on what " + "https://eff.org/letsencrypt-plugins for more detail on what " "the plugins do and how to use them.") filtered = plugins.visible().ifaces(ifaces)