Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requestbuilder/auth/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def get_canonicalized_resource(self, req, service):
if val is None:
subresources.append(key)
else:
print '{0}={1}'.format(key, val), key + '=' + val
print('{0}={1}'.format(key, val), key + '=' + val)
subresources.append(key + '=' + val)
if subresources:
resource += '?' + '&'.join(subresources)
Expand Down
21 changes: 12 additions & 9 deletions requestbuilder/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

from __future__ import absolute_import
from __future__ import absolute_import, print_function

import argparse
import bdb
Expand All @@ -36,6 +36,9 @@
from requestbuilder.util import add_default_routes, aggregate_subclass_fields


import six
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per PEP 8, third party library imports come between standard library imports and local imports.



class BaseCommand(object):
'''
The basis for a command line tool. To invoke this as a command line tool,
Expand Down Expand Up @@ -250,7 +253,7 @@ def process_cli_args(self):
self.log.debug('parsed arguments: ' + str(cli_args))

def distribute_args(self):
for key, val in self.args.iteritems():
for key, val in six.iteritems(self.args):
# If a location to route this to was supplied, put it there, too.
if key not in self._arg_routes:
raise TypeError('got unrecognized arg: "{0}"'.format(key))
Expand Down Expand Up @@ -286,12 +289,12 @@ def run(cls):
if getattr(err, 'filename', None):
err_bits[-1] += ':'
err_bits.append(err.filename)
print >> sys.stderr, ' '.join(err_bits)
print(' '.join(err_bits), file=sys.stderr)
else:
if len(err.args) > 0 and err.args[0]:
print >> sys.stderr, msg_prefix, err.args[0]
print(msg_prefix, err.args[0], file=sys.stderr)
else:
print >> sys.stderr, msg_prefix, str(err)
print(msg_prefix, str(err), file=sys.stderr)
# Since we don't even have a config file to consult our options for
# determining when debugging is on are limited to what we got at
# the command line.
Expand Down Expand Up @@ -347,12 +350,12 @@ def handle_cli_exception(self, err):
if getattr(err, 'filename', None):
err_bits[-1] += ':'
err_bits.append(err.filename)
print >> sys.stderr, ' '.join(err_bits)
print(' '.join(err_bits), file=sys.stderr)
else:
if len(err.args) > 0 and err.args[0]:
print >> sys.stderr, msg_prefix, err.args[0]
print(msg_prefix, err.args[0], file=sys.stderr)
else:
print >> sys.stderr, msg_prefix, str(err)
print(msg_prefix, str(err), file=sys.stderr)
if self.debug:
raise
sys.exit(1)
Expand Down Expand Up @@ -394,4 +397,4 @@ def _debugger_usr1_handler(_, frame):
frame_dict = {'_frame': frame}
frame_dict.update(frame.f_globals)
frame_dict.update(frame.f_locals)
print >> sys.stderr, ''.join(traceback.format_stack(frame))
print(''.join(traceback.format_stack(frame)), file=sys.stderr)
9 changes: 6 additions & 3 deletions requestbuilder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@

from __future__ import absolute_import

import ConfigParser
import itertools
import logging


import six
from six.moves import configparser


class ConfigView(object):
def __init__(self, data, region=None, user=None):
self.log = data.log
Expand Down Expand Up @@ -87,7 +90,7 @@ def get_all_user_options(self, option):
@staticmethod
def __get_all_options(confdict, option):
matches = {}
for section, options in confdict.iteritems():
for section, options in six.iteritems(confdict):
if '*' not in section and option in options:
matches[section] = options[option]
return matches
Expand Down Expand Up @@ -115,7 +118,7 @@ def __init__(self, filenames):
self._parse_config(filenames)

def _parse_config(self, filenames):
parser = ConfigParser.SafeConfigParser()
parser = configparser.SafeConfigParser()
parser.read(filenames)
for section in parser.sections():
if section == 'global':
Expand Down
11 changes: 7 additions & 4 deletions requestbuilder/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

from __future__ import absolute_import
from __future__ import absolute_import, print_function

import argparse
import copy
Expand All @@ -31,6 +31,9 @@
from requestbuilder.xmlparse import parse_listdelimited_aws_xml


import six


class BaseRequest(BaseCommand):
'''
The basis for a command line tool that represents a request. The data for
Expand Down Expand Up @@ -218,7 +221,7 @@ def handle_cli_exception(self, err):
if isinstance(err, ServerError):
msg = '{0}: {1}'.format(os.path.basename(sys.argv[0]),
err.format_for_cli())
print >> sys.stderr, msg
print(msg, file=sys.stderr)
if self.debug:
raise
sys.exit(1)
Expand Down Expand Up @@ -325,7 +328,7 @@ def flatten_params(self, args, prefix=None):
if args is None:
pass
elif isinstance(args, dict):
for (key, val) in args.iteritems():
for (key, val) in six.iteritems(args):
# Prefix.Key1, Prefix.Key2, ...
if prefix:
prefixed_key = '{0}.{1}'.format(prefix, key)
Expand Down Expand Up @@ -436,7 +439,7 @@ def _process_filters(cli_filters):
filter_args[key].append(val)
# Build the flattenable [{'Name': key, 'Value': [value, ...]}, ...]
filters = [{'Name': name, 'Value': values} for (name, values)
in filter_args.iteritems()]
in six.iteritems(filter_args)]
return filters


Expand Down
6 changes: 3 additions & 3 deletions requestbuilder/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def configure(self):
def session(self):
if self._session is None:
self._session = requests.session()
for key, val in self.session_args.iteritems():
for key, val in six.iteritems(self.session_args):
setattr(self._session, key, val)
for adapter in self._session.adapters.values():
# send_request handles retries to allow for re-signing
Expand Down Expand Up @@ -280,7 +280,7 @@ def __log_and_prepare_request(self, method, url, params, data, files,
self.log.debug('request method: %s', request.method)
self.log.debug('request url: %s', p_request.url)
if isinstance(p_request.headers, (dict, collections.Mapping)):
for key, val in sorted(p_request.headers.iteritems()):
for key, val in sorted(six.iteritems(p_request.headers)):
if key.lower().endswith('password'):
val = '<redacted>'
self.log.debug('request header: %s: %s', key, val)
Expand Down Expand Up @@ -313,7 +313,7 @@ def __log_and_prepare_request(self, method, url, params, data, files,
val = '<redacted>'
self.log.debug('request data: %s: %s', key, val)
if isinstance(request.files, (dict, collections.Mapping)):
for key, val in sorted(request.files.iteritems()):
for key, val in sorted(six.iteritems(request.files)):
if hasattr(val, '__len__'):
val = '<{0} bytes>'.format(len(val))
self.log.debug('request file: %s: %s', key, val)
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def make_release_tree(self, base_dir, files):
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Internet'],
cmdclass={'build_py': build_py_with_git_version,
'sdist': sdist_with_git_version})