#NEWLINE# def code_exec( self , code , extra_environ = None , debug = False ) : #NEWLINE# #INDENT# '\n        Execute a single code block, including imports and appending\n        global vars.\n\n        Args:\n            code (str): Code to run.\n            extra_environ (dict): Environment variables to run with code.\n            debug (bool, optional): Insert delete statements for objects.\n\n        Returns:\n            err (str or None): An error code or None (ok).\n\n        ' #NEWLINE# environdict = { #NEWLINE# #INDENT# 'settings_module' : settings , #NEWLINE# #UNINDENT# } #NEWLINE# environ = 'settings_module.configure()' #NEWLINE# if extra_environ : #NEWLINE# #INDENT# for ( key , value ) in extra_environ . items ( ) : #NEWLINE# #INDENT# environdict [ key ] = value #NEWLINE# #UNINDENT# #UNINDENT# code = ( '# auto-added by Evennia\ntry: %s\nexcept RuntimeError: pass\nfinally: del settings_module\n%s' % ( environ , code ) ) #NEWLINE# try : #NEWLINE# #INDENT# exec ( code , environdict ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# ( etype , value , tb ) = sys . exc_info ( ) #NEWLINE# fname = tb_filename ( tb ) #NEWLINE# for tb in tb_iter ( tb ) : #NEWLINE# #INDENT# if ( fname != tb_filename ( tb ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# lineno = ( tb . tb_lineno - 1 ) #NEWLINE# err = '' #NEWLINE# for ( iline , line ) in enumerate ( code . split ( '\n' ) ) : #NEWLINE# #INDENT# if ( iline == lineno ) : #NEWLINE# #INDENT# err += ( '\n{w%02i{n: %s' % ( ( tb + 1 ) , line ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( lineno - 5 ) < iline < ( lineno + 5 ) ) : #NEWLINE# #INDENT# err += ( '\n%02i: %s' % ( ( iline + 1 ) , line ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# err += '\n' . join ( traceback . format_exception ( etype , value , tb ) ) #NEWLINE# return err #NEWLINE# #UNINDENT# return None