Permalink
Browse files

Decorator needs to appear before annotations using it in py 2.4

  • Loading branch information...
1 parent 4ee0370 commit d26f98f06556cd2bb0dcd514c1c2b2afcc3e19bb @harryf committed Jun 30, 2008
Showing with 14 additions and 15 deletions.
  1. +14 −15 dammit/db_mysql.py
View
@@ -8,6 +8,19 @@
def todatetime(dt):
return time.strftime("%Y-%m-%d %H:%M:%S", dt.timetuple())
+def reconnect(func):
+ """
+ Decorator - reconnect and retry if we
+ get an OperationalError
+ """
+ def retry(self, *args, **kwargs):
+ try:
+ return func(self, *args, **kwargs)
+ except MySQLdb.OperationalError, e:
+ self._connect()
+ return func(self, *args, **kwargs)
+ return retry
+
class MySQL(object):
"""
MySQL backend support
@@ -285,21 +298,7 @@ def _store_pairs(self, cursor, uri, deletefirst = True):
VALUES ( %s, %s, %s)"""
for k, v in uri.pairs.items():
- cursor.execute(sql, (uri.id, k, v))
-
-def reconnect(func):
- """
- Decorator - reconnect and retry if we
- get an OperationalError
- """
- def retry(self, *args, **kwargs):
- try:
- return func(self, *args, **kwargs)
- except MySQLdb.OperationalError, e:
- self._connect()
- return func(self, *args, **kwargs)
- return retry
-
+ cursor.execute(sql, (uri.id, k, v))
def _test():
import doctest

0 comments on commit d26f98f

Please sign in to comment.