From: Hong Minhee Date: Fri, 12 Apr 2013 19:26:24 +0000 (+0900) Subject: Make exec to work on both 2 and 3 X-Git-Tag: rel_0_6_0~22^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34b3aaf7e68fe9edfa9bc06ff033fec1c97c09ed;p=thirdparty%2Fsqlalchemy%2Falembic.git Make exec to work on both 2 and 3 --- diff --git a/alembic/util.py b/alembic/util.py index 826247f6..c7c3784a 100644 --- a/alembic/util.py +++ b/alembic/util.py @@ -1,5 +1,9 @@ from __future__ import with_statement +try: + import builtins +except ImportError: + import __builtin__ as builtins import sys import os import textwrap @@ -114,7 +118,13 @@ def create_module_class_proxy(cls, globals_, locals_): 'doc': fn.__doc__, }) lcl = {} - exec func_text in globals_, lcl + try: + exec_ = getattr(builtins, 'exec') + except AttributeError: + # Python 2 + def exec_(func_text, globals_, lcl): + exec('exec func_text in globals_, lcl') + exec_(func_text, globals_, lcl) return lcl[name] for methname in dir(cls):