From 782bd7329a8bbd398b35802eb07a417a4261b66f Mon Sep 17 00:00:00 2001 From: Piper Merriam Date: Thu, 2 Feb 2017 16:33:39 -0700 Subject: [PATCH] py34 and py27 compat --- web3/utils/caching.py | 6 ++++-- web3/utils/compat/__init__.py | 2 ++ web3/utils/compat/compat_py2.py | 1 + web3/utils/compat/compat_py3.py | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/web3/utils/caching.py b/web3/utils/caching.py index b7c50ce..58ae43e 100644 --- a/web3/utils/caching.py +++ b/web3/utils/caching.py @@ -1,5 +1,4 @@ import hashlib -import collections from .types import ( is_boolean, @@ -13,6 +12,9 @@ from .types import ( from .string import ( force_bytes, ) +from .compat import ( + Generator, +) def generate_cache_key(value): @@ -31,7 +33,7 @@ def generate_cache_key(value): for key in sorted(value.keys()) )) - elif is_array(value) or isinstance(value, collections.Generator): + elif is_array(value) or isinstance(value, Generator): return generate_cache_key("".join(( generate_cache_key(item) for item diff --git a/web3/utils/compat/__init__.py b/web3/utils/compat/__init__.py index 2ae6664..e4e6c34 100644 --- a/web3/utils/compat/__init__.py +++ b/web3/utils/compat/__init__.py @@ -6,11 +6,13 @@ if sys.version_info.major == 2: from .compat_py2 import ( urlparse, urlunparse, + Generator, ) else: from .compat_py3 import ( # noqa: #401 urlparse, urlunparse, + Generator, ) diff --git a/web3/utils/compat/compat_py2.py b/web3/utils/compat/compat_py2.py index 4560f1d..d1c0795 100644 --- a/web3/utils/compat/compat_py2.py +++ b/web3/utils/compat/compat_py2.py @@ -2,3 +2,4 @@ from urlparse import ( # noqa: F401 urlparse, urlunparse, ) +Generator = type(_ for _ in tuple()) diff --git a/web3/utils/compat/compat_py3.py b/web3/utils/compat/compat_py3.py index 265d478..11777ce 100644 --- a/web3/utils/compat/compat_py3.py +++ b/web3/utils/compat/compat_py3.py @@ -1,4 +1,8 @@ +import collections + from urllib.parse import ( # noqa: F401 urlparse, urlunparse, ) + +Generator = collections.Generator