Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/olpc/datastore/backingstore.py
diff options
context:
space:
mode:
authorBenjamin Saller <bcsaller@objectrealms.net>2007-04-29 00:43:21 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-04-29 00:43:21 (GMT)
commitb5f4403a08e4f24913709fbb9f83b1f3daa22d8b (patch)
treeff325196cd1eb2d4c7d7843076ae46b7daf4a149 /src/olpc/datastore/backingstore.py
parentfcf7ffeca964c31925c0ba275b2b09715070d541 (diff)
removed 2.5 hashlib dep
Diffstat (limited to 'src/olpc/datastore/backingstore.py')
-rw-r--r--src/olpc/datastore/backingstore.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/olpc/datastore/backingstore.py b/src/olpc/datastore/backingstore.py
index 81d1f9a..02cdb1a 100644
--- a/src/olpc/datastore/backingstore.py
+++ b/src/olpc/datastore/backingstore.py
@@ -10,7 +10,7 @@ __docformat__ = 'restructuredtext'
__copyright__ = 'Copyright ObjectRealms, LLC, 2007'
__license__ = 'The GNU Public License V2+'
-import hashlib
+import sha
import os
class BackingStore(object):
@@ -73,8 +73,6 @@ class FileBackingStore(BackingStore):
def _translatePath(self, uid):
"""translate a UID to a path name"""
- # this backend maps back the file checksum as a sha224 hex uid
- # so this works
return os.path.join(self.base, str(uid))
def create(self, content, filelike):
@@ -110,6 +108,13 @@ class FileBackingStore(BackingStore):
"""
content = self.querymanager.get(uid)
content.file = fp
+ if self.options.get('verify', False):
+ c = sha.sha()
+ for line in fp:
+ c.update(line)
+ fp.seek(0)
+ if c.hexdigest() != content.checksum:
+ raise ValueError("Content for %s corrupt" % uid)
return content
def _writeContent(self, content, filelike, replace=True):
@@ -118,7 +123,7 @@ class FileBackingStore(BackingStore):
raise KeyError("objects with path:%s for uid:%s exists" %(
path, content.id))
fp = open(path, 'w')
- c = hashlib.sha224()
+ c = sha.sha()
for line in filelike:
c.update(line)
fp.write(line)