mirror of https://github.com/zulip/zulip.git
camo: Clean up type ignores.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
9b392917c5
commit
bb5507009f
|
@ -1,5 +1,5 @@
|
|||
from django.conf import settings
|
||||
import codecs
|
||||
import binascii
|
||||
import hashlib
|
||||
import hmac
|
||||
|
||||
|
@ -7,7 +7,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 = codecs.encode(encoded_url, "hex") # type: ignore # https://github.com/python/typeshed/issues/300
|
||||
hex_encoded_url = binascii.b2a_hex(encoded_url)
|
||||
return "%s/%s" % (digest, hex_encoded_url.decode("utf-8"))
|
||||
|
||||
# Encodes the provided URL using the same algorithm used by the camo
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.http import (
|
|||
from zerver.lib.camo import is_camo_url_valid
|
||||
from zerver.lib.thumbnail import generate_thumbnail_url
|
||||
|
||||
import codecs
|
||||
import binascii
|
||||
|
||||
def handle_camo_url(request: HttpRequest, digest: str,
|
||||
received_url: str) -> HttpResponse:
|
||||
|
@ -15,8 +15,8 @@ def handle_camo_url(request: HttpRequest, digest: str,
|
|||
return HttpResponseNotFound()
|
||||
|
||||
hex_encoded_url = received_url.encode('utf-8')
|
||||
hex_decoded_url = codecs.decode(hex_encoded_url, 'hex')
|
||||
original_url = hex_decoded_url.decode('utf-8') # type: ignore # https://github.com/python/typeshed/issues/300
|
||||
hex_decoded_url = binascii.a2b_hex(hex_encoded_url)
|
||||
original_url = hex_decoded_url.decode('utf-8')
|
||||
if is_camo_url_valid(digest, original_url):
|
||||
return redirect(generate_thumbnail_url(original_url, is_camo_url=True))
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue