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 33 34 35 36
|
"""
Standardized serialization code.
"""
from hashlib import md5
_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
def timestamp(dt):
"""
Convert a UTC datetime to a string.
@param dt: A C{datetime.datetime} in UTC timezone.
@return: C{unicode}
"""
return dt.strftime(_TIME_FORMAT)
def identity(value):
"""
Return the passed in object.
"""
return value
def md5hex(data):
"""
Return hex MD5 of the input bytes.
@param data: Some C{bytes}.
@return: Hex-encoded MD5 of the data.
"""
return md5(data).hexdigest()
|