#NEWLINE# def parse_duration( duration ) : #NEWLINE# #INDENT# index = 0 #NEWLINE# if ( duration [ 0 ] == '-' ) : #NEWLINE# #INDENT# sign = '-' #NEWLINE# index += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sign = '+' #NEWLINE# #UNINDENT# assert ( duration [ index ] == 'P' ) #NEWLINE# index += 1 #NEWLINE# dic = dict ( [ ( typ , 0 ) for ( code , typ ) in D_FORMAT ] ) #NEWLINE# for ( code , typ ) in D_FORMAT : #NEWLINE# #INDENT# if ( duration [ index ] == '-' ) : #NEWLINE# #INDENT# raise TimeUtilError ( 'Negation not allowed on individual items' ) #NEWLINE# #UNINDENT# if ( code == 'T' ) : #NEWLINE# #INDENT# if ( duration [ index ] == 'T' ) : #NEWLINE# #INDENT# index += 1 #NEWLINE# if ( index == len ( duration ) ) : #NEWLINE# #INDENT# raise TimeUtilError ( "Not allowed to end with 'T'" ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise TimeUtilError ( 'Missing T' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# mod = duration [ index : ] . index ( code ) #NEWLINE# try : #NEWLINE# #INDENT# dic [ typ ] = int ( duration [ index : ( index + mod ) ] ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# if ( code == 'S' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# dic [ typ ] = float ( duration [ index : ( index + mod ) ] ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise TimeUtilError ( 'Not a float' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise TimeUtilError ( 'Fractions not allow on anything byt seconds' ) #NEWLINE# #UNINDENT# #UNINDENT# index = ( ( mod + index ) + 1 ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# dic [ typ ] = 0 #NEWLINE# #UNINDENT# #UNINDENT# if ( index == len ( duration ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# return ( sign , dic )