@staticmethod<EOL><INDENT>def add_safety_check(member_name, member_value):<DEDENT>
import functools<EOL>from types import FunctionType<EOL>is_method = isinstance(member_value, FunctionType)<EOL>is_read_only = hasattr(member_value, '<STR_LIT>')<EOL>is_private = member_name.startswith('<STR_LIT:_>')<EOL>if not is_method or is_read_only or is_private:<EOL><INDENT>return member_value<EOL><DEDENT>def safety_checked_method(self, *args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>world = getattr(self, '<STR_LIT>', None)<EOL>if world and world.is_locked():<EOL><INDENT>nonlocal member_name<EOL>raise ApiUsageError("""<STR_LIT>""")<EOL><DEDENT>return member_value(self, *args, **kwargs)<EOL><DEDENT>functools.update_wrapper(<EOL>safety_checked_method, member_value,<EOL>assigned=functools.WRAPPER_ASSIGNMENTS + (<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>)<EOL>)<EOL>return safety_checked_method<EOL>
If the given member is a method that is public (i.e. doesn't start with 
an underscore) and hasn't been marked as read-only, replace it with a 
version that will check to make sure the world is locked.  This ensures 
that methods that alter the token are only called from update methods 
or messages.