def get_ranges(headervalue, content_length):
 if (not headervalue):
  return None
 result = []
 (bytesunit, byteranges) = headervalue.split('=', 1)
 for brange in byteranges.split(','):
  (start, stop) = [x.strip() for x in brange.split('-', 1)]
  if start:
   if (not stop):
    stop = (content_length - 1)
   (start, stop) = (int(start), int(stop))
   if (start >= content_length):
    continue
   if (stop < start):
    return None
   result.append((start, (stop + 1)))
  else:
   if (not stop):
    return None
   result.append(((content_length - int(stop)), content_length))
 return result

def get_ranges ( headervalue , content_length ) : if ( not headervalue ) : return None result = [ ] ( bytesunit , byteranges ) = headervalue . split ( '=' , 1 ) for brange in byteranges . split ( ',' ) : ( start , stop ) = [ x . strip ( ) for x in brange . split ( '-' , 1 ) ] if start : if ( not stop ) : stop = ( content_length - 1 ) ( start , stop ) = ( int ( start ) , int ( stop ) ) if ( start >= content_length ) : continue if ( stop < start ) : return None result . append ( ( start , ( stop + 1 ) ) ) else : if ( not stop ) : return None result . append ( ( ( content_length - int ( stop ) ) , content_length ) ) return result
return a list of indices from a range header .