<s> from django . core . paginator import Paginator , EmptyPage , PageNotAnInteger <EOL> def paginate ( request , products , num = None ) : <EOL> paginator = Paginator ( products , num if num else <NUM_LIT> ) <EOL> try : <EOL> products = paginator . page ( request . GET . get ( '<STR_LIT>' ) ) <EOL> except PageNotAnInteger : <EOL> products = paginator . page ( <NUM_LIT:1> ) <EOL> except EmptyPage : <EOL> products = paginator . page ( paginator . num_pages ) <EOL> return products </s>
