def tm_tween(request): if 'repoze.tm.active' in request.environ: # don't handle txn mgmt if repoze.tm is in the WSGI pipeline return handler(request) if activate is not None: if not activate(request): return handler(request) manager = getattr(request, 'tm', None) if manager is None: # pragma: no cover (pyramid < 1.4) manager = create_tm(request) request.tm = manager number = attempts if annotate_user: if hasattr(request, 'unauthenticated_userid'): userid = request.unauthenticated_userid else: # pragma no cover (for pyramid < 1.5) from pyramid.security import unauthenticated_userid userid = unauthenticated_userid(request) else: userid = None while number: number -= 1 try: manager.begin() # make_body_seekable will copy wsgi.input if necessary, # otherwise it will rewind the copy to position zero if attempts != 1: request.make_body_seekable() t = manager.get() if userid: userid = native_(userid, 'utf-8') t.setUser(userid, '') try: t.note(native_(request.path_info, 'utf-8')) except UnicodeDecodeError: t.note("Unable to decode path as unicode") response = handler(request) if manager.isDoomed(): raise AbortResponse(response) if commit_veto is not None: veto = commit_veto(request, response) if veto: raise AbortResponse(response) manager.commit() return response except AbortResponse as e: manager.abort() return e.response except: exc_info = sys.exc_info() try: retryable = manager._retryable(*exc_info[:-1]) manager.abort() if (number <= 0) or (not retryable): reraise(*exc_info) finally: del exc_info # avoid leak
def tm_tween(request): if 'repoze.tm.active' in request.environ: # don't handle txn mgmt if repoze.tm is in the WSGI pipeline return handler(request) manager = transaction.manager number = attempts if hasattr(request, 'unauthenticated_userid'): userid = request.unauthenticated_userid else: #pragma NO COVER deprecated from pyramid.security import unauthenticated_userid userid = unauthenticated_userid(request) while number: number -= 1 try: manager.begin() # make_body_seekable will copy wsgi.input if necessary, # otherwise it will rewind the copy to position zero if attempts != 1: request.make_body_seekable() t = manager.get() if userid: t.setUser(userid, '') try: t.note(request.path_info) except UnicodeDecodeError: t.note("Unable to decode path as unicode") response = handler(request) if manager.isDoomed(): raise AbortResponse(response) if commit_veto is not None: veto = commit_veto(request, response) if veto: raise AbortResponse(response) manager.commit() return response except AbortResponse: e = sys.exc_info()[1] # py2.5-py3 compat manager.abort() return e.response except: exc_info = sys.exc_info() try: retryable = manager._retryable(*exc_info[:-1]) manager.abort() if (number <= 0) or (not retryable): reraise(*exc_info) finally: del exc_info # avoid leak
def tm_tween(request): if 'repoze.tm.active' in request.environ: # don't handle txn mgmt if repoze.tm is in the WSGI pipeline return handler(request) manager = transaction.manager number = attempts userid = unauthenticated_userid(request) while number: number -= 1 try: manager.begin() # make_body_seekable will copy wsgi.input if necessary, # otherwise it will rewind the copy to position zero if attempts != 1: request.make_body_seekable() t = manager.get() t.setUser(userid, '') t.note(request.path_info) response = handler(request) if manager.isDoomed(): raise AbortResponse(response) if commit_veto is not None: veto = commit_veto(request, response) if veto: raise AbortResponse(response) manager.commit() return response except AbortResponse: e = sys.exc_info()[1] # py2.5-py3 compat manager.abort() return e.response except: exc_info = sys.exc_info() try: manager.abort() retryable = manager._retryable(*exc_info[:-1]) if (number <= 0) or (not retryable): reraise(*exc_info) finally: del exc_info # avoid leak