Skip to content

Commit 0fe4cd0

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 03d034f commit 0fe4cd0

File tree

6 files changed

+8
-22
lines changed

6 files changed

+8
-22
lines changed

cachecontrol/compat.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5-
try:
6-
from urllib.parse import urljoin
7-
except ImportError:
8-
from urlparse import urljoin
9-
10-
11-
try:
12-
import cPickle as pickle
13-
except ImportError:
14-
import pickle
15-
165
# Handle the case where the requests module has been patched to not have
176
# urllib3 bundled as part of its source.
187
try:
@@ -24,9 +13,3 @@
2413
from requests.packages.urllib3.util import is_fp_closed
2514
except ImportError:
2615
from urllib3.util import is_fp_closed
27-
28-
# Replicate some six behaviour
29-
try:
30-
text_type = unicode
31-
except NameError:
32-
text_type = str

cachecontrol/serialize.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
import msgpack
1111
from requests.structures import CaseInsensitiveDict
1212

13-
from .compat import HTTPResponse, pickle, text_type
13+
from six import text_type
14+
from six.moves import cPickle as pickle
15+
16+
from .compat import HTTPResponse
1417

1518

1619
def _b64_decode_bytes(b):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
include_package_data=True,
2222
description="httplib2 caching for requests",
2323
long_description=long_description,
24-
install_requires=["requests", "msgpack>=0.5.2"],
24+
install_requires=["requests", "msgpack>=0.5.2", "six"],
2525
extras_require={"filecache": ["lockfile>=0.9"], "redis": ["redis>=2.10.5"]},
2626
entry_points={"console_scripts": ["doesitcache = cachecontrol._cmd:main"]},
2727
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
@@ -8,7 +8,7 @@
88

99
from cachecontrol import CacheControl
1010
from cachecontrol.cache import DictCache
11-
from cachecontrol.compat import urljoin
11+
from six.moves.urllib.parse import urljoin
1212

1313

1414
class NullSerializer(object):

tests/test_serialization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import requests
77
from mock import Mock
88

9-
from cachecontrol.compat import pickle
109
from cachecontrol.serialize import Serializer
10+
from six.moves import cPickle as pickle
1111

1212

1313
class TestSerializer(object):

tests/test_vary.py

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

88
from cachecontrol import CacheControl
99
from cachecontrol.cache import DictCache
10-
from cachecontrol.compat import urljoin
10+
from six.moves.urllib.parse import urljoin
1111

1212

1313
class TestVary(object):

0 commit comments

Comments
 (0)