Пример #1
0
 def _convertErrors(reason):
     reason.trap(psycopg2.DatabaseError)
     exc_value = reason.value
     if getattr(exc_value, 'pgcode', None):
         exc_type = nerror.getExceptionFromCode(reason.value.pgcode)
         exc_value = exc_type(*exc_value.args)
         exc_value.err_code = reason.value.pgcode
         new = failure.Failure(exc_value, exc_type)
         new.frames = reason.frames
         new.stack = reason.stack
         return new
     return reason
Пример #2
0
 def _tryCall(self, func, *args, **kwargs):
     """
     Check that the transaction is ready, then execute C{func}. If
     an error is raised, flag the transaction as "in error" then
     re-raise so that further statements will not be executed.
     """
     self._txn().ready()
     try:
         try:
             return func(*args, **kwargs)
         except psycopg2.DatabaseError:
             e_type, e_value, e_tb = sys.exc_info()
             # Re-throw with our more specific types
             pgcode = getattr(e_value, 'pgcode', None)
             if pgcode:
                 new_type = error.getExceptionFromCode(e_value.pgcode)
             else:
                 new_type = error.DatabaseError
             new_value = new_type(*e_value.args)
             new_value.err_code = pgcode
             raise new_type, new_value, e_tb
     except:
         self._txn().setInError()
         raise