<s> """<STR_LIT>""" <EOL> import logging <EOL> from kafka . partitioner . base import Partitioner <EOL> import monk . core . api as monkapi <EOL> from itertools import cycle <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> class UserPartitioner ( Partitioner ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , partitions = [ <NUM_LIT:0> ] ) : <EOL> """<STR_LIT>""" <EOL> self . _set_partition ( partitions ) <EOL> def _set_partition ( self , partitions ) : <EOL> self . partitions = partitions <EOL> if partitions : <EOL> self . iterpart = cycle ( partitions ) <EOL> else : <EOL> self . iterpart = cycle ( [ <NUM_LIT:0> ] ) <EOL> def partition ( self , key , partitions = None ) : <EOL> if partitions and self . partitions != partitions : <EOL> self . _set_partitions ( partitions ) <EOL> logger . debug ( '<STR_LIT>' . format ( key ) ) <EOL> user = monkapi . load_user ( key ) <EOL> if not user : <EOL> return self . iterpart . next ( ) <EOL> else : <EOL> return user . partition </s>
