[gobject-introspection] giscanner: Use pickle when cPickle is not available
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] giscanner: Use pickle when cPickle is not available
- Date: Wed, 30 Sep 2015 03:35:10 +0000 (UTC)
commit 6e7e809a06c2133b744dd2d3f5ca2f72c02aef06
Author: Simon Feltman <sfeltman src gnome org>
Date: Tue Apr 29 01:21:14 2014 -0700
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
giscanner/cachestore.py | 16 ++++++++++------
1 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py
index f235259..20a6b60 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]