mypy: Convert zerver/lib to use typing.Text.

This commit is contained in:
Robert Hönig
2016-12-21 12:17:53 +00:00
committed by showell
parent 654e8de5ba
commit 0917493588
37 changed files with 290 additions and 307 deletions

View File

@@ -1,8 +1,7 @@
from __future__ import absolute_import
import random
from six import text_type
from typing import Any, Dict, Optional, SupportsInt
from typing import Any, Dict, Optional, SupportsInt, Text
from zerver.models import PushDeviceToken, UserProfile
from zerver.models import get_user_profile_by_id
@@ -53,7 +52,7 @@ def get_apns_key(identifer):
class APNsMessage(object):
def __init__(self, user, tokens, alert=None, badge=None, sound=None,
category=None, **kwargs):
# type: (UserProfile, List[text_type], text_type, int, text_type, text_type, **Any) -> None
# type: (UserProfile, List[Text], Text, int, Text, Text, **Any) -> None
self.frame = Frame()
self.tokens = tokens
expiry = int(time.time() + 24 * 3600)
@@ -124,11 +123,11 @@ def num_push_devices_for_user(user_profile, kind = None):
# We store the token as b64, but apns-client wants hex strings
def b64_to_hex(data):
# type: (bytes) -> text_type
# type: (bytes) -> Text
return binascii.hexlify(base64.b64decode(data)).decode('utf-8')
def hex_to_b64(data):
# type: (text_type) -> bytes
# type: (Text) -> bytes
return base64.b64encode(binascii.unhexlify(data.encode('utf-8')))
def _do_push_to_apns_service(user, message, apns_connection):
@@ -145,7 +144,7 @@ def _do_push_to_apns_service(user, message, apns_connection):
# mobile app
@statsd_increment("apple_push_notification")
def send_apple_push_notification(user, alert, **extra_data):
# type: (UserProfile, text_type, **Any) -> None
# type: (UserProfile, Text, **Any) -> None
if not connection and not dbx_connection:
logging.error("Attempting to send push notification, but no connection was found. "
"This may be because we could not find the APNS Certificate file.")