# HG changeset patch # User RhodeCode Admin # Date 2023-07-18 09:04:35 # Node ID 0a4c18928ecac2689a5a873dcd3468447af25629 # Parent f62624b047eb7eb8ccb6eb5ac0c3b2bc494e04f1 subscribers: optimized used of threadglobals and fix python3 compat diff --git a/rhodecode/subscribers.py b/rhodecode/subscribers.py --- a/rhodecode/subscribers.py +++ b/rhodecode/subscribers.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (C) 2010-2020 RhodeCode GmbH # @@ -30,7 +29,6 @@ import subprocess from dateutil.parser import parse -from pyramid.threadlocal import get_current_request from pyramid.interfaces import IRoutesMapper from pyramid.settings import asbool from pyramid.path import AssetResolver @@ -38,6 +36,7 @@ from threading import Thread from rhodecode.config.jsroutes import generate_jsroutes_content from rhodecode.lib.base import get_auth_user +from rhodecode.lib.celerylib.loader import set_celery_conf import rhodecode @@ -50,6 +49,7 @@ def add_renderer_globals(event): # TODO: When executed in pyramid view context the request is not available # in the event. Find a better solution to get the request. + from pyramid.threadlocal import get_current_request request = event['request'] or get_current_request() # Add Pyramid translation as '_' to context @@ -70,7 +70,6 @@ def set_user_lang(event): def update_celery_conf(event): - from rhodecode.lib.celerylib.loader import set_celery_conf log.debug('Setting celery config from new request') set_celery_conf(request=event.request, registry=event.request.registry) @@ -79,6 +78,7 @@ def add_request_user_context(event): """ Adds auth user into request context """ + request = event.request # access req_id as soon as possible req_id = request.req_id @@ -307,7 +307,7 @@ def write_js_routes_if_enabled(event): static_path, 'js', 'rhodecode', 'routes.js') try: - with io.open(jsroutes_file_path, 'w', encoding='utf-8') as f: + with open(jsroutes_file_path, 'w', encoding='utf-8') as f: f.write(jsroutes_file_content) except Exception: log.exception('Failed to write routes.js into %s', jsroutes_file_path)