Skip to content

Commit

Permalink
Extract method for getting exception wrapper in backward compatible m…
Browse files Browse the repository at this point in the history
…anner
  • Loading branch information
rudyryk committed Mar 5, 2017
1 parent c00cb3c commit 6c0880f
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions peewee_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
logger = logging.getLogger('peewee.async')
logger.addHandler(logging.NullHandler())


def get_peewee_version_tuple():
return tuple([int(x) for x in peewee.__version__.split('.')])

PEEWEE_VERSION = get_peewee_version_tuple()
PEEWEE_VERSION = tuple([int(x) for x in peewee.__version__.split('.')])

try:
import aiopg
Expand Down Expand Up @@ -1484,18 +1480,23 @@ def __aexit__(self, exc_type, exc_val, exc_tb):
# Internal helpers #
####################

def _get_exception_wrapper(database):
"""Get peewee exceptions context manager for database
in backward compatible manner.
"""
if PEEWEE_VERSION <= (2, 8, 5):
return database.exception_wrapper()
else:
return database.exception_wrapper


@asyncio.coroutine
def _run_sql(database, operation, *args, **kwargs):
"""Run SQL operation (query or command) against database.
"""
logger.debug((operation, args, kwargs))

exception_wrapper = database.exception_wrapper
if PEEWEE_VERSION <= (2, 8, 5):
exception_wrapper = exception_wrapper()

with exception_wrapper:
with _get_exception_wrapper(database):
cursor = yield from database.cursor_async()

try:
Expand Down

0 comments on commit 6c0880f

Please sign in to comment.