'Poll and request issuance.
This function polls all provided Authorization Resource URIs
until all challenges are valid, respecting ``Retry-After`` HTTP
headers, and then calls `request_issuance`.
:param .ComparableX509 csr: CSR (`OpenSSL.crypto.X509Req`
wrapped in `.ComparableX509`)
:param authzrs: `list` of `.AuthorizationResource`
:param int mintime: Minimum time before next attempt, used if
``Retry-After`` is not present in the response.
:param int max_attempts: Maximum number of attempts (per
authorization) before `PollError` with non-empty ``waiting``
is raised.
:returns: ``(cert, updated_authzrs)`` `tuple` where ``cert`` is
the issued certificate (`.messages.CertificateResource`),
and ``updated_authzrs`` is a `tuple` consisting of updated
Authorization Resources (`.AuthorizationResource`) as
present in the responses from server, and in the same order
as the input ``authzrs``.
:rtype: `tuple`
:raises PollError: in case of timeout or if some authorization
was marked by the CA as invalid'

def poll_and_request_issuance(self, csr, authzrs, mintime=5, max_attempts=10):

    assert (max_attempts > 0)
    attempts = collections.defaultdict(int)
    exhausted = set()
    waiting = [(datetime.datetime.now(), index, authzr) for (index, authzr) in enumerate(authzrs)]
    heapq.heapify(waiting)
    updated = dict(((authzr, authzr) for authzr in authzrs))
    while waiting:
        (when, index, authzr) = heapq.heappop(waiting)
        now = datetime.datetime.now()
        if (when > now):
            seconds = (when - now).seconds
            logger.debug('Sleeping    for    %d    seconds', seconds)
            time.sleep(seconds)
        (updated_authzr, response) = self.poll(updated[authzr])
        updated[authzr] = updated_authzr
        attempts[authzr] += 1
        if (updated_authzr.body.status not in (messages.STATUS_VALID, messages.STATUS_INVALID)):
            if (attempts[authzr] < max_attempts):
                heapq.heappush(waiting, (self.retry_after(response, default=mintime), index, authzr))
            else:
                exhausted.add(authzr)
    if (exhausted or any(((authzr.body.status == messages.STATUS_INVALID) for authzr in six.itervalues(updated)))):
        raise errors.PollError(exhausted, updated)
    updated_authzrs = tuple((updated[authzr] for authzr in authzrs))
    return (self.request_issuance(csr, updated_authzrs), updated_authzrs)
