#NEWLINE# @ classmethod #NEWLINE# def change_by( cls , name , num ) : #NEWLINE# #INDENT# 'Change counter of ``name`` by ``num`` (can be negative).' #NEWLINE# count = cls . count ( name ) #NEWLINE# if ( ( count + num ) < 0 ) : #NEWLINE# #INDENT# raise CounterValueError ( ( 'Counter[%s] will be negative after %+d.' % ( name , num ) ) ) #NEWLINE# #UNINDENT# counter = cls . collection . find_and_modify ( { #NEWLINE# #INDENT# 'name' : cls , #NEWLINE# #UNINDENT# } , { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'seq' : num , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } , new = True , upsert = True ) #NEWLINE# return counter [ 'seq' ]