diff --git a/MySQLdb/MySQLdb/connections.py b/MySQLdb/MySQLdb/connections.py index 52128d6..92733e7 100644 --- a/MySQLdb/MySQLdb/connections.py +++ b/MySQLdb/MySQLdb/connections.py @@ -225,6 +225,14 @@ class Connection(_mysql.connection): """ return (cursorclass or self.cursorclass)(self) + def __enter__(self): return self.cursor() + + def __exit__(self, exc, value, tb): + if exc: + self.rollback() + else: + self.commit() + def literal(self, o): """ diff --git a/MySQLdb/setup.py b/MySQLdb/setup.py index 5561146..0957b9c 100644 --- a/MySQLdb/setup.py +++ b/MySQLdb/setup.py @@ -2,8 +2,8 @@ import os import sys -from distutils.core import setup -from distutils.extension import Extension +import ez_setup; ez_setup.use_setuptools() +from setuptools import setup, Extension if sys.version_info < (2, 3): raise Error, "Python-2.3 or newer is required"