i have noticed when using python gnupg, that if i sign some data and save the signed data to a file using pickle, lots of data gets saved along with the signed data. one of these things is a timestamp in unix time, for example the following line is part of a timestamp:
p24
sS'timestamp'
p25
V1347364912
the documentation does not mention any of this, which makes me a little confused. after loading in the file using pickle, i can't see any mention of the timestamp or any way to return the value. but if pickle is saving it, it must be part of the python object. does this mean there should be a way i can get to this information in python? i would also like to utilise this data, which i can maybe do by reading in the file itself but am looking for a cleaner way to do it using the gnupg module.
gnupg isn't very well documented but if you Inspect it you will see there are attributes besides the ones normally used...
#234567891123456789212345678931234567894123456789512345678961234567897123456789
# core
import inspect
import pickle
import datetime
# 3rd party
import gnupg
def depickle():
""" pull and depickle our signed data """
f = open('pickle.txt', 'r')
signed_data = pickle.load(f)
f.close()
return signed_data
# depickle our signed data
signed_data = depickle()
# inspect the object
for key, value in inspect.getmembers(signed_data):
print key
One of them is your timestamp... aptly named timestamp. Now that you know it you can use it easily enough...
# use the attribute now that we know it
print signed_data.timestamp
# make it pretty
print datetime.datetime.fromtimestamp(float(signed_data.timestamp))
That felt long winded but I thought this discussion would benefit from documenting the use of inspect to identify the undocumented attributes instead of just saying "use signed_data.timestamp".