From e97f4b84b7b78a8931a40823823fad29c3db71d9 Mon Sep 17 00:00:00 2001 From: Theo Massard Date: Tue, 26 Jun 2018 12:17:39 +0200 Subject: [PATCH 1/2] Allow to use a datetime.timedelta parameter for Client.set Closes #145 --- memcache.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/memcache.py b/memcache.py index 05b6657..c90af62 100644 --- a/memcache.py +++ b/memcache.py @@ -48,6 +48,7 @@ from __future__ import print_function import binascii +from datetime import timedelta from io import BytesIO import re import socket @@ -709,7 +710,7 @@ def set(self, key, val, time=0, min_compress_len=0, noreply=False): expire, either as a delta number of seconds, or an absolute unix time-since-the-epoch value. See the memcached protocol docs section "Storage Commands" for more info on . We - default to 0 == cache forever. + default to 0 == cache forever. Optionnaly now accepts a timedelta. @param min_compress_len: The threshold length to kick in auto-compression of the value using the compressor @@ -724,6 +725,8 @@ def set(self, key, val, time=0, min_compress_len=0, noreply=False): @param noreply: optional parameter instructs the server to not send the reply. ''' + if isinstance(time, timedelta): + time = int(time.total_seconds()) return self._set("set", key, val, time, min_compress_len, noreply) def cas(self, key, val, time=0, min_compress_len=0, noreply=False): From ad8dff243d572fc3316ef5ed0557f7b568b40b12 Mon Sep 17 00:00:00 2001 From: Theo Massard Date: Tue, 26 Jun 2018 14:30:29 +0200 Subject: [PATCH 2/2] minor flake8 errors --- memcache.py | 5 ++++- setup.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/memcache.py b/memcache.py index c90af62..e0a2662 100644 --- a/memcache.py +++ b/memcache.py @@ -68,6 +68,8 @@ def cmemcache_hash(key): return (((binascii.crc32(key) & 0xffffffff) >> 16) & 0x7fff) or 1 + + serverHashFunction = cmemcache_hash @@ -1443,7 +1445,8 @@ def readline(self, raise_exception=False): if self.socket: recv = self.socket.recv else: - recv = lambda bufsize: b'' + def recv(bufsize): + return b'' while True: index = buf.find(b'\r\n') diff --git a/setup.py b/setup.py index 93cbe4d..b8a0d79 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,7 @@ from setuptools.depends import get_module_constant from setuptools import setup # noqa +dl_url = "https://github.com/linsomniac/python-memcached/releases/download/{0}/python-memcached-{0}.tar.gz" version = get_module_constant('memcache', '__version__') setup( @@ -15,7 +16,7 @@ maintainer="Sean Reifschneider", maintainer_email="jafo@tummy.com", url="https://github.com/linsomniac/python-memcached", - download_url="https://github.com/linsomniac/python-memcached/releases/download/{0}/python-memcached-{0}.tar.gz".format(version), + download_url=dl_url.format(version), py_modules=["memcache"], install_requires=open('requirements.txt').read().split(), classifiers=[