summaryrefslogtreecommitdiff
path: root/giscanner/cachestore.py
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2014-04-29 01:21:14 -0700
committerColin Walters <walters@verbum.org>2015-09-29 23:16:32 -0400
commit6e7e809a06c2133b744dd2d3f5ca2f72c02aef06 (patch)
treefd567ebb605652ffa19ce58e96eb624144ce43fe /giscanner/cachestore.py
parentae198873254769bd49207003d25b47d12b096e2f (diff)
downloadgobject-introspection-6e7e809a06c2133b744dd2d3f5ca2f72c02aef06.tar.gz
giscanner: Use pickle when cPickle is not available
This adds compatibility with Python 3 which removed the cPickle module. Explicitly use binary files for reading and writing the cache. https://bugzilla.gnome.org/show_bug.cgi?id=679438
Diffstat (limited to 'giscanner/cachestore.py')
-rw-r--r--giscanner/cachestore.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py
index f2352591..20a6b606 100644
--- a/giscanner/cachestore.py
+++ b/giscanner/cachestore.py
@@ -24,7 +24,6 @@ from __future__ import print_function
from __future__ import unicode_literals
import errno
-import cPickle
import glob
import hashlib
import os
@@ -32,6 +31,11 @@ import shutil
import sys
import tempfile
+try:
+ import cPickle as pickle
+except ImportError:
+ import pickle
+
import giscanner
from . import utils
@@ -143,8 +147,8 @@ class CacheStore(object):
tmp_fd, tmp_filename = tempfile.mkstemp(prefix='g-ir-scanner-cache-')
try:
- with os.fdopen(tmp_fd, 'w') as tmp_file:
- cPickle.dump(data, tmp_file)
+ with os.fdopen(tmp_fd, 'wb') as tmp_file:
+ pickle.dump(data, tmp_file)
except IOError as e:
# No space left on device
if e.errno == errno.ENOSPC:
@@ -167,7 +171,7 @@ class CacheStore(object):
if store_filename is None:
return
try:
- fd = open(store_filename)
+ fd = open(store_filename, 'rb')
except IOError as e:
if e.errno == errno.ENOENT:
return None
@@ -176,8 +180,8 @@ class CacheStore(object):
if not self._cache_is_valid(store_filename, filename):
return None
try:
- data = cPickle.load(fd)
- except (AttributeError, EOFError, ValueError, cPickle.BadPickleGet):
+ data = pickle.load(fd)
+ except (AttributeError, EOFError, ValueError, pickle.BadPickleGet):
# Broken cache entry, remove it
self._remove_filename(store_filename)
data = None