# HG changeset patch # User RhodeCode Admin # Date 2023-03-28 08:22:23 # Node ID c1b8a600ac5e5c469ab74c18d881aa5240d830e7 # Parent 0838f6187a5d248f3842f1372daf4e85d80c2b85 channelstream: python3 fixes diff --git a/rhodecode/lib/channelstream.py b/rhodecode/lib/channelstream.py --- a/rhodecode/lib/channelstream.py +++ b/rhodecode/lib/channelstream.py @@ -19,7 +19,6 @@ # and proprietary license terms, please see https://rhodecode.com/licenses/ import os -import hashlib import itsdangerous import logging import requests @@ -32,6 +31,8 @@ import rhodecode.lib.helpers as h from rhodecode.lib.auth import HasRepoPermissionAny from rhodecode.lib.ext_json import json from rhodecode.model.db import User +from rhodecode.lib.str_utils import ascii_str +from rhodecode.lib.hash_utils import sha1_safe log = logging.getLogger(__name__) @@ -157,13 +158,13 @@ def parse_channels_info(info_result, inc user_state_dict = {} for userinfo in info_result['users']: user_state_dict[userinfo['user']] = { - k: v for k, v in userinfo['state'].items() + k: v for k, v in list(userinfo['state'].items()) if k in USER_STATE_PUBLIC_KEYS } channels_info = {} - for c_name, c_info in info_result['channels'].items(): + for c_name, c_info in list(info_result['channels'].items()): if c_name not in include_channel_info: continue connected_list = [] @@ -179,9 +180,9 @@ def parse_channels_info(info_result, inc def log_filepath(history_location, channel_name): - hasher = hashlib.sha256() - hasher.update(channel_name.encode('utf8')) - filename = '{}.log'.format(hasher.hexdigest()) + + channel_hash = ascii_str(sha1_safe(channel_name)) + filename = f'{channel_hash}.log' filepath = os.path.join(history_location, filename) return filepath @@ -226,7 +227,7 @@ def write_history(config, message): def get_connection_validators(registry): validators = [] - for k, config in registry.rhodecode_plugins.items(): + for k, config in list(registry.rhodecode_plugins.items()): validator = config.get('channelstream', {}).get('connect_validator') if validator: validators.append(validator) @@ -340,7 +341,7 @@ def comment_channelstream_push(request, comment_data = kwargs.pop('comment_data', {}) user_data = kwargs.pop('user_data', {}) - comment_id = comment_data.keys()[0] if comment_data else '' + comment_id = list(comment_data.keys())[0] if comment_data else '' message = '{} {} #{}'.format( user.username,