code: def compile_code(cls, code, filename=None, exec_namespace=None):
          
          if filename is None:
              if isinstance(code, SourceCode):
                  filename = code.sourcename
              else:
                  filename = "<string>"
  
          # compile
          try:
              if isinstance(code, SourceCode):
                  pyc = code.compiled
              else:
                  pyc = compile(code, filename, 'exec')
          except SourceCodeError as e:
              reraise(e, RexError)
          except Exception as e:
              stack = traceback.format_exc()
              raise RexError("Failed to compile %s:\n\n%s" % (filename, stack))
  
          error_class = Exception if config.catch_rex_errors else None
  
          # execute
          if exec_namespace is not None:
              try:
                  if isinstance(code, SourceCode):
                      code.exec_(globals_=exec_namespace)
                  else:
                      exec pyc in exec_namespace
              except RexError:
                  raise
              except SourceCodeError as e:
                  reraise(e, RexError)
              except error_class as e:
                  stack = traceback.format_exc()
                  raise RexError("Failed to exec %s:\n\n%s" % (filename, stack))
  
          return pyc
docs: Compile and possibly execute rex code.
  
          Args:
              code (str or SourceCode): The python code to compile.
              filename (str): File to associate with the code, will default to
                  '<string>'.
              exec_namespace (dict): Namespace to execute the code in. If None,
                  the code is not executed.
  
          Returns:
              Compiled code object.