From eae00735bd5dd1322b84cf3d7a5ddf4592b383d0 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Fri, 30 Dec 2016 03:24:18 +0100 Subject: [PATCH] Fix issue where '%s' is not supported in strftime() (non unix machine) as the doc doesn't have it. This solution should be py2-py3 compliant. --- esipy/__init__.py | 2 +- esipy/client.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/esipy/__init__.py b/esipy/__init__.py index 39d5b72..af717d8 100644 --- a/esipy/__init__.py +++ b/esipy/__init__.py @@ -10,4 +10,4 @@ pass -__version__ = '0.1.0' +__version__ = '0.1.1' diff --git a/esipy/client.py b/esipy/client.py index 8509984..4428a50 100644 --- a/esipy/client.py +++ b/esipy/client.py @@ -6,14 +6,15 @@ from .cache import DummyCache from collections import namedtuple +from datetime import datetime from email.utils import parsedate from pyswagger.core import BaseClient from requests import Request from requests import Session from requests.adapters import HTTPAdapter + import six -import datetime class EsiClient(BaseClient): @@ -135,10 +136,14 @@ def request(self, req_and_resp, raw_body_only=False, opt={}): def __cache_response(self, cache_key, res): if 'expires' in res.headers: # this date is ALWAYS in UTC (RFC 7231) - expire = datetime.datetime( - *parsedate(res.headers['expires'])[:6] - ).strftime('%s') - now = datetime.datetime.utcnow().strftime('%s') + # + epoch = datetime(1970, 1, 1) + expire = ( + datetime( + *parsedate(res.headers['expires'])[:6] + ) - epoch + ).total_seconds() + now = (datetime.utcnow() - epoch).total_seconds() cache_timeout = int(expire) - int(now) else: