Commit e5354e76 authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/t/{tcpu,tzodb}.py: Move hashing utilities & hashRegistry to -> zodbtools

Moved here:

	nexedi/zodbtools@e973d519
parent fe751a15
......@@ -25,37 +25,11 @@ from __future__ import print_function
import sys
import hashlib
import zlib
from zlib import crc32, adler32
from os.path import dirname
from zodbtools.util import Adler32Hasher, CRC32Hasher
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
_unitv = "BKMGT" # (2^10)^i represents by corresponding char suffix
def fmtsize(size):
......
......@@ -22,37 +22,15 @@
from __future__ import print_function
import zodbtools.util
from zodbtools.util import storageFromURL, hashRegistry
from ZODB.POSException import POSKeyError
from ZODB.utils import p64, u64
import hashlib
from tcpu import Adler32Hasher, CRC32Hasher
import sys
import logging
from time import time
from getopt import getopt, GetoptError
# hasher that discards data
class NullHasher:
name = "null"
def update(self, data):
pass
def hexdigest(self):
return "00"
# {} name -> hasher
hashRegistry = {
"null": NullHasher,
"adler32": Adler32Hasher,
"crc32": CRC32Hasher,
"sha1": hashlib.sha1,
"sha256": hashlib.sha256,
"sha512": hashlib.sha512,
}
def usage(w):
print(\
"""Usage: tzodb zhash [options] url
......@@ -115,7 +93,7 @@ def zhash():
l = logging.getLogger()
l.addHandler(logging.StreamHandler())
stor = zodbtools.util.storageFromURL(url, read_only=True)
stor = storageFromURL(url, read_only=True)
last_tid = stor.lastTransaction()
before = p64(u64(last_tid) + 1)
......
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