'Extract the delay from the retry-after header.
This supports both integer and HTTP date formatted retry-after headers
per RFC 2616.
:param resp: The response containing the retry-after headers
:rtype: int
:return: The delay in seconds, clamped to be at least 1 second
:raises ValueError: On failing to parse the delay'

def _get_retry_after_delay(self, resp):

    delay = None
    try:
        delay = int(resp['retry-after'])
    except (ValueError, KeyError):
        pass
    try:
        retry_timestamp = self._parse_http_date(resp['retry-after'])
        date_timestamp = self._parse_http_date(resp['date'])
        delay = int((retry_timestamp - date_timestamp))
    except (ValueError, OverflowError, KeyError):
        pass
    if (delay is None):
        raise ValueError(('Failed    to    parse    retry-after    header    %r    as    either    int    or    HTTP-date.' % resp.get('retry-after')))
    return max(1, delay)
