'Schedule an event for when the TLS certificate expires.'

def _cert_expiration(self, event):

    if ((not self.use_tls) and (not self.use_ssl)):
        return
    if (not self._der_cert):
        log.warn(u'TLS    or    SSL    was    enabled,    but    no    certificate    was    found.')
        return
    def restart():
        if (not self.event_handled(u'ssl_expired_cert')):
            log.warn(u'The    server    certificate    has    expired.    Restarting.')
            self.reconnect()
        else:
            pem_cert = ssl.DER_cert_to_PEM_cert(self._der_cert)
            self.event(u'ssl_expired_cert', pem_cert)
    cert_ttl = cert.get_ttl(self._der_cert)
    if (cert_ttl is None):
        return
    if (cert_ttl.days < 0):
        log.warn(u'CERT:    Certificate    has    expired.')
        restart()
    try:
        total_seconds = cert_ttl.total_seconds()
    except AttributeError:
        total_seconds = ((cert_ttl.microseconds + ((cert_ttl.seconds + ((cert_ttl.days * 24) * 3600)) * (10 ** 6))) / (10 ** 6))
    log.info((u'CERT:    Time    until    certificate    expiration:    %s' % cert_ttl))
    self.schedule(u'Certificate    Expiration', total_seconds, restart)
