Revision 6e147ecc snf-pithos-backend/pithos/backends/modular.py
b/snf-pithos-backend/pithos/backends/modular.py | ||
---|---|---|
36 | 36 |
import time |
37 | 37 |
import uuid as uuidlib |
38 | 38 |
import logging |
39 |
import hashlib |
|
39 | 40 |
import binascii |
40 | 41 |
|
41 | 42 |
from base import DEFAULT_QUOTA, DEFAULT_VERSIONING, NotAllowedError, QuotaError, BaseBackend |
42 | 43 |
|
43 |
from pithos.lib.hashmap import HashMap |
|
44 |
# Stripped-down version of the HashMap class found in tools. |
|
45 |
class HashMap(list): |
|
46 |
|
|
47 |
def __init__(self, blocksize, blockhash): |
|
48 |
super(HashMap, self).__init__() |
|
49 |
self.blocksize = blocksize |
|
50 |
self.blockhash = blockhash |
|
51 |
|
|
52 |
def _hash_raw(self, v): |
|
53 |
h = hashlib.new(self.blockhash) |
|
54 |
h.update(v) |
|
55 |
return h.digest() |
|
56 |
|
|
57 |
def hash(self): |
|
58 |
if len(self) == 0: |
|
59 |
return self._hash_raw('') |
|
60 |
if len(self) == 1: |
|
61 |
return self.__getitem__(0) |
|
62 |
|
|
63 |
h = list(self) |
|
64 |
s = 2 |
|
65 |
while s < len(h): |
|
66 |
s = s * 2 |
|
67 |
h += [('\x00' * len(h[0]))] * (s - len(h)) |
|
68 |
while len(h) > 1: |
|
69 |
h = [self._hash_raw(h[x] + h[x + 1]) for x in range(0, len(h), 2)] |
|
70 |
return h[0] |
|
44 | 71 |
|
45 | 72 |
# Default modules and settings. |
46 | 73 |
DEFAULT_DB_MODULE = 'pithos.backends.lib.sqlalchemy' |
Also available in: Unified diff