Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/python3 #39

Merged
merged 14 commits into from
Jul 2, 2019
2 changes: 1 addition & 1 deletion cdispyutils/auth/jwt_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_public_key_for_kid(kid, attempt_refresh=True):
raise JWTValidationError('no key exists with this key id')
else:
# Grab the key from the first in the list of keys.
return flask.current_app.jwt_public_keys.items()[0][1]
return list(flask.current_app.jwt_public_keys.items())[0][1]
Copy link
Contributor

Choose a reason for hiding this comment

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

How about:

next(iter(flask.current_app.jwt_public_keys.values()))



def validate_request_jwt(
Expand Down
8 changes: 4 additions & 4 deletions cdispyutils/hmac4/hmac4_auth_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
try:
from urllib.parse import urlparse, parse_qs, quote, unquote, quote_plus
except ImportError:
from urlparse import urlparse, parse_qs
from urllib import quote, unquote, quote_plus
Copy link
Contributor

Choose a reason for hiding this comment

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

This was Python 3 compatible, 2to3 is not smart enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, right, i will just remove the try except since we don't need to support python 2 anymore

from urllib.parse import urlparse, parse_qs
from urllib.parse import quote, unquote, quote_plus

def set_req_date(req, req_date):
if constants.REQUEST_DATE_HEADER in req.headers:
Expand Down Expand Up @@ -110,10 +110,10 @@ def generate_presigned_url(url, method, access_key, signing_key, request_date, e
querystring[constants.AWS_SIGNED_HEADERS_KEY] = 'host'

canonical_qs = ''
for key in sorted(querystring.iterkeys()):
for key in sorted(querystring.keys()):
canonical_qs += '&' + key + '=' + querystring[key]
canonical_qs = canonical_qs[1:]
for key in sorted(additional_signed_qs.iterkeys()):
for key in sorted(additional_signed_qs.keys()):
canonical_qs += '&' + key + '=' + quote_plus(additional_signed_qs[key])

url_parts = url.split('://')
Expand Down
16 changes: 8 additions & 8 deletions cdispyutils/hmac4/hmac4_auth_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
try:
from urllib.parse import urlparse, parse_qs, quote, unquote
except ImportError:
from urlparse import urlparse, parse_qs
from urllib import quote, unquote
from urllib.parse import urlparse, parse_qs
from urllib.parse import quote, unquote


DEFAULT_INCLUDE_HEADERS = [
Expand Down Expand Up @@ -119,7 +119,7 @@ def normalize_date_format(date_str):
}

out_date = None
for regex, xform in formats.items():
for regex, xform in list(formats.items()):
m = re.search(regex, date_str)
if m:
out_date = xform(m)
Expand Down Expand Up @@ -224,7 +224,7 @@ def get_canonical_headers(req, include=None):
# Requests, since it uses a case-insensitive dict to hold headers, this
# is here just in case you duck type with a regular dict
cano_headers_dict = {}
for hdr, val in headers.items():
for hdr, val in list(headers.items()):
Copy link
Contributor

Choose a reason for hiding this comment

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

useless list()

hdr = hdr.strip().lower()
val = normalize_whitespace(val).strip()
if (hdr in include or '*' in include or
Expand Down Expand Up @@ -280,7 +280,7 @@ def format_cano_path(path):
qm = b'?' if PY2 else '?'
full_path = qm.join((full_path, qs))
if PY2:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need these if PY2?

full_path = unicode(full_path)
full_path = str(full_path)
return full_path


Expand All @@ -306,17 +306,17 @@ def format_cano_querystring(qs):
qs = qs.split(space)[0]
qs = quote(qs, safe=safe_qs_amz_chars)
qs_items = {}
for name, vals in parse_qs(qs, keep_blank_values=True).items():
for name, vals in list(parse_qs(qs, keep_blank_values=True).items()):
name = quote(name, safe=safe_qs_unresvd)
vals = [quote(val, safe=safe_qs_unresvd) for val in vals]
qs_items[name] = vals
qs_strings = []
for name, vals in qs_items.items():
for name, vals in list(qs_items.items()):
for val in vals:
qs_strings.append('='.join([name, val]))
qs = '&'.join(sorted(qs_strings))
if PY2:
qs = unicode(qs)
qs = str(qs)
return qs


Expand Down
2 changes: 1 addition & 1 deletion cdispyutils/hmac4/hmac4_signing_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# http://opensource.org/licenses/MIT


from __future__ import unicode_literals


import hmac
import hashlib
Expand Down
16 changes: 8 additions & 8 deletions cdispyutils/profiling/vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load_file(filepath):
here = reduce(lambda acc, p: acc.get(p, {}), split[:-1], self.stats)
# add entry to the stats dictionary
here[split[-1]] = {f: load_file(os.path.join(path, f)) for f in files}
here[split[-1]] = {f: stat for f, stat in here[split[-1]].iteritems() if stat}
here[split[-1]] = {f: stat for f, stat in here[split[-1]].items() if stat}

if corrupted:
msg = (
Expand Down Expand Up @@ -95,25 +95,25 @@ def make_all_plots(self, save_file="profile_graphs.pdf"):
points are the run name as the x and the result time as the y.
"""
results = {}
for run, categories in self.stats.stats.iteritems():
for category, files in categories.iteritems():
for run, categories in self.stats.stats.items():
for category, files in categories.items():
if category not in results:
results[category] = {}
aggregator = (
_aggregate_wsgi_filename
if category == "wsgi"
else _aggregate_profiler_filename
)
for filename, times in _aggregate_results(files, aggregator).iteritems():
for filename, times in _aggregate_results(files, aggregator).items():
if filename not in results[category]:
results[category][filename] = {}
if run not in results[category][filename]:
results[category][filename][run] = []
results[category][filename][run].extend(times)

with PdfPages(save_file) as pdf:
for category, profiles in results.iteritems():
for profile, data in profiles.iteritems():
for category, profiles in results.items():
for profile, data in profiles.items():
figure = plt.figure()
figure.suptitle("{}: {}".format(category, profile), fontsize=16)
axes = figure.subplots()
Expand All @@ -126,7 +126,7 @@ def make_all_plots(self, save_file="profile_graphs.pdf"):
errorbar_x = []
errorbar_y = []
errorbar_dy = []
for run, times in data.iteritems():
for run, times in data.items():
if len(times) > 1:
axes.scatter(
len(times) * [run], times, s=3, c='C1', zorder=10,
Expand Down Expand Up @@ -219,7 +219,7 @@ def _aggregate_results(file_stats, f_aggregate):
{"GET.root.prof": [0.003, 0.002, 0.003, 0.003], "GET._status.prof": [0.019]}
"""
results = {}
for filename, stat in file_stats.iteritems():
for filename, stat in file_stats.items():
filename = f_aggregate(filename)
if filename not in results:
results[filename] = []
Expand Down
4 changes: 2 additions & 2 deletions cdispyutils/uwsgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import absolute_import


import time
from flask import request, abort
Expand All @@ -16,7 +16,7 @@ def setup_user_harakiri(app):
"""

try:
import uwsgi
from . import uwsgi
except ImportError:
uwsgi = None
else:
Expand Down
8 changes: 4 additions & 4 deletions test/hmac4/test_hmac4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# coding: utf-8

from __future__ import unicode_literals, print_function


import datetime
import sys
Expand All @@ -16,8 +16,8 @@
try:
from urllib.parse import urlparse, quote_plus
except ImportError:
from urlparse import urlparse
from urllib import quote_plus
from urllib.parse import urlparse
from urllib.parse import quote_plus

import requests
from test.mock_datetime import mock_datetime
Expand Down Expand Up @@ -47,7 +47,7 @@ def request_from_text(text):
hdr = hdr.lower()
vals = headers.setdefault(hdr, [])
vals.append(val)
headers = {hdr: ','.join(sorted(vals)) for hdr, vals in headers.items()}
headers = {hdr: ','.join(sorted(vals)) for hdr, vals in list(headers.items())}
check_url = urlparse(path)
if check_url.scheme and check_url.netloc:
# absolute URL in path
Expand Down