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,5 +1,4 @@
import base64
import binascii
import logging
import re
import time
@@ -45,10 +44,10 @@ DeviceToken = Union[PushDeviceToken, "RemotePushDeviceToken"]
# We store the token as b64, but apns-client wants hex strings
def b64_to_hex(data: str) -> str:
return binascii.hexlify(base64.b64decode(data)).decode('utf-8')
return base64.b64decode(data).hex()
def hex_to_b64(data: str) -> str:
return base64.b64encode(binascii.unhexlify(data)).decode()
return base64.b64encode(bytes.fromhex(data)).decode()
#
# Sending to APNs, for iOS