Handle unicode, utf8, and windows-1252

(cherry picked from commit 0d4f24a)
This commit is contained in:
Ebag333
2016-11-26 22:57:53 -08:00
parent 38bf143704
commit 08b5abc7ad
6 changed files with 104 additions and 27 deletions

View File

@@ -45,7 +45,13 @@ class FileCache(APICache):
os.mkdir(self.path, 0o700)
def _getpath(self, key):
return os.path.join(self.path, str(hash(key)) + '.cache')
path = os.path.join(self.path, str(hash(key)) + '.cache')
if type(path) == str: # leave unicode ones alone
try:
path = path.decode('utf8')
except UnicodeDecodeError:
path = path.decode('windows-1252')
return path
def put(self, key, value):
with open(self._getpath(key), 'wb') as f: