#NEWLINE# def to_iso( obj ) : #NEWLINE# #INDENT# '\n    Converts datetime object to an ISO 8601 timestamp.\n    ' #NEWLINE# if ( isinstance ( obj , basestring ) or ( obj is None ) ) : #NEWLINE# #INDENT# return obj #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( obj , datetime ) : #NEWLINE# #INDENT# timestamp = obj . isoformat ( ) #NEWLINE# if ( ( '+' not in timestamp ) and ( len ( timestamp ) == 19 ) and ( not timestamp . endswith ( 'Z' ) ) ) : #NEWLINE# #INDENT# timestamp += 'Z' #NEWLINE# #UNINDENT# return timestamp #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( ( 'Unable to convert %s to an ISO 8601 timestampe.' % timestamp ) )