def parselinenos(spec, total):
 items = list()
 parts = spec.split(',')
 for part in parts:
  try:
   begend = part.strip().split('-')
   if (len(begend) > 2):
    raise ValueError
   if (len(begend) == 1):
    items.append((int(begend[0]) - 1))
   else:
    start = (((begend[0] == '') and 0) or (int(begend[0]) - 1))
    end = (((begend[1] == '') and total) or int(begend[1]))
    items.extend(xrange(start, end))
  except Exception:
   raise ValueError(('invalid line number spec: %r' % spec))
 return items

def parselinenos ( spec , total ) : items = list ( ) parts = spec . split ( ',' ) for part in parts : try : begend = part . strip ( ) . split ( '-' ) if ( len ( begend ) > 2 ) : raise ValueError if ( len ( begend ) == 1 ) : items . append ( ( int ( begend [ 0 ] ) - 1 ) ) else : start = ( ( ( begend [ 0 ] == '' ) and 0 ) or ( int ( begend [ 0 ] ) - 1 ) ) end = ( ( ( begend [ 1 ] == '' ) and total ) or int ( begend [ 1 ] ) ) items . extend ( xrange ( start , end ) ) except Exception : raise ValueError ( ( 'invalid line number spec: %r' % spec ) ) return items
parse a line number spec and return a list of wanted line numbers .