From fa023eb2d66291e05703bdefa960ab0ad440d5a9 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 19 May 2014 07:21:03 -0700 Subject: [PATCH] Changed several files to be Python3 friendly The print syntax has been changed to be Python3 compatible. Change-Id: Id3fcbab390f08dcb3380cfda16d7b820b03ef683 --- swift/common/middleware/tempauth.py | 4 +++- swift/common/utils.py | 18 +++++++++++------- swift/common/wsgi.py | 4 +++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/swift/common/middleware/tempauth.py b/swift/common/middleware/tempauth.py index 4f756247b9..bf632e7a84 100644 --- a/swift/common/middleware/tempauth.py +++ b/swift/common/middleware/tempauth.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function + from time import time from traceback import format_exc from urllib import unquote @@ -484,7 +486,7 @@ class TempAuth(object): req.headers['x-auth-token'] = req.headers['x-storage-token'] return self.handle_request(req)(env, start_response) except (Exception, Timeout): - print "EXCEPTION IN handle: %s: %s" % (format_exc(), env) + print("EXCEPTION IN handle: %s: %s" % (format_exc(), env)) self.logger.increment('errors') start_response('500 Server Error', [('Content-Type', 'text/plain')]) diff --git a/swift/common/utils.py b/swift/common/utils.py index 58b4228505..b1f402ac99 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -15,6 +15,8 @@ """Miscellaneous utility functions for use with Swift.""" +from __future__ import print_function + import errno import fcntl import grp @@ -1200,9 +1202,11 @@ def get_logger(conf, name=None, log_to_console=False, log_route=None, logger_hook(conf, name, log_to_console, log_route, fmt, logger, adapted_logger) except (AttributeError, ImportError): - print >>sys.stderr, 'Error calling custom handler [%s]' % hook + print( + 'Error calling custom handler [%s]' % hook, + file=sys.stderr) except ValueError: - print >>sys.stderr, 'Invalid custom handler format [%s]' % hook + print('Invalid custom handler format [%s]' % hook, sys.stderr) # Python 2.6 has the undesirable property of keeping references to all log # handlers around forever in logging._handlers and logging._handlerList. @@ -1341,12 +1345,12 @@ def parse_options(parser=None, once=False, test_args=None): if not args: parser.print_usage() - print _("Error: missing config path argument") + print(_("Error: missing config path argument")) sys.exit(1) config = os.path.abspath(args.pop(0)) if not os.path.exists(config): parser.print_usage() - print _("Error: unable to locate %s") % config + print(_("Error: unable to locate %s") % config) sys.exit(1) extra_args = [] @@ -1628,14 +1632,14 @@ def readconf(conf_path, section_name=None, log_name=None, defaults=None, else: success = c.read(conf_path) if not success: - print _("Unable to read config from %s") % conf_path + print(_("Unable to read config from %s") % conf_path) sys.exit(1) if section_name: if c.has_section(section_name): conf = dict(c.items(section_name)) else: - print _("Unable to find %s config section in %s") % \ - (section_name, conf_path) + print(_("Unable to find %s config section in %s") % + (section_name, conf_path)) sys.exit(1) if "log_name" not in conf: if log_name is not None: diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 3d775fd47a..7ba131f287 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -15,6 +15,8 @@ """WSGI tools for use with swift.""" +from __future__ import print_function + import errno import os import signal @@ -359,7 +361,7 @@ def run_wsgi(conf_path, app_section, *args, **kwargs): (conf, logger, log_name) = \ _initrp(conf_path, app_section, *args, **kwargs) except ConfigFileError as e: - print e + print(e) return 1 # bind to address and port