本文整理汇总了Python中xxhash.xxh64方法的典型用法代码示例。如果您正苦于以下问题:Python xxhash.xxh64方法的具体用法?Python xxhash.xxh64怎么用?Python xxhash.xxh64使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xxhash
的用法示例。
在下文中一共展示了xxhash.xxh64方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rename
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def rename(self, old, new):
old = self.remotepath(old)
new = self.remotepath(new)
self.logger.info('rename {} {}'.format(old, new))
self.taskpool.wait(xxhash.xxh64(old).intdigest())
try:
self.unlink(self.localpath(new))
except Exception as e:
self.logger.debug(e)
status = self.sftp.rename(old, new)
self.attributes.remove(old)
self.attributes.remove(new)
self.directories.remove(os.path.dirname(old))
self.directories.remove(os.path.dirname(new))
return status
示例2: truncate
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def truncate(self, path, length, fh=None):
realpath = self.remotepath(path)
cachefile = self.cachefile(realpath)
if not os.path.exists(cachefile):
if self.empty_file(realpath):
self.create(path, 'wb')
else:
raise FuseOSError(ENOENT)
status = os.truncate(cachefile, length)
self.logger.info(self.extract(os.lstat(cachefile)))
self.attributes.insert(realpath, self.extract(os.lstat(cachefile)))
task = Task(xxhash.xxh64(realpath).intdigest(),
self._truncate, realpath, length)
self.taskpool.submit(task)
return status
示例3: write
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def write(self, path, data, offset, fh):
realpath = self.remotepath(path)
cachefile = self.cachefile(realpath)
if not os.path.exists(cachefile):
if self.empty_file(realpath):
self.create(path, 'wb')
else:
raise FuseOSError(ENOENT)
with open(cachefile, 'rb+') as outfile:
outfile.seek(offset, 0)
outfile.write(data)
self.attributes.insert(realpath, self.extract(os.lstat(cachefile)))
task = Task(xxhash.xxh64(realpath).intdigest(),
self._write, realpath, data, offset)
self.taskpool.submit(task)
return len(data)
示例4: __hash__
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def __hash__(self):
h = xxhash.xxh64()
h.update(self._coordinate_system)
if self.is_regular:
h.update(self.delta)
h.update(self.dims)
h.update(self.zero)
elif self.is_separated:
for s in self.separated_coords:
h.update(s)
else:
for s in self.coords:
h.update(s)
return h.intdigest()
示例5: xxh128
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def xxh128(data):
"""
Helper function to calculate a 2 concatenated xxh64 hash for provided data, used as key for several Substrate
Parameters
----------
data
Returns
-------
"""
storage_key1 = bytearray(xxhash.xxh64(data, seed=0).digest())
storage_key1.reverse()
storage_key2 = bytearray(xxhash.xxh64(data, seed=1).digest())
storage_key2.reverse()
return "{}{}".format(storage_key1.hex(), storage_key2.hex())
示例6: two_x64_concat
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def two_x64_concat(data):
"""
Helper function to calculate a xxh64 hash with concatenated data for provided data,
used as key for several Substrate
Parameters
----------
data
Returns
-------
"""
storage_key = bytearray(xxhash.xxh64(data, seed=0).digest())
storage_key.reverse()
return "{}{}".format(storage_key.hex(), data.hex())
示例7: get_profile_picture_absolute_url
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def get_profile_picture_absolute_url(self):
# Because of invitations, profile photos are not protected by
# authorization. But to prevent user enumeration and to bust
# caches when photos change, we include in the URL some
# information about the internal data of the profile photo,
# which is checked in views_landing.py's user_profile_photo().
# Get the current profile photo.
try:
pic = self._get_setting("picture")
if pic is None:
return
except:
return None
# We've got the content. Make a fingerprint.
import xxhash, base64
payload = pic['content_dataurl']
fingerprint = base64.urlsafe_b64encode(
xxhash.xxh64(payload).digest()
).decode('ascii').rstrip("=")
return settings.SITE_ROOT_URL + "/media/users/%d/photo/%s" % (
self.id,
fingerprint
)
示例8: get_avatar_fallback_css
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def get_avatar_fallback_css(self):
# Compute a non-cryptographic hash over the user ID and username to generate
# a stable set of random bytes to use to select CSS styles.
import xxhash
payload = "%d|%s|" % (self.id, self.username)
digest = xxhash.xxh64(payload).digest()
# Choose two colors at random using the bytes of the digest.
color1 = User.random_colors[digest[0] % len(User.random_colors)]
color2 = User.random_colors[digest[1] % len(User.random_colors)]
# Generate some CSS using a gradient and a fallback style.
return {
"css": "background: {color1}; background: linear-gradient({color1}, {color2}); color: black;"
.format(color1=color1, color2=color2),
"text": self.username[0:2].upper(),
}
示例9: hash_array
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def hash_array(array):
"""Compute hash of a NumPy array by hashing data as a byte sequence.
Args:
array (array): NumPy array to compute hash of.
Returns:
hash (int): Computed hash as an integer.
"""
if XXHASH_AVAILABLE:
# If fast Python wrapper of fast xxhash implementation is available use
# in preference to built in hash function
h = xxhash.xxh64()
# Update hash by viewing array as byte sequence - no copy required
h.update(array.view(np.byte).data)
# Also update hash by array dtype, shape and strides to avoid clashes
# between different views of same array
h.update(bytes(f'{array.dtype}{array.shape}{array.strides}', 'utf-8'))
return h.intdigest()
else:
# Evaluate built-in hash function on *copy* of data as a byte sequence
return hash(array.tobytes())
示例10: __init__
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def __init__(self, *args, **kwargs):
super(Topic, self).__init__(*args, **kwargs)
self.raw_content_hash = xxhash.xxh64(self.content_raw).hexdigest()
示例11: save
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def save(self, *args, **kwargs):
new_hash = xxhash.xxh64(self.content_raw).hexdigest()
mentioned_users = []
if new_hash != self.raw_content_hash or (not self.pk):
# To (re-)render the content if content changed or topic is newly created
self.content_rendered, mentioned_users = render_content(self.content_raw, sender=self.user.username)
super(Topic, self).save(*args, **kwargs)
self.raw_content_hash = new_hash
for to in mentioned_users:
notify.delay(to=to.username, sender=self.user.username, topic=self.pk)
示例12: read
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def read(self, path, size, offset, fh):
path = self.remotepath(path)
cachefile = self.cachefile(path)
if os.path.exists(cachefile):
with open(cachefile, 'rb') as infile:
infile.seek(offset, 0)
return infile.read(size)
task = Task(xxhash.xxh64(path).intdigest(), self.getfile, path)
self.taskpool.submit(task)
with self.sftp.open(path, 'rb') as infile:
infile.seek(offset, 0)
return infile.read(size)
示例13: hash_file2
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def hash_file2(fpath, blocksize=65536, hasher='xx64'):
r"""
Hashes the data in a file on disk using xxHash
xxHash is much faster than sha1, bringing computation time down from .57
seconds to .12 seconds for a 387M file.
my_weights_fpath_ = ub.truepath('~/tmp/my_weights.pt')
xdata = 2 ** np.array([8, 12, 14, 16])
ydatas = ub.ddict(list)
for blocksize in xdata:
print('blocksize = {!r}'.format(blocksize))
ydatas['sha1'].append(ub.Timerit(2).call(ub.hash_file, my_weights_fpath_, hasher='sha1', blocksize=blocksize).min())
ydatas['sha256'].append(ub.Timerit(2).call(ub.hash_file, my_weights_fpath_, hasher='sha256', blocksize=blocksize).min())
ydatas['sha512'].append(ub.Timerit(2).call(ub.hash_file, my_weights_fpath_, hasher='sha512', blocksize=blocksize).min())
ydatas['md5'].append(ub.Timerit(2).call(ub.hash_file, my_weights_fpath_, hasher='md5', blocksize=blocksize).min())
ydatas['xx32'].append(ub.Timerit(2).call(hash_file2, my_weights_fpath_, hasher='xx32', blocksize=blocksize).min())
ydatas['xx64'].append(ub.Timerit(2).call(hash_file2, my_weights_fpath_, hasher='xx64', blocksize=blocksize).min())
import netharn as nh
nh.util.qtensure()
nh.util.multi_plot(xdata, ydatas)
"""
import xxhash
if hasher == 'xx32':
hasher = xxhash.xxh32()
elif hasher == 'xx64':
hasher = xxhash.xxh64()
with open(fpath, 'rb') as file:
buf = file.read(blocksize)
# otherwise hash the entire file
while len(buf) > 0:
hasher.update(buf)
buf = file.read(blocksize)
# Get the hashed representation
text = ub.util_hash._digest_hasher(hasher, hashlen=None,
base=ub.util_hash.DEFAULT_ALPHABET)
return text
示例14: xxh64
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def xxh64(data):
storage_key = bytearray(xxhash.xxh64(data, seed=0).digest())
storage_key.reverse()
return "{}".format(storage_key.hex())
示例15: make_cache_stale_key
# 需要导入模块: import xxhash [as 别名]
# 或者: from xxhash import xxh64 [as 别名]
def make_cache_stale_key(self):
import xxhash, json
payload = b""
payload += json.dumps(self.spec).encode("utf8")
payload += self.updated.isoformat().encode("ascii")
return xxhash.xxh64(payload).hexdigest()