1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
"""Generally useful utilities for AWS web services not specific to a service.
New things in this module should be of relevance to more than one of amazon's
services.
"""
__all__ = ['hmac_sha1', 'iso8601time']
from base64 import b64encode
from hashlib import sha1
import hmac
import time
# Import XML from somwhere; here in one place to prevent duplication.
try:
from xml.etree.ElementTree import XML
except ImportError:
from elementtree.ElementTree import XML
def hmac_sha1(secret, data):
digest = hmac.new(secret, data, sha1).digest()
return b64encode(digest)
def iso8601time(time_tuple):
"""Format time_tuple as a ISO8601 time string.
:param time_tuple: Either None, to use the current time, or a tuple tuple.
"""
if time_tuple:
return time.strftime("%Y-%m-%dT%H:%M:%SZ", time_tuple)
else:
return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
|