Changeset - 2837b66f68bb
[Not reviewed]
default
0 10 0
Mads Kiilerich - 6 years ago 2019-12-26 15:20:08
mads@kiilerich.com
Grafted from: 9f6fdfc71a91
py3: trivially replace safe_str with safe_bytes in some places where that is what we need
10 files changed with 26 insertions and 24 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/auth.py
Show inline comments
 
@@ -41,7 +41,7 @@ from kallithea import __platform__, is_u
 
from kallithea.config.routing import url
 
from kallithea.lib.caching_query import FromCache
 
from kallithea.lib.utils import conditional_cache, get_repo_group_slug, get_repo_slug, get_user_group_slug
 
from kallithea.lib.utils2 import ascii_bytes, ascii_str, safe_str, safe_unicode
 
from kallithea.lib.utils2 import ascii_bytes, ascii_str, safe_bytes, safe_unicode
 
from kallithea.lib.vcs.utils.lazy import LazyProperty
 
from kallithea.model.db import (
 
    Permission, RepoGroup, Repository, User, UserApiKeys, UserGroup, UserGroupMember, UserGroupRepoGroupToPerm, UserGroupRepoToPerm, UserGroupToPerm, UserGroupUserGroupToPerm, UserIpMap, UserToPerm)
 
@@ -95,7 +95,7 @@ def get_crypt_password(password):
 
        return hashlib.sha256(password).hexdigest()
 
    elif is_unix:
 
        import bcrypt
 
        return ascii_str(bcrypt.hashpw(safe_str(password), bcrypt.gensalt(10)))
 
        return ascii_str(bcrypt.hashpw(safe_bytes(password), bcrypt.gensalt(10)))
 
    else:
 
        raise Exception('Unknown or unsupported platform %s'
 
                        % __platform__)
 
@@ -115,7 +115,7 @@ def check_password(password, hashed):
 
    elif is_unix:
 
        import bcrypt
 
        try:
 
            return bcrypt.checkpw(safe_str(password), ascii_bytes(hashed))
 
            return bcrypt.checkpw(safe_bytes(password), ascii_bytes(hashed))
 
        except ValueError as e:
 
            # bcrypt will throw ValueError 'Invalid hashed_password salt' on all password errors
 
            log.error('error from bcrypt checking password: %s', e)
kallithea/lib/celerylib/__init__.py
Show inline comments
 
@@ -35,7 +35,7 @@ from tg import config
 

	
 
from kallithea import CELERY_EAGER, CELERY_ON
 
from kallithea.lib.pidlock import DaemonLock, LockHeld
 
from kallithea.lib.utils2 import safe_str
 
from kallithea.lib.utils2 import safe_bytes
 
from kallithea.model import meta
 

	
 

	
 
@@ -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(safe_str(func_name + '-' + '-'.join(unicode(x) for x in params))).hexdigest()
 
        md5(safe_bytes(func_name + '-' + '-'.join(unicode(x) for x in params))).hexdigest()
 
    return lockkey
 

	
 

	
kallithea/lib/helpers.py
Show inline comments
 
@@ -48,7 +48,7 @@ from kallithea.lib.markup_renderer impor
 
from kallithea.lib.pygmentsutils import get_custom_lexer
 
from kallithea.lib.utils2 import MENTIONS_REGEX, AttributeDict
 
from kallithea.lib.utils2 import age as _age
 
from kallithea.lib.utils2 import credentials_filter, safe_int, safe_str, safe_unicode, str2bool, time_to_datetime
 
from kallithea.lib.utils2 import credentials_filter, safe_bytes, safe_int, safe_unicode, str2bool, time_to_datetime
 
from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
 
from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError
 
#==============================================================================
 
@@ -199,7 +199,7 @@ def FID(raw_id, path):
 
    :param path:
 
    """
 

	
 
    return 'C-%s-%s' % (short_id(raw_id), hashlib.md5(safe_str(path)).hexdigest()[:12])
 
    return 'C-%s-%s' % (short_id(raw_id), hashlib.md5(safe_bytes(path)).hexdigest()[:12])
 

	
 

	
 
class _FilesBreadCrumbs(object):
 
@@ -938,7 +938,7 @@ def gravatar_url(email_address, size=30,
 
    parsed_url = urlparse.urlparse(url.current(qualified=True))
 
    url = (c.visual.gravatar_url or User.DEFAULT_GRAVATAR_URL) \
 
               .replace('{email}', email_address) \
 
               .replace('{md5email}', hashlib.md5(safe_str(email_address).lower()).hexdigest()) \
 
               .replace('{md5email}', hashlib.md5(safe_bytes(email_address).lower()).hexdigest()) \
 
               .replace('{netloc}', parsed_url.netloc) \
 
               .replace('{scheme}', parsed_url.scheme) \
 
               .replace('{size}', str(size))
kallithea/lib/middleware/permanent_repo_url.py
Show inline comments
 
@@ -21,7 +21,7 @@ middleware to handle permanent repo URLs
 

	
 

	
 
from kallithea.lib.utils import fix_repo_id_name
 
from kallithea.lib.utils2 import safe_str, safe_unicode
 
from kallithea.lib.utils2 import safe_bytes, safe_unicode
 

	
 

	
 
class PermanentRepoUrl(object):
 
@@ -35,7 +35,7 @@ class PermanentRepoUrl(object):
 
        # we also have to do the reverse operation when patching it back in
 
        path_info = safe_unicode(environ['PATH_INFO'])
 
        if path_info.startswith('/'): # it must
 
            path_info = '/' + safe_str(fix_repo_id_name(path_info[1:]))
 
            environ['PATH_INFO'] = path_info
 
            path_info = '/' + fix_repo_id_name(path_info[1:])
 
            environ['PATH_INFO'] = safe_bytes(path_info)
 

	
 
        return self.application(environ, start_response)
kallithea/lib/utils.py
Show inline comments
 
@@ -337,7 +337,7 @@ def make_ui(repo_path=None):
 
    sa = meta.Session()
 
    for ui_ in sa.query(Ui).all():
 
        if ui_.ui_active:
 
            ui_val = b'' if ui_.ui_value is None else safe_str(ui_.ui_value)
 
            ui_val = b'' if ui_.ui_value is None else safe_bytes(ui_.ui_value)
 
            log.debug('config from db: [%s] %s=%r', ui_.ui_section,
 
                      ui_.ui_key, ui_val)
 
            baseui.setconfig(ascii_bytes(ui_.ui_section), ascii_bytes(ui_.ui_key),
kallithea/lib/vcs/backends/git/inmemory.py
Show inline comments
 
@@ -7,7 +7,7 @@ from dulwich import objects
 

	
 
from kallithea.lib.vcs.backends.base import BaseInMemoryChangeset
 
from kallithea.lib.vcs.exceptions import RepositoryError
 
from kallithea.lib.vcs.utils import ascii_str, safe_bytes, safe_str
 
from kallithea.lib.vcs.utils import ascii_str, safe_bytes
 

	
 

	
 
class GitInMemoryChangeset(BaseInMemoryChangeset):
 
@@ -47,7 +47,7 @@ class GitInMemoryChangeset(BaseInMemoryC
 
        for node in self.added + self.changed:
 
            # Compute subdirs if needed
 
            dirpath, nodename = posixpath.split(node.path)
 
            dirnames = safe_str(dirpath).split(b'/') if dirpath else []
 
            dirnames = safe_bytes(dirpath).split(b'/') if dirpath else []
 
            parent = commit_tree
 
            ancestors = [('', parent)]
 

	
 
@@ -126,9 +126,9 @@ class GitInMemoryChangeset(BaseInMemoryC
 
        commit = objects.Commit()
 
        commit.tree = commit_tree.id
 
        commit.parents = [p._commit.id for p in self.parents if p]
 
        commit.author = commit.committer = safe_str(author)
 
        commit.author = commit.committer = safe_bytes(author)
 
        commit.encoding = ENCODING
 
        commit.message = safe_str(message)
 
        commit.message = safe_bytes(message)
 

	
 
        # Compute date
 
        if date is None:
kallithea/lib/vcs/backends/hg/repository.py
Show inline comments
 
@@ -347,7 +347,7 @@ class MercurialRepository(BaseRepository
 

	
 
        try:
 
            if src_url:
 
                url = safe_str(self._get_url(src_url))
 
                url = safe_bytes(self._get_url(src_url))
 
                opts = {}
 
                if not update_after_clone:
 
                    opts.update({'noupdate': True})
 
@@ -521,7 +521,7 @@ class MercurialRepository(BaseRepository
 
        # filter branches
 
        filter_ = []
 
        if branch_name:
 
            filter_.append(b'branch("%s")' % safe_str(branch_name))
 
            filter_.append(b'branch("%s")' % safe_bytes(branch_name))
 
        if start_date:
 
            filter_.append(b'date(">%s")' % start_date)
 
        if end_date:
kallithea/lib/vcs/backends/hg/ssh.py
Show inline comments
 
@@ -19,7 +19,7 @@ from mercurial.wireprotoserver import ss
 

	
 
from kallithea.lib.utils import make_ui
 
from kallithea.lib.vcs.backends.ssh import BaseSshHandler
 
from kallithea.lib.vcs.utils import safe_str, safe_unicode
 
from kallithea.lib.vcs.utils import safe_bytes, safe_unicode
 

	
 

	
 
log = logging.getLogger(__name__)
 
@@ -61,6 +61,6 @@ class MercurialSshHandler(BaseSshHandler
 
            baseui.setconfig(b'hooks', b'pretxnopen._ssh_reject', b'python:kallithea.lib.hooks.rejectpush')
 
            baseui.setconfig(b'hooks', b'prepushkey._ssh_reject', b'python:kallithea.lib.hooks.rejectpush')
 

	
 
        repo = hg.repository(baseui, safe_str(self.db_repo.repo_full_path))
 
        repo = hg.repository(baseui, safe_bytes(self.db_repo.repo_full_path))
 
        log.debug("Starting Mercurial sshserver for %s", self.db_repo.repo_full_path)
 
        sshserver(baseui, repo).serve_forever()
kallithea/lib/vcs/conf/settings.py
Show inline comments
 
@@ -18,7 +18,7 @@ VCSRC_PATH = VCSRC_PATH or abspath(HOME_
 
if os.path.isdir(VCSRC_PATH):
 
    VCSRC_PATH = os.path.join(VCSRC_PATH, '__init__.py')
 

	
 
# list of default encoding used in safe_unicode/safe_str methods
 
# list of default encoding used in safe_unicode/safe_bytes methods
 
DEFAULT_ENCODINGS = aslist('utf-8')
 

	
 
# path to git executable run by run_git_command function
kallithea/model/db.py
Show inline comments
 
@@ -48,7 +48,8 @@ import kallithea
 
from kallithea.lib.caching_query import FromCache
 
from kallithea.lib.compat import json
 
from kallithea.lib.exceptions import DefaultUserException
 
from kallithea.lib.utils2 import Optional, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_int, safe_str, safe_unicode, str2bool, urlreadable
 
from kallithea.lib.utils2 import (
 
    Optional, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_str, safe_unicode, str2bool, urlreadable)
 
from kallithea.lib.vcs import get_backend
 
from kallithea.lib.vcs.backends.base import EmptyChangeset
 
from kallithea.lib.vcs.utils.helpers import get_scm
 
@@ -63,7 +64,8 @@ log = logging.getLogger(__name__)
 
# BASE CLASSES
 
#==============================================================================
 

	
 
_hash_key = lambda k: hashlib.md5(safe_str(k)).hexdigest()
 
def _hash_key(k):
 
    return hashlib.md5(safe_bytes(k)).hexdigest()
 

	
 

	
 
class BaseDbModel(object):
 
@@ -183,7 +185,7 @@ class Setting(Base, BaseDbModel):
 
    )
 

	
 
    SETTINGS_TYPES = {
 
        'str': safe_str,
 
        'str': safe_bytes,
 
        'int': safe_int,
 
        'unicode': safe_unicode,
 
        'bool': str2bool,
0 comments (0 inline, 0 general)