diff options
author | Adam Chainz <adam@adamj.eu> | 2016-08-16 18:31:42 +0100 |
---|---|---|
committer | Adam Chainz <adam@adamj.eu> | 2016-08-16 18:31:42 +0100 |
commit | e7489e533a2f173ae9d79251c2ed96ddf8fcb519 (patch) | |
tree | ae72847d6c15d17e03303ff5eb5fdb2bbd4611a2 | |
parent | cddab4731afe2012f15bd89ff84acbe1203fa744 (diff) | |
download | pymemcache-e7489e533a2f173ae9d79251c2ed96ddf8fcb519.tar.gz |
Make serde import on Python 3
-rw-r--r-- | pymemcache/serde.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/pymemcache/serde.py b/pymemcache/serde.py index c7a00ee..1a5a31a 100644 --- a/pymemcache/serde.py +++ b/pymemcache/serde.py @@ -20,6 +20,11 @@ try: except ImportError: from StringIO import StringIO +try: + long_type = long # noqa +except NameError: + long_type = None + FLAG_PICKLE = 1 << 0 FLAG_INTEGER = 1 << 1 @@ -34,7 +39,7 @@ def python_memcache_serializer(key, value): elif isinstance(value, int): flags |= FLAG_INTEGER value = "%d" % value - elif isinstance(value, long): + elif long_type is not None and isinstance(value, long_type): flags |= FLAG_LONG value = "%d" % value else: @@ -55,7 +60,7 @@ def python_memcache_deserializer(key, value, flags): return int(value) if flags & FLAG_LONG: - return long(value) + return long_type(value) if flags & FLAG_PICKLE: try: |