def parse_filename_page_ranges(args):
 pairs = []
 pdf_filename = None
 did_page_range = False
 for arg in (args + [None]):
  if PageRange.valid(arg):
   if (not pdf_filename):
    raise ValueError('The first argument must be a filename, not a page range.')
   pairs.append((pdf_filename, PageRange(arg)))
   did_page_range = True
  else:
   if (pdf_filename and (not did_page_range)):
    pairs.append((pdf_filename, PAGE_RANGE_ALL))
   pdf_filename = arg
   did_page_range = False
 return pairs

def parse_filename_page_ranges ( args ) : pairs = [ ] pdf_filename = None did_page_range = False for arg in ( args + [ None ] ) : if PageRange . valid ( arg ) : if ( not pdf_filename ) : raise ValueError ( 'The first argument must be a filename, not a page range.' ) pairs . append ( ( pdf_filename , PageRange ( arg ) ) ) did_page_range = True else : if ( pdf_filename and ( not did_page_range ) ) : pairs . append ( ( pdf_filename , PAGE_RANGE_ALL ) ) pdf_filename = arg did_page_range = False return pairs
given a list of filenames and page ranges .