Skip to content

Commit 4a91d1b

Browse files
committed
Use six instead of manually maintaining compatibility with PY2.
This makes it easier to use constants for status codes as well.
1 parent 5d498d2 commit 4a91d1b

File tree

6 files changed

+8
-23
lines changed

6 files changed

+8
-23
lines changed

cachecontrol/compat.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
try:
2-
from urllib.parse import urljoin
3-
except ImportError:
4-
from urlparse import urljoin
5-
6-
7-
try:
8-
import cPickle as pickle
9-
except ImportError:
10-
import pickle
11-
12-
131
# Handle the case where the requests module has been patched to not have
142
# urllib3 bundled as part of its source.
153
try:
@@ -21,9 +9,3 @@
219
from requests.packages.urllib3.util import is_fp_closed
2210
except ImportError:
2311
from urllib3.util import is_fp_closed
24-
25-
# Replicate some six behaviour
26-
try:
27-
text_type = unicode
28-
except NameError:
29-
text_type = str

cachecontrol/serialize.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import msgpack
77
from requests.structures import CaseInsensitiveDict
88

9-
from .compat import HTTPResponse, pickle, text_type
9+
from six import text_type
10+
from six.moves import cPickle as pickle
11+
12+
from .compat import HTTPResponse
1013

1114

1215
def _b64_decode_bytes(b):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
include_package_data=True,
1818
description="httplib2 caching for requests",
1919
long_description=long_description,
20-
install_requires=["requests", "msgpack>=0.5.2"],
20+
install_requires=["requests", "msgpack>=0.5.2", "six"],
2121
extras_require={"filecache": ["lockfile>=0.9"], "redis": ["redis>=2.10.5"]},
2222
entry_points={"console_scripts": ["doesitcache = cachecontrol._cmd:main"]},
2323
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",

tests/test_etag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from cachecontrol import CacheControl
66
from cachecontrol.cache import DictCache
7-
from cachecontrol.compat import urljoin
7+
from six.moves.urllib.parse import urljoin
88

99

1010
class NullSerializer(object):

tests/test_serialization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import requests
33
from mock import Mock
44

5-
from cachecontrol.compat import pickle
65
from cachecontrol.serialize import Serializer
6+
from six.moves import cPickle as pickle
77

88

99
class TestSerializer(object):

tests/test_vary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from cachecontrol import CacheControl
77
from cachecontrol.cache import DictCache
8-
from cachecontrol.compat import urljoin
8+
from six.moves.urllib.parse import urljoin
99

1010

1111
class TestVary(object):

0 commit comments

Comments
 (0)