server/session.py
changeset 10589 7c23b7de2b8d
parent 10541 03bae22c8d0e
child 10663 54b8a1f249fb
equal deleted inserted replaced
10588:fdaa0e4b7eaf 10589:7c23b7de2b8d
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """Repository users' and internal' sessions."""
    18 """Repository users' and internal' sessions."""
       
    19 from __future__ import print_function
       
    20 
    19 __docformat__ = "restructuredtext en"
    21 __docformat__ = "restructuredtext en"
    20 
    22 
    21 import sys
    23 import sys
    22 from time import time
    24 from time import time
    23 from uuid import uuid4
    25 from uuid import uuid4
   872             # by default, operations are executed with security turned off
   874             # by default, operations are executed with security turned off
   873             with self.security_enabled(False, False):
   875             with self.security_enabled(False, False):
   874                 processed = []
   876                 processed = []
   875                 self.commit_state = 'precommit'
   877                 self.commit_state = 'precommit'
   876                 if debug:
   878                 if debug:
   877                     print self.commit_state, '*' * 20
   879                     print(self.commit_state, '*' * 20)
   878                 try:
   880                 try:
   879                     with self.running_hooks_ops():
   881                     with self.running_hooks_ops():
   880                         while self.pending_operations:
   882                         while self.pending_operations:
   881                             operation = self.pending_operations.pop(0)
   883                             operation = self.pending_operations.pop(0)
   882                             operation.processed = 'precommit'
   884                             operation.processed = 'precommit'
   883                             processed.append(operation)
   885                             processed.append(operation)
   884                             if debug:
   886                             if debug:
   885                                 print operation
   887                                 print(operation)
   886                             operation.handle_event('precommit_event')
   888                             operation.handle_event('precommit_event')
   887                     self.pending_operations[:] = processed
   889                     self.pending_operations[:] = processed
   888                     self.debug('precommit transaction %s done', self.connectionid)
   890                     self.debug('precommit transaction %s done', self.connectionid)
   889                 except BaseException:
   891                 except BaseException:
   890                     # if error on [pre]commit:
   892                     # if error on [pre]commit:
   897                     # for processed operations, and allow generic rollback
   899                     # for processed operations, and allow generic rollback
   898                     # instead of having to implements rollback, revertprecommit
   900                     # instead of having to implements rollback, revertprecommit
   899                     # and revertcommit, that will be enough in mont case.
   901                     # and revertcommit, that will be enough in mont case.
   900                     operation.failed = True
   902                     operation.failed = True
   901                     if debug:
   903                     if debug:
   902                         print self.commit_state, '*' * 20
   904                         print(self.commit_state, '*' * 20)
   903                     with self.running_hooks_ops():
   905                     with self.running_hooks_ops():
   904                         for operation in reversed(processed):
   906                         for operation in reversed(processed):
   905                             if debug:
   907                             if debug:
   906                                 print operation
   908                                 print(operation)
   907                             try:
   909                             try:
   908                                 operation.handle_event('revertprecommit_event')
   910                                 operation.handle_event('revertprecommit_event')
   909                             except BaseException:
   911                             except BaseException:
   910                                 self.critical('error while reverting precommit',
   912                                 self.critical('error while reverting precommit',
   911                                               exc_info=True)
   913                                               exc_info=True)
   915                     self.rollback()
   917                     self.rollback()
   916                     raise
   918                     raise
   917                 self.cnxset.commit()
   919                 self.cnxset.commit()
   918                 self.commit_state = 'postcommit'
   920                 self.commit_state = 'postcommit'
   919                 if debug:
   921                 if debug:
   920                     print self.commit_state, '*' * 20
   922                     print(self.commit_state, '*' * 20)
   921                 with self.running_hooks_ops():
   923                 with self.running_hooks_ops():
   922                     while self.pending_operations:
   924                     while self.pending_operations:
   923                         operation = self.pending_operations.pop(0)
   925                         operation = self.pending_operations.pop(0)
   924                         if debug:
   926                         if debug:
   925                             print operation
   927                             print(operation)
   926                         operation.processed = 'postcommit'
   928                         operation.processed = 'postcommit'
   927                         try:
   929                         try:
   928                             operation.handle_event('postcommit_event')
   930                             operation.handle_event('postcommit_event')
   929                         except BaseException:
   931                         except BaseException:
   930                             self.critical('error while postcommit',
   932                             self.critical('error while postcommit',