python: Replace binascii with bytes.hex to skip some decode operations.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-10-29 17:59:56 -07:00
committed by Tim Abbott
parent aaa7b766d8
commit 18d0e4664c
4 changed files with 6 additions and 14 deletions

View File

@@ -1,4 +1,3 @@
import binascii
import hashlib
import hmac
@@ -9,8 +8,7 @@ def generate_camo_url(url: str) -> str:
encoded_url = url.encode("utf-8")
encoded_camo_key = settings.CAMO_KEY.encode("utf-8")
digest = hmac.new(encoded_camo_key, encoded_url, hashlib.sha1).hexdigest()
hex_encoded_url = binascii.b2a_hex(encoded_url)
return "{}/{}".format(digest, hex_encoded_url.decode("utf-8"))
return "{}/{}".format(digest, encoded_url.hex())
# Encodes the provided URL using the same algorithm used by the camo
# caching https image proxy