apns.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:universal_notifications 作者: ArabellaTech 项目源码 文件源码
def _apns_create_socket(address_tuple, app_id):
    app_settings = get_app_settings(app_id)
    if not app_settings:
        raise ImproperlyConfigured('You need to set UNIVERSAL_NOTIFICATIONS_MOBILE_APPS[app_id]'
                                   ' to send messages through APNS')

    certfile = app_settings.get("APNS_CERTIFICATE")
    if not certfile:
        raise ImproperlyConfigured(
            'You need to set UNIVERSAL_NOTIFICATIONS_MOBILE_APPS[app_id]["APNS_CERTIFICATE"] '
            'to send messages through APNS.'
        )

    try:
        with open(certfile, "r") as f:
            f.read()
    except Exception as e:
        raise ImproperlyConfigured("The APNS certificate file at %r is not readable: %s" % (certfile, e))

    sock = socket.socket()
    sock = ssl.wrap_socket(sock, ssl_version=ssl.PROTOCOL_TLSv1, certfile=certfile)
    sock.connect(address_tuple)

    return sock
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号