mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
Always give hashlib.sha1 and friends bytes.
This fixes an experienced bug where you couldn't subscribe to a stream with non-ASCII characters (failing with a UnicodeEncodeError), as well as many other potential bugs. (imported from commit f084a4b4b597b85935655097a7b5a163811c4d71)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import hashlib
|
||||
from time import sleep
|
||||
|
||||
# Runs the callback with slices of all_list of a given batch_size
|
||||
@@ -21,3 +22,11 @@ def run_in_batches(all_list, batch_size, callback, sleep_time = 0, logger = None
|
||||
|
||||
if i != limit - 1:
|
||||
sleep(sleep_time)
|
||||
|
||||
def make_safe_digest(string, hash_func=hashlib.sha1):
|
||||
"""
|
||||
return a hex digest of `string`.
|
||||
"""
|
||||
# hashlib.sha1, md5, etc. expect bytes, so non-ASCII strings must
|
||||
# be encoded.
|
||||
return hash_func(string.encode('utf-8')).hexdigest()
|
||||
|
||||
Reference in New Issue
Block a user