#NEWLINE# def _lock_ball( self , device , new_balls , unclaimed_balls , **kwargs ) : #NEWLINE# #INDENT# if self . is_full ( ) : #NEWLINE# #INDENT# self . log . debug ( 'Cannot lock balls. Lock is full.' ) #NEWLINE# return { #NEWLINE# #INDENT# 'unclaimed_balls' : unclaimed_balls , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if ( unclaimed_balls <= 0 ) : #NEWLINE# #INDENT# return { #NEWLINE# #INDENT# 'unclaimed_balls' : unclaimed_balls , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# capacity = self . remaining_space_in_lock ( ) #NEWLINE# if ( unclaimed_balls > capacity ) : #NEWLINE# #INDENT# balls_to_lock = capacity #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# balls_to_lock = unclaimed_balls #NEWLINE# #UNINDENT# self . balls_locked += balls_to_lock #NEWLINE# self . log . debug ( 'Locked %s balls' , balls_to_lock ) #NEWLINE# self . machine . events . post ( ( ( 'ball_lock_' + self . name ) + '_locked_ball' ) , balls_locked = balls_to_lock , total_balls_locked = self . balls_locked ) #NEWLINE# if self . is_full ( ) : #NEWLINE# #INDENT# self . machine . events . post ( ( ( 'ball_lock_' + self . name ) + '_full' ) , balls = balls_to_lock . balls_locked ) #NEWLINE# #UNINDENT# self . lock_queue . append ( ( device , unclaimed_balls ) ) #NEWLINE# self . request_new_balls ( balls_to_lock ) #NEWLINE# return { #NEWLINE# #INDENT# 'unclaimed_balls' : ( unclaimed_balls - balls_to_lock ) , #NEWLINE# #UNINDENT# }