Commit 9aa96d2e authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8a6145c1
...@@ -24,12 +24,38 @@ from __future__ import print_function ...@@ -24,12 +24,38 @@ from __future__ import print_function
import sys import sys
import hashlib import hashlib
import tzodb
import zlib import zlib
from zlib import crc32, adler32
from os.path import dirname from os.path import dirname
from golang import testing from golang import testing
# adler32 in hashlib interface
class Adler32Hasher:
name = "adler32"
def __init__(self):
self.h = adler32('')
def update(self, data):
self.h = adler32(data, self.h)
def hexdigest(self):
return '%08x' % (self.h & 0xffffffff)
# crc32 in hashlib interface
class CRC32Hasher:
name = "crc32"
def __init__(self):
self.h = crc32('')
def update(self, data):
self.h = crc32(data, self.h)
def hexdigest(self):
return '%08x' % (self.h & 0xffffffff)
# fmtsize formats size in human readable form # fmtsize formats size in human readable form
_unitv = "BKMGT" # (2^10)^i represents by corresponding char suffix _unitv = "BKMGT" # (2^10)^i represents by corresponding char suffix
def fmtsize(size): def fmtsize(size):
...@@ -77,8 +103,8 @@ def _bench_hasher(b, h, blksize): ...@@ -77,8 +103,8 @@ def _bench_hasher(b, h, blksize):
i += 1 i += 1
def bench_adler32(b, blksize): _bench_hasher(b, tzodb.Adler32Hasher(), blksize) def bench_adler32(b, blksize): _bench_hasher(b, Adler32Hasher(), blksize)
def bench_crc32(b, blksize): _bench_hasher(b, tzodb.CRC32Hasher(), blksize) def bench_crc32(b, blksize): _bench_hasher(b, CRC32Hasher(), blksize)
def bench_sha1(b, blksize): _bench_hasher(b, hashlib.sha1(), blksize) def bench_sha1(b, blksize): _bench_hasher(b, hashlib.sha1(), blksize)
......
...@@ -27,7 +27,7 @@ from ZODB.POSException import POSKeyError ...@@ -27,7 +27,7 @@ from ZODB.POSException import POSKeyError
from ZODB.utils import p64, u64 from ZODB.utils import p64, u64
import hashlib import hashlib
from zlib import crc32, adler32 from tcpu import Adler32Hasher, CRC32Hasher
import sys import sys
import logging import logging
from time import time from time import time
...@@ -43,32 +43,6 @@ class NullHasher: ...@@ -43,32 +43,6 @@ class NullHasher:
def hexdigest(self): def hexdigest(self):
return "00" return "00"
# adler32 in hashlib interface
class Adler32Hasher:
name = "adler32"
def __init__(self):
self.h = adler32('')
def update(self, data):
self.h = adler32(data, self.h)
def hexdigest(self):
return '%08x' % (self.h & 0xffffffff)
# crc32 in hashlib interface
class CRC32Hasher:
name = "crc32"
def __init__(self):
self.h = crc32('')
def update(self, data):
self.h = crc32(data, self.h)
def hexdigest(self):
return '%08x' % (self.h & 0xffffffff)
# {} name -> hasher # {} name -> hasher
hashRegistry = { hashRegistry = {
"null": NullHasher, "null": NullHasher,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment