python3: removed more unicode usage

This commit is contained in:
RhodeCode Admin 2023-03-10 10:05:54 +01:00
parent 3731a4a02c
commit aab457fdca
21 changed files with 30 additions and 31 deletions

View file

@ -237,7 +237,7 @@ class TestAdminSettingsGlobal(object):
app_settings = SettingsModel().get_all_settings()
del settings['csrf_token']
for key, value in settings.items():
assert app_settings[key] == value.decode('utf-8')
assert app_settings[key] == value
return response

View file

@ -442,7 +442,7 @@ class AdminSettingsView(BaseAppView):
'repo_group/test_repo1', error_container=error_container)
if error_container:
def converter(inp):
return h.html_escape(unicode(inp))
return h.html_escape(inp)
return 'ERRORS: ' + '\n'.join(map(converter, error_container))

View file

@ -81,8 +81,6 @@ class SettingsMaker(object):
@classmethod
def _bool_func(cls, input_val):
if isinstance(input_val, str):
input_val = input_val.encode('utf8')
return str2bool(input_val)
@classmethod

View file

@ -273,7 +273,7 @@ class WerkzeugAdapter(BaseAdapter):
self.response = response
def write(self, value):
self.response.data = self.response.data.decode('utf-8') + value
self.response.data = self.response.data + value
def set_header(self, key, value):
self.response.headers[key] = value

View file

@ -1156,7 +1156,7 @@ class Response(ReprMixin):
if self.is_binary_string(content):
self._content = content
else:
self._content = content.decode('utf-8')
self._content = content
return self._content
@property

View file

@ -298,7 +298,7 @@ class OAuth2(providers.AuthorizationProvider):
# unquote Cast to str to void b64decode translation error. Base64
# should be str compatible.
return json.loads(base64.urlsafe_b64decode(
unquote(str(state))).decode('utf-8'))[param]
unquote(str(state))))[param]
else:
return state if param == 'csrf' else ''

View file

@ -156,7 +156,7 @@ class RhodeCodeSetting(Base, BaseModel):
@validates('_app_settings_value')
def validate_settings_value(self, key, val):
assert type(val) == unicode
assert type(val) == str
return val
@hybrid_property

View file

@ -178,7 +178,7 @@ class RhodeCodeSetting(Base, BaseModel):
@validates('_app_settings_value')
def validate_settings_value(self, key, val):
assert type(val) == unicode
assert type(val) == str
return val
@hybrid_property

View file

@ -57,7 +57,6 @@ def rfc2822_date(date):
month = months[date.month - 1]
time_str = date.strftime('%s, %%d %s %%Y %%H:%%M:%%S ' % (dow, month))
time_str = time_str.decode('utf-8')
offset = date.utcoffset()
# Historically, this function assumes that naive datetimes are in UTC.
if offset is None:
@ -73,7 +72,6 @@ def rfc3339_date(date):
date = datetime_safe.new_datetime(date)
time_str = date.strftime('%Y-%m-%dT%H:%M:%S')
time_str = time_str.decode('utf-8')
offset = date.utcoffset()
# Historically, this function assumes that naive datetimes are in UTC.
if offset is None:

View file

@ -1441,7 +1441,7 @@ def gravatar_url(email_address, size=30, request=None):
_use_gravatar = request.call_context.visual.use_gravatar
email_address = email_address or User.DEFAULT_USER_EMAIL
if isinstance(email_address, unicode):
if isinstance(email_address, str):
# hashlib crashes on unicode items
email_address = safe_str(email_address)

View file

@ -79,7 +79,7 @@ class HooksHttpHandler(BaseHTTPRequestHandler):
# support for new vcsserver msgpack based protocol hooks
data = msgpack.unpackb(self.rfile.read(length), raw=False)
else:
body = self.rfile.read(length).decode('utf-8')
body = self.rfile.read(length)
data = json.loads(body)
return hooks_proto, data['method'], data['extras']

View file

@ -285,7 +285,7 @@ class InvalidationContext(object):
self.uid = uid
self.invalidation_namespace = invalidation_namespace
self.raise_exception = raise_exception
self.proc_id = safe_unicode(rhodecode.CONFIG.get('instance_id') or 'DEFAULT')
self.proc_id = rhodecode.CONFIG.get('instance_id') or 'DEFAULT'
self.thread_id = 'global'
if thread_scoped is None:

View file

@ -240,7 +240,7 @@ class GitRepository(BaseRepository):
commit_missing_err = "Commit {} does not exist for `{}`".format(
*map(safe_str, [commit_id_or_idx, self.name]))
is_bstr = isinstance(commit_id_or_idx, (str, unicode))
is_bstr = isinstance(commit_id_or_idx, str)
is_branch = reference_obj and reference_obj.branch
lookup_ok = False

View file

@ -180,7 +180,7 @@ def _stub_git_repo(repo_path):
repo_path.ensure('.git', dir=True)
@pytest.mark.parametrize('str_class', [str, unicode], ids=['str', 'unicode'])
@pytest.mark.parametrize('str_class', [str, bytes], ids=['str', 'bytes'])
def test_get_dirpaths_returns_all_paths(tmpdir, str_class):
tmpdir.ensure('test-file')
dirpaths = utils._get_dirpaths(str_class(tmpdir))

View file

@ -162,7 +162,7 @@ def test_get_nodes_max_file_bytes(backend_random):
def assert_contains_only_unicode(structure):
assert structure
for value in structure:
assert isinstance(value, unicode)
assert isinstance(value, str)
@pytest.mark.backends("hg", "git")

View file

@ -69,6 +69,12 @@ from rhodecode.config import utils as config_utils
log = logging.getLogger(__name__)
def cmp(a, b):
# backport cmp from python2 so we can still use it in the custom code in this module
return (a > b) - (a < b)
def _split_comma(value):
return value.split(',')
@ -872,7 +878,7 @@ def _add_commits_to_repo(vcs_repo, commits):
commit = None
for idx, commit in enumerate(commits):
message = unicode(commit.get('message', 'Commit %s' % idx))
message = str(commit.get('message', 'Commit %s' % idx))
for node in commit.get('added', []):
imc.add(FileNode(node.path, content=node.content))
@ -891,7 +897,7 @@ def _add_commits_to_repo(vcs_repo, commits):
commit = imc.commit(
message=message,
author=unicode(commit.get('author', 'Automatic <automatic@rhodecode.com>')),
author=str(commit.get('author', 'Automatic <automatic@rhodecode.com>')),
date=commit.get('date'),
branch=commit.get('branch'),
parents=parents)

View file

@ -592,5 +592,5 @@ class TestCommitsChanges(BackendTestMixin):
def assert_text_equal(expected, given):
assert expected == given
assert isinstance(expected, unicode)
assert isinstance(given, unicode)
assert isinstance(expected, str)
assert isinstance(given, str)

View file

@ -29,7 +29,7 @@ from rhodecode.tests.vcs.conftest import BackendTestMixin
class TestFileNodeUnicodePath(BackendTestMixin):
fname = 'ąśðąęłąć.txt'
ufname = (fname).decode('utf-8')
ufname = fname
@classmethod
def _get_commits(cls):

View file

@ -965,17 +965,17 @@ class TestGitCommit(object):
def test_commit_message_is_unicode(self):
for commit in self.repo:
assert type(commit.message) == unicode
assert type(commit.message) == str
def test_commit_author_is_unicode(self):
for commit in self.repo:
assert type(commit.author) == unicode
assert type(commit.author) == str
def test_repo_files_content_is_unicode(self):
commit = self.repo.get_commit()
for node in commit.get_node('/'):
if node.is_file():
assert type(node.content) == unicode
assert type(node.content) == str
def test_wrong_path(self):
# There is 'setup.py' in the root dir but not there:

View file

@ -1084,17 +1084,17 @@ class TestMercurialCommit(object):
def test_commit_message_is_unicode(self):
for cm in self.repo:
assert type(cm.message) == unicode
assert type(cm.message) == str
def test_commit_author_is_unicode(self):
for cm in self.repo:
assert type(cm.author) == unicode
assert type(cm.author) == str
def test_repo_files_content_is_unicode(self):
test_commit = self.repo.get_commit(commit_idx=100)
for node in test_commit.get_node('/'):
if node.is_file():
assert type(node.content) == unicode
assert type(node.content) == str
def test_wrong_path(self):
# There is 'setup.py' in the root dir but not there:

View file

@ -36,9 +36,6 @@ class _LazyString(object):
translator = req.translate
return translator(*self.args, **self.kw)
def __unicode__(self):
return unicode(self.eval())
def __str__(self):
return self.eval()