From 856adada79537bd47eda3079805646c6af13c299 Mon Sep 17 00:00:00 2001 From: Christian Wygoda Date: Wed, 6 Jun 2018 22:41:03 +0200 Subject: [PATCH] Make code compatible with Python 2.6+ and Python 3 --- garminexport/garminclient.py | 7 ++++--- requirements.txt | 1 + tests/test_retryer.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/garminexport/garminclient.py b/garminexport/garminclient.py index c22f3b3..d1eb4ef 100755 --- a/garminexport/garminclient.py +++ b/garminexport/garminclient.py @@ -8,13 +8,14 @@ import logging import os import re import requests -from StringIO import StringIO +from io import BytesIO import sys import zipfile import dateutil import dateutil.parser import os.path from functools import wraps +from builtins import range # # Note: For more detailed information about the API services @@ -163,7 +164,7 @@ class GarminClient(object): batch_size = 100 # fetch in batches since the API doesn't allow more than a certain # number of activities to be retrieved on every invocation - for start_index in xrange(0, sys.maxint, batch_size): + for start_index in range(0, sys.maxsize, batch_size): next_batch = self._fetch_activity_ids_and_ts(start_index, batch_size) if not next_batch: break @@ -328,7 +329,7 @@ class GarminClient(object): # return the first entry from the zip archive where the filename is # activity_id (should be the only entry!) - zip = zipfile.ZipFile(StringIO(response.content), mode="r") + zip = zipfile.ZipFile(BytesIO(response.content), mode="r") for path in zip.namelist(): fn, ext = os.path.splitext(path) if fn==str(activity_id): diff --git a/requirements.txt b/requirements.txt index 2a57eaf..b550dab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ requests==2.9.1 python-dateutil==2.4.1 +future==0.16.0 nose==1.3.7 coverage==4.2 diff --git a/tests/test_retryer.py b/tests/test_retryer.py index b3720fd..e2a6d74 100644 --- a/tests/test_retryer.py +++ b/tests/test_retryer.py @@ -74,7 +74,7 @@ class TestRetryer(unittest.TestCase): func = lambda : int(time.time()) returnval = retryer.call(func) - print returnval + print(returnval) class TestFixedDelayStrategy(unittest.TestCase):