Use BytesIO instead of StringIO for python2/3 compatibility

This commit is contained in:
Benjamin Yolken 2017-02-03 22:36:34 -08:00
parent 716406198e
commit 461e41cd61
1 changed files with 3 additions and 7 deletions

View File

@ -12,13 +12,9 @@ try:
except ImportError: except ImportError:
import pickle import pickle
import io
import logging import logging
try:
import StringIO
except ImportError:
import io as StringIO
import boto3 import boto3
from werkzeug.contrib.cache import BaseCache from werkzeug.contrib.cache import BaseCache
@ -56,7 +52,7 @@ class S3Cache(BaseCache):
if not self._key_exists(key): if not self._key_exists(key):
return None return None
else: else:
value_file = StringIO.StringIO() value_file = io.BytesIO()
try: try:
self.s3_client.download_fileobj( self.s3_client.download_fileobj(
@ -117,7 +113,7 @@ class S3Cache(BaseCache):
``pickle.PickleError``. ``pickle.PickleError``.
:rtype: boolean :rtype: boolean
""" """
value_file = StringIO.StringIO() value_file = io.BytesIO()
pickle.dump(value, value_file) pickle.dump(value, value_file)
try: try: