mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 03:41:53 +02:00
bugfixes & minimalism
This commit is contained in:
+9
-8
@@ -1,10 +1,11 @@
|
|||||||
"""ACME client API."""
|
"""ACME client API."""
|
||||||
import collections
|
import collections
|
||||||
import datetime
|
|
||||||
import heapq
|
import heapq
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six.moves import http_client # pylint: disable=import-error
|
from six.moves import http_client # pylint: disable=import-error
|
||||||
|
|
||||||
@@ -259,13 +260,12 @@ class Client(object): # pylint: disable=too-many-instance-attributes
|
|||||||
:rtype: `datetime.datetime`
|
:rtype: `datetime.datetime`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
retry_after = response.headers.get('Retry-After', str(default))
|
retry_after = response.headers.get('Retry-After', str(default)).strip()
|
||||||
now = datetime.datetime.now()
|
|
||||||
try:
|
try:
|
||||||
seconds = int(retry_after)
|
seconds = int(retry_after)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
t = list(parsedate_tz(value.strip())) # returns None on fail
|
t = list(parsedate_tz(retry_after))
|
||||||
try:
|
try:
|
||||||
year = t[0] # raises TypeError if t is None
|
year = t[0] # raises TypeError if t is None
|
||||||
# Handle two-digit years -- but any webserver that thinks
|
# Handle two-digit years -- but any webserver that thinks
|
||||||
@@ -273,11 +273,12 @@ class Client(object): # pylint: disable=too-many-instance-attributes
|
|||||||
if year >= 0 and year < 100:
|
if year >= 0 and year < 100:
|
||||||
t[0] = year + 2000
|
t[0] = year + 2000
|
||||||
tz = t[-1] if t[-1] else 0
|
tz = t[-1] if t[-1] else 0
|
||||||
return datetime(*t) - timedelta(tz) # raises Value/OverflowError
|
# raises ValueError/OverflowError
|
||||||
|
return datetime(*t) - timedelta(tz)
|
||||||
except (TypeError, ValueError, OverflowError):
|
except (TypeError, ValueError, OverflowError):
|
||||||
seconds = default
|
seconds = default
|
||||||
|
|
||||||
return now + datetime.timedelta(seconds=seconds)
|
return datetime.now() + timedelta(seconds=seconds)
|
||||||
|
|
||||||
def poll(self, authzr):
|
def poll(self, authzr):
|
||||||
"""Poll Authorization Resource for status.
|
"""Poll Authorization Resource for status.
|
||||||
@@ -369,7 +370,7 @@ class Client(object): # pylint: disable=too-many-instance-attributes
|
|||||||
|
|
||||||
# priority queue with datetime (based on Retry-After) as key,
|
# priority queue with datetime (based on Retry-After) as key,
|
||||||
# and original Authorization Resource as value
|
# and original Authorization Resource as value
|
||||||
waiting = [(datetime.datetime.now(), authzr) for authzr in authzrs]
|
waiting = [(datetime.now(), authzr) for authzr in authzrs]
|
||||||
# mapping between original Authorization Resource and the most
|
# mapping between original Authorization Resource and the most
|
||||||
# recently updated one
|
# recently updated one
|
||||||
updated = dict((authzr, authzr) for authzr in authzrs)
|
updated = dict((authzr, authzr) for authzr in authzrs)
|
||||||
@@ -377,7 +378,7 @@ class Client(object): # pylint: disable=too-many-instance-attributes
|
|||||||
while waiting:
|
while waiting:
|
||||||
# find the smallest Retry-After, and sleep if necessary
|
# find the smallest Retry-After, and sleep if necessary
|
||||||
when, authzr = heapq.heappop(waiting)
|
when, authzr = heapq.heappop(waiting)
|
||||||
now = datetime.datetime.now()
|
now = datetime.now()
|
||||||
if when > now:
|
if when > now:
|
||||||
seconds = (when - now).seconds
|
seconds = (when - now).seconds
|
||||||
logger.debug('Sleeping for %d seconds', seconds)
|
logger.debug('Sleeping for %d seconds', seconds)
|
||||||
|
|||||||
Reference in New Issue
Block a user