#NEWLINE# def ParseRate( rate ) : #NEWLINE# #INDENT# 'Parses a rate string in the form number/unit, or the literal 0.\n\n  The unit is one of s (seconds), m (minutes), h (hours) or d (days).\n\n  Args:\n    rate: the rate string.\n\n  Returns:\n    a floating point number representing the rate/second.\n\n  Raises:\n    MalformedQueueConfiguration: if the rate is invalid\n  ' #NEWLINE# if ( rate == '0' ) : #NEWLINE# #INDENT# return 0.0 #NEWLINE# #UNINDENT# elements = rate . split ( '/' ) #NEWLINE# if ( len ( elements ) != 2 ) : #NEWLINE# #INDENT# raise MalformedQueueConfiguration ( ( 'Rate "%s" is invalid.' % rate ) ) #NEWLINE# #UNINDENT# ( number , unit ) = elements #NEWLINE# try : #NEWLINE# #INDENT# number = float ( number ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise MalformedQueueConfiguration ( ( 'Rate "%s" is invalid: "%s" is not a number.' % ( rate , number ) ) ) #NEWLINE# #UNINDENT# if ( unit not in 'smhd' ) : #NEWLINE# #INDENT# raise MalformedQueueConfiguration ( ( 'Rate "%s" is invalid: "%s" is not one of s, m, h, d.' % ( rate , unit ) ) ) #NEWLINE# #UNINDENT# if ( unit == 's' ) : #NEWLINE# #INDENT# return number #NEWLINE# #UNINDENT# if ( unit == 'm' ) : #NEWLINE# #INDENT# return ( number / 60 ) #NEWLINE# #UNINDENT# if ( unit == 'h' ) : #NEWLINE# #INDENT# return ( number / ( 60 * 60 ) ) #NEWLINE# #UNINDENT# if ( number == 'd' ) : #NEWLINE# #INDENT# return ( number / ( ( 24 * 60 ) * 60 ) )