def ParseRangeHeader(range_header):
 if (not range_header):
  return (None, None)
 try:
  (range_type, ranges) = range_header.split('=', 1)
  if (range_type != 'bytes'):
   return (None, None)
  ranges = ranges.lstrip()
  if (',' in ranges):
   return (None, None)
  end = None
  if ranges.startswith('-'):
   start = int(ranges)
   if (start == 0):
    return (None, None)
  else:
   split_range = ranges.split('-', 1)
   start = int(split_range[0])
   if ((len(split_range) == 2) and split_range[1].strip()):
    end = (int(split_range[1]) + 1)
    if (start > end):
     return (None, None)
  return (start, end)
 except ValueError:
  return (None, None)

def ParseRangeHeader ( range_header ) : if ( not range_header ) : return ( None , None ) try : ( range_type , ranges ) = range_header . split ( '=' , 1 ) if ( range_type != 'bytes' ) : return ( None , None ) ranges = ranges . lstrip ( ) if ( ',' in ranges ) : return ( None , None ) end = None if ranges . startswith ( '-' ) : start = int ( ranges ) if ( start == 0 ) : return ( None , None ) else : split_range = ranges . split ( '-' , 1 ) start = int ( split_range [ 0 ] ) if ( ( len ( split_range ) == 2 ) and split_range [ 1 ] . strip ( ) ) : end = ( int ( split_range [ 1 ] ) + 1 ) if ( start > end ) : return ( None , None ) return ( start , end ) except ValueError : return ( None , None )
parse http range header .