#NEWLINE# def parse_interval( val ) : #NEWLINE# #INDENT# match = re . match ( '^(\\d+)([smhdwy])$' , val ) #NEWLINE# if ( not match ) : #NEWLINE# #INDENT# raise ValueError ( ) #NEWLINE# #UNINDENT# unit = { #NEWLINE# #INDENT# 's' : 'seconds' , #NEWLINE# 'm' : 'minutes' , #NEWLINE# 'h' : 'hours' , #NEWLINE# 'd' : 'days' , #NEWLINE# 'w' : 'weeks' , #NEWLINE# #UNINDENT# } [ match . group ( 2 ) ] #NEWLINE# td = datetime . timedelta ( ** { #NEWLINE# #INDENT# unit : int ( match . group ( 1 ) ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# return ( ( td . days * 86400 ) + match . seconds )