From 742bfa3a67d265f01df207252386cae56b194e49 Mon Sep 17 00:00:00 2001 From: Python3pkg Date: Wed, 17 May 2017 23:14:45 -0700 Subject: [PATCH] Convert to python3 --- blueox/client.py | 2 +- blueox/contrib/django/middleware.py | 4 ++-- blueox/contrib/flask/__init__.py | 2 +- blueox/network.py | 2 +- blueox/store.py | 2 +- blueox/tornado_utils.py | 2 +- tests/store_test.py | 2 +- tests/tornado_utils_test.py | 10 +++++----- vendor/tornado_test.py | 26 +++++++++++++------------- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/blueox/client.py b/blueox/client.py index 617bb8a..e61af8d 100644 --- a/blueox/client.py +++ b/blueox/client.py @@ -44,7 +44,7 @@ def decode_stream(stream): while True: try: - data = stream.next() + data = next(stream) except StopIteration: break diff --git a/blueox/contrib/django/middleware.py b/blueox/contrib/django/middleware.py index b16f486..ef48df5 100644 --- a/blueox/contrib/django/middleware.py +++ b/blueox/contrib/django/middleware.py @@ -27,7 +27,7 @@ def process_request(self, request): blueox.set('path', request.path) headers = {} - for k, v in request.META.iteritems(): + for k, v in request.META.items(): if k.startswith('HTTP_') or k in ('CONTENT_LENGTH', 'CONTENT_TYPE'): headers[k] = v blueox.set('headers', headers) @@ -60,7 +60,7 @@ def process_response(self, request, response): blueox.set('response_size', len(response.content)) headers = {} - for k, v in response.items(): + for k, v in list(response.items()): headers[k] = v blueox.set('response_headers', headers) diff --git a/blueox/contrib/flask/__init__.py b/blueox/contrib/flask/__init__.py index 56fb178..78c9f83 100644 --- a/blueox/contrib/flask/__init__.py +++ b/blueox/contrib/flask/__init__.py @@ -43,7 +43,7 @@ def before_request(self, *args, **kwargs): blueox.set('path', request.path) headers = {} - for k, v in request.environ.iteritems(): + for k, v in request.environ.items(): if ( k.startswith('HTTP_') or k in ('CONTENT_LENGTH', 'CONTENT_TYPE')): diff --git a/blueox/network.py b/blueox/network.py index 377a786..5e39869 100644 --- a/blueox/network.py +++ b/blueox/network.py @@ -117,7 +117,7 @@ def send(context): log.debug("Sending msg") threadLocal.zmq_socket.send_multipart( (meta_data, context_data), zmq.NOBLOCK) - except zmq.ZMQError, e: + except zmq.ZMQError as e: log.exception("Failed sending blueox event, buffer full?") else: log.info("Skipping sending event %s", context.name) diff --git a/blueox/store.py b/blueox/store.py index 66f4f19..adbe8eb 100644 --- a/blueox/store.py +++ b/blueox/store.py @@ -233,7 +233,7 @@ def filter_log_files_for_active(log_files): for lf in log_files: files_by_type[lf.type_name].append(lf) - for type_files in files_by_type.values(): + for type_files in list(files_by_type.values()): type_files.sort(key=lambda f: f.sort_dt) # We assume only the last log file in the list can be possibly be in diff --git a/blueox/tornado_utils.py b/blueox/tornado_utils.py index ffbfa9b..9a91a11 100644 --- a/blueox/tornado_utils.py +++ b/blueox/tornado_utils.py @@ -147,7 +147,7 @@ def __init__(self, *args, **kwargs): def fetch(self, request, callback=None, **kwargs): start_time = time.time() - if isinstance(request, basestring): + if isinstance(request, str): request = tornado.httpclient.HTTPRequest(url=request, **kwargs) ctx = blueox.Context(self.blueox_name) diff --git a/tests/store_test.py b/tests/store_test.py index 944b6a6..13cbbee 100644 --- a/tests/store_test.py +++ b/tests/store_test.py @@ -347,7 +347,7 @@ def test_range(self): dt_str = dt.strftime('%Y%m%d%H') full_path = os.path.join(self.log_path, date_str, "foo-{}.log".format(dt_str)) with io.open(full_path, "w") as f: - f.write(u"hi") + f.write("hi") start_dt = datetime.datetime(2015, 5, 19, 1) end_dt = datetime.datetime(2015, 5, 19, 3) diff --git a/tests/tornado_utils_test.py b/tests/tornado_utils_test.py index e6aedd4..6b1fce4 100644 --- a/tests/tornado_utils_test.py +++ b/tests/tornado_utils_test.py @@ -65,7 +65,7 @@ def post(self): blueox.set("start", True) try: f = yield http_client.fetch(self.request.body, request_timeout=0.5) - except tornado.httpclient.HTTPError, e: + except tornado.httpclient.HTTPError as e: self.write("got it") else: self.write("nope") @@ -120,7 +120,7 @@ def test_error(self): assert_equal(len(self.log_ctx), 2) found_exception = False - for ctx_list in self.log_ctx.values(): + for ctx_list in list(self.log_ctx.values()): for ctx in ctx_list: if ctx.to_dict()['body'].get('exception'): found_exception = True @@ -137,7 +137,7 @@ def test_timeout_error(self): #pprint.pprint(ctx.to_dict()) assert_equal(len(self.log_ctx), 1) - ctx = self.log_ctx[self.log_ctx.keys()[0]][0] + ctx = self.log_ctx[list(self.log_ctx.keys())[0]][0] assert_equal(get_deep(ctx.to_dict(), 'body.response.code'), 599) def test_recurse_timeout_error(self): @@ -158,7 +158,7 @@ def test_recurse_timeout_error(self): found_timeout = False found_request = False - for ctx_list in self.log_ctx.values(): + for ctx_list in list(self.log_ctx.values()): for ctx in ctx_list: c = ctx.to_dict() if c['type'] == 'request.httpclient' and c['body']['response']['code'] == 599: @@ -186,7 +186,7 @@ def test_context(self): found_sync = None found_async = None found_client = 0 - for ctx_list in self.log_ctx.values(): + for ctx_list in list(self.log_ctx.values()): for ctx in ctx_list: if ctx.name == "request" and ctx.to_dict()['body']['async']: assert_equal(len(ctx_list), 3) diff --git a/vendor/tornado_test.py b/vendor/tornado_test.py index 22caaea..618b415 100644 --- a/vendor/tornado_test.py +++ b/vendor/tornado_test.py @@ -2,7 +2,7 @@ Testify. """ -import Cookie +import http.cookies import tornado.httputil from tornado.httpclient import AsyncHTTPClient from tornado.httpserver import HTTPServer @@ -12,7 +12,7 @@ import sys import time import json -import urlparse +import urllib.parse import pprint try: @@ -202,9 +202,9 @@ def timeout_func(): # 2to3 isn't smart enough to convert three-argument raise # statements correctly in some cases. if isinstance(self.__failure[1], self.__failure[0]): - raise self.__failure[1], None, self.__failure[2] + raise self.__failure[1].with_traceback(self.__failure[2]) else: - raise self.__failure[0], self.__failure[1], self.__failure[2] + raise self.__failure[0](self.__failure[1]).with_traceback(self.__failure[2]) result = self.__stop_args self.__stop_args = None return result @@ -277,10 +277,10 @@ def fetch(self, request, **kwargs): timeout = kwargs.pop('timeout') if hasattr(request, 'url'): - parsed = urlparse.urlparse(request.url) + parsed = urllib.parse.urlparse(request.url) request.url = self.update_urlparsed(parsed) else: - parsed = urlparse.urlparse(request) + parsed = urllib.parse.urlparse(request) request = self.update_urlparsed(parsed) if 'headers' in kwargs and not isinstance(kwargs['headers'], tornado.httputil.HTTPHeaders): @@ -289,27 +289,27 @@ def fetch(self, request, **kwargs): else: kwargs.setdefault('headers', tornado.httputil.HTTPHeaders()) - if 'body' in kwargs and not isinstance(kwargs['body'], basestring): + if 'body' in kwargs and not isinstance(kwargs['body'], str): kwargs['body'] = json.dumps(kwargs['body']) kwargs['headers']['Content-Type'] = 'application/json' if 'cookies' in kwargs: for cookie in kwargs['cookies']: - for val in cookie.values(): + for val in list(cookie.values()): kwargs['headers'].add('Cookie', val.OutputString(None)) if self.cookie_jar: - cookie = Cookie.SimpleCookie(self.cookie_jar) - for val in cookie.values(): + cookie = http.cookies.SimpleCookie(self.cookie_jar) + for val in list(cookie.values()): kwargs['headers'].add('Cookie', val.OutputString(None)) self.http_client.fetch(request, self.stop, **kwargs) res = self.wait(timeout=timeout) for cookie_val in res.headers.get_list('set-cookie'): - cookie = Cookie.SimpleCookie() + cookie = http.cookies.SimpleCookie() cookie.load(cookie_val) - for val in cookie.values(): + for val in list(cookie.values()): if not val.value: del self.cookie_jar[val.key] else: @@ -343,6 +343,6 @@ def get_url(self, path): return 'http://localhost:%s%s' % (self.get_http_port(), path) def update_urlparsed(self, parsed): - return urlparse.urlunparse(['http', 'localhost:%s' % self.get_http_port()] + list(parsed[2:])) + return urllib.parse.urlunparse(['http', 'localhost:%s' % self.get_http_port()] + list(parsed[2:]))