#NEWLINE# def _parse_range_value( range_value ) : #NEWLINE# #INDENT# 'Parses a single range value from a Range header.\n\n  Parses strings of the form "0-0", "0-", "0" and "-1" into (start, end) tuples,\n  respectively, (0, 0), (0, None), (0, None), (-1, None).\n\n  Args:\n    range_value: A str containing a single range of a Range header.\n\n  Returns:\n    A tuple containing (start, end) where end is None if the range only has a\n    start value.\n\n  Raises:\n    ValueError: If range_value is not a valid range.\n  ' #NEWLINE# end = None #NEWLINE# if range_value . startswith ( '-' ) : #NEWLINE# #INDENT# start = int ( range_value ) #NEWLINE# if ( start == 0 ) : #NEWLINE# #INDENT# raise ValueError ( '-0 is not a valid range.' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# split_range = range_value . split ( '-' , 1 ) #NEWLINE# start = int ( split_range [ 0 ] ) #NEWLINE# if ( ( len ( split_range ) > 1 ) and split_range [ 1 ] . strip ( ) ) : #NEWLINE# #INDENT# end = int ( split_range [ 1 ] ) #NEWLINE# if ( start > end ) : #NEWLINE# #INDENT# raise ValueError ( 'start must be <= end.' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ( start , end )