Skip to content

Commit

Permalink
Merge pull request certbot#2513 from thanatos/py3k-minor-fixes
Browse files Browse the repository at this point in the history
Py3k minor fixes
  • Loading branch information
pde committed Mar 2, 2016
2 parents 1c46ff4 + 8046cdc commit ebf0163
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 28 deletions.
11 changes: 6 additions & 5 deletions letsencrypt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import configargparse
import OpenSSL
import six
import zope.component
import zope.interface.exceptions
import zope.interface.verify
Expand Down Expand Up @@ -842,7 +843,7 @@ def _restore_plugin_configs(config, renewalparams):
if renewalparams.get("installer", None) is not None:
plugin_prefixes.append(renewalparams["installer"])
for plugin_prefix in set(plugin_prefixes):
for config_item, config_value in renewalparams.iteritems():
for config_item, config_value in six.iteritems(renewalparams):
if config_item.startswith(plugin_prefix + "_") and not _set_by_cli(config_item):
# Values None, True, and False need to be treated specially,
# As they don't get parsed correctly based on type
Expand Down Expand Up @@ -1159,10 +1160,10 @@ class HelpfulArgumentParser(object):

# List of topics for which additional help can be provided
HELP_TOPICS = ["all", "security",
"paths", "automation", "testing"] + VERBS.keys()
"paths", "automation", "testing"] + list(six.iterkeys(VERBS))

def __init__(self, args, plugins, detect_defaults=False):
plugin_names = [name for name, _p in plugins.iteritems()]
plugin_names = list(six.iterkeys(plugins))
self.help_topics = self.HELP_TOPICS + plugin_names + [None]
usage, short_usage = usage_strings(plugins)
self.parser = configargparse.ArgParser(
Expand Down Expand Up @@ -1432,7 +1433,7 @@ def add_plugin_args(self, plugins):
may or may not be displayed as help topics.
"""
for name, plugin_ep in plugins.iteritems():
for name, plugin_ep in six.iteritems(plugins):
parser_or_group = self.add_group(name, description=plugin_ep.description)
#print(parser_or_group)
plugin_ep.plugin_cls.inject_parser_options(parser_or_group, name)
Expand Down Expand Up @@ -1827,7 +1828,7 @@ def _process_domain(args_or_config, domain_arg, webroot_path=None):
class WebrootMapProcessor(argparse.Action): # pylint: disable=missing-docstring
def __call__(self, parser, args, webroot_map_arg, option_string=None):
webroot_map = json.loads(webroot_map_arg)
for domains, webroot_path in webroot_map.iteritems():
for domains, webroot_path in six.iteritems(webroot_map):
_process_domain(args, domains, [webroot_path])


Expand Down
5 changes: 4 additions & 1 deletion letsencrypt/plugins/webroot_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Tests for letsencrypt.plugins.webroot."""

from __future__ import print_function

import errno
import os
import shutil
Expand Down Expand Up @@ -74,7 +77,7 @@ def test_prepare_reraises_other_errors(self):
os.chmod(self.path, 0o000)
try:
open(permission_canary, "r")
print "Warning, running tests as root skips permissions tests..."
print("Warning, running tests as root skips permissions tests...")
except IOError:
# ok, permissions work, test away...
self.assertRaises(errors.PluginError, self.auth.prepare)
Expand Down
6 changes: 3 additions & 3 deletions letsencrypt/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import collections
import logging
import os
import Queue
import sys
import textwrap

from six.moves import queue # pylint: disable=import-error
import zope.interface

from letsencrypt import interfaces
Expand All @@ -21,7 +21,7 @@
class Reporter(object):
"""Collects and displays information to the user.
:ivar `Queue.PriorityQueue` messages: Messages to be displayed to
:ivar `queue.PriorityQueue` messages: Messages to be displayed to
the user.
"""
Expand All @@ -36,7 +36,7 @@ class Reporter(object):
_msg_type = collections.namedtuple('ReporterMsg', 'priority text on_crash')

def __init__(self):
self.messages = Queue.PriorityQueue()
self.messages = queue.PriorityQueue()

def add_message(self, msg, priority, on_crash=True):
"""Adds msg to the list of messages to be printed.
Expand Down
2 changes: 1 addition & 1 deletion letsencrypt/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def new_lineage(cls, lineagename, cert, privkey, chain, cli_config):
for i in (cli_config.renewal_configs_dir, cli_config.archive_dir,
cli_config.live_dir):
if not os.path.exists(i):
os.makedirs(i, 0700)
os.makedirs(i, 0o700)
logger.debug("Creating directory %s.", i)
config_file, config_filename = le_util.unique_lineage_name(
cli_config.renewal_configs_dir, lineagename)
Expand Down
13 changes: 8 additions & 5 deletions letsencrypt/tests/cli_test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"""Tests for letsencrypt.cli."""

from __future__ import print_function

import argparse
import functools
import itertools
import os
import shutil
import StringIO
import traceback
import tempfile
import unittest

import mock
import six

from acme import jose

Expand Down Expand Up @@ -81,7 +84,7 @@ def test_no_flags(self):

def _help_output(self, args):
"Run a command, and return the ouput string for scrutiny"
output = StringIO.StringIO()
output = six.StringIO()
with mock.patch('letsencrypt.cli.sys.stdout', new=output):
self.assertRaises(SystemExit, self._call_stdout, args)
out = output.getvalue()
Expand Down Expand Up @@ -580,7 +583,7 @@ def _test_renewal_common(self, due_for_renewal, extra_args, log_out=None,
try:
ret, _, _, _ = self._call(args)
if ret:
print "Returned", ret
print("Returned", ret)
raise AssertionError(ret)
assert not error_expected, "renewal should have errored"
except: # pylint: disable=bare-except
Expand Down Expand Up @@ -628,8 +631,8 @@ def test_certonly_renewal_triggers(self):

def _dump_log(self):
with open(os.path.join(self.logs_dir, "letsencrypt.log")) as lf:
print "Logs:"
print lf.read()
print("Logs:")
print(lf.read())


def _make_test_renewal_conf(self, testfile):
Expand Down
5 changes: 3 additions & 2 deletions letsencrypt/tests/colored_logging_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Tests for letsencrypt.colored_logging."""
import logging
import StringIO
import unittest

import six

from letsencrypt import le_util


Expand All @@ -12,7 +13,7 @@ class StreamHandlerTest(unittest.TestCase):
def setUp(self):
from letsencrypt import colored_logging

self.stream = StringIO.StringIO()
self.stream = six.StringIO()
self.stream.isatty = lambda: True
self.handler = colored_logging.StreamHandler(self.stream)

Expand Down
6 changes: 3 additions & 3 deletions letsencrypt/tests/le_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import os
import shutil
import stat
import StringIO
import tempfile
import unittest

import mock
import six

from letsencrypt import errors

Expand Down Expand Up @@ -307,14 +307,14 @@ def test_warning_with_arg(self):
self.assertTrue("--old-option is deprecated" in stderr)

def _get_argparse_warnings(self, args):
stderr = StringIO.StringIO()
stderr = six.StringIO()
with mock.patch("letsencrypt.le_util.sys.stderr", new=stderr):
self.parser.parse_args(args)
return stderr.getvalue()

def test_help(self):
self._call("--old-option", 2)
stdout = StringIO.StringIO()
stdout = six.StringIO()
with mock.patch("letsencrypt.le_util.sys.stdout", new=stdout):
try:
self.parser.parse_args(["-h"])
Expand Down
5 changes: 3 additions & 2 deletions letsencrypt/tests/reporter_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Tests for letsencrypt.reporter."""
import StringIO
import sys
import unittest

import six


class ReporterTest(unittest.TestCase):
"""Tests for letsencrypt.reporter.Reporter."""
Expand All @@ -12,7 +13,7 @@ def setUp(self):
self.reporter = reporter.Reporter()

self.old_stdout = sys.stdout
sys.stdout = StringIO.StringIO()
sys.stdout = six.StringIO()

def tearDown(self):
sys.stdout = self.old_stdout
Expand Down
15 changes: 9 additions & 6 deletions letshelp-letsencrypt/letshelp_letsencrypt/apache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env python
"""Let's Encrypt Apache configuration submission script"""

from __future__ import print_function

import argparse
import atexit
import contextlib
Expand Down Expand Up @@ -48,20 +51,20 @@ def make_and_verify_selection(server_root, temp_dir):
"""
copied_files, copied_dirs = copy_config(server_root, temp_dir)

print textwrap.fill("A secure copy of the files that have been selected "
print(textwrap.fill("A secure copy of the files that have been selected "
"for submission has been created under {0}. All "
"comments have been removed and the files are only "
"accessible by the current user. A list of the files "
"that have been included is shown below. Please make "
"sure that this selection does not contain private "
"keys, passwords, or any other sensitive "
"information.".format(temp_dir))
print "\nFiles:"
"information.".format(temp_dir)))
print("\nFiles:")
for copied_file in copied_files:
print copied_file
print "Directories (including all contained files):"
print(copied_file)
print("Directories (including all contained files):")
for copied_dir in copied_dirs:
print copied_dir
print(copied_dir)

sys.stdout.write("\nIs it safe to submit these files? ")
while True:
Expand Down

0 comments on commit ebf0163

Please sign in to comment.