# HG changeset patch # User Mads Kiilerich # Date 2019-12-16 03:22:22 # Node ID fd0998635e839c276d8a817323d2e9f3c231402d # Parent 38749d420fbd2620a63e5e7c1cde22d0ffb0626b cleanup: drop some unnecessary use of safe_str diff --git a/kallithea/lib/celerylib/__init__.py b/kallithea/lib/celerylib/__init__.py --- a/kallithea/lib/celerylib/__init__.py +++ b/kallithea/lib/celerylib/__init__.py @@ -95,7 +95,7 @@ def __get_lockkey(func, *fargs, **fkwarg func_name = str(func.__name__) if hasattr(func, '__name__') else str(func) lockkey = 'task_%s.lock' % \ - md5(func_name + '-' + '-'.join(map(safe_str, params))).hexdigest() + md5(safe_str(func_name + '-' + '-'.join(unicode(x) for x in params))).hexdigest() return lockkey diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py +++ b/kallithea/lib/helpers.py @@ -942,7 +942,7 @@ def gravatar_url(email_address, size=30, .replace('{md5email}', hashlib.md5(safe_str(email_address).lower()).hexdigest()) \ .replace('{netloc}', parsed_url.netloc) \ .replace('{scheme}', parsed_url.scheme) \ - .replace('{size}', safe_str(size)) + .replace('{size}', str(size)) return url diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -136,8 +136,10 @@ class BaseDbModel(object): return None if isinstance(value, cls): return value - if isinstance(value, (int, long)) or safe_str(value).isdigit(): + if isinstance(value, (int, long)): return cls.get(value) + if isinstance(value, basestring) and value.isdigit(): + return cls.get(int(value)) if callback is not None: return callback(value) diff --git a/kallithea/model/scm.py b/kallithea/model/scm.py --- a/kallithea/model/scm.py +++ b/kallithea/model/scm.py @@ -139,9 +139,11 @@ class ScmModel(object): cls = Repository if isinstance(instance, cls): return instance - elif isinstance(instance, int) or safe_str(instance).isdigit(): + elif isinstance(instance, int): return cls.get(instance) elif isinstance(instance, basestring): + if instance.isdigit(): + return cls.get(int(instance)) return cls.get_by_repo_name(instance) elif instance is not None: raise Exception('given object must be int, basestr or Instance' diff --git a/kallithea/model/ssh_key.py b/kallithea/model/ssh_key.py --- a/kallithea/model/ssh_key.py +++ b/kallithea/model/ssh_key.py @@ -29,7 +29,7 @@ from tg import config from tg.i18n import ugettext as _ from kallithea.lib import ssh -from kallithea.lib.utils2 import safe_str, str2bool +from kallithea.lib.utils2 import str2bool from kallithea.model.db import User, UserSshKeys from kallithea.model.meta import Session @@ -53,7 +53,7 @@ class SshKeyModel(object): try: keytype, pub, comment = ssh.parse_pub_key(public_key) except ssh.SshKeyParseError as e: - raise SshKeyModelException(_('SSH key %r is invalid: %s') % (safe_str(public_key), e.message)) + raise SshKeyModelException(_('SSH key %r is invalid: %s') % (public_key, e.message)) if not description.strip(): description = comment.strip() @@ -86,7 +86,7 @@ class SshKeyModel(object): ssh_key = ssh_key.scalar() if ssh_key is None: - raise SshKeyModelException(_('SSH key %r not found') % safe_str(public_key)) + raise SshKeyModelException(_('SSH key %r not found') % public_key) Session().delete(ssh_key) def get_ssh_keys(self, user):