changeset 8198:08eec03c9485

py3: rename all existing safe_unicode to safe_str
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 02 Jan 2020 02:22:14 +0100
parents b1a3e6df8bae
children 1112e440b921
files kallithea/controllers/admin/gists.py kallithea/controllers/admin/settings.py kallithea/controllers/admin/user_groups.py kallithea/controllers/changeset.py kallithea/controllers/feed.py kallithea/controllers/files.py kallithea/controllers/summary.py kallithea/lib/annotate.py kallithea/lib/base.py kallithea/lib/diffs.py kallithea/lib/helpers.py kallithea/lib/indexers/daemon.py kallithea/lib/markup_renderer.py kallithea/lib/middleware/permanent_repo_url.py kallithea/lib/utils2.py kallithea/lib/vcs/backends/git/changeset.py kallithea/lib/vcs/backends/git/inmemory.py kallithea/lib/vcs/backends/git/repository.py kallithea/lib/vcs/backends/hg/changeset.py kallithea/lib/vcs/backends/hg/repository.py kallithea/lib/vcs/conf/settings.py kallithea/lib/vcs/nodes.py kallithea/lib/vcs/utils/__init__.py kallithea/model/db.py kallithea/templates/admin/gists/edit.html kallithea/templates/files/files_edit.html
diffstat 26 files changed, 68 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/gists.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/controllers/admin/gists.py	Thu Jan 02 02:22:14 2020 +0100
@@ -40,7 +40,7 @@
 from kallithea.lib.auth import LoginRequired
 from kallithea.lib.base import BaseController, jsonify, render
 from kallithea.lib.page import Page
-from kallithea.lib.utils2 import safe_int, safe_unicode, time_to_datetime
+from kallithea.lib.utils2 import safe_int, safe_str, time_to_datetime
 from kallithea.lib.vcs.exceptions import NodeNotChangedError, VCSError
 from kallithea.model.db import Gist
 from kallithea.model.forms import GistForm
@@ -183,7 +183,7 @@
             raise HTTPNotFound()
         if format == 'raw':
             content = '\n\n'.join(
-                safe_unicode(f.content)
+                safe_str(f.content)
                 for f in c.files if (f_path is None or f.path == f_path)
             )
             response.content_type = 'text/plain'
--- a/kallithea/controllers/admin/settings.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/controllers/admin/settings.py	Thu Jan 02 02:22:14 2020 +0100
@@ -42,7 +42,7 @@
 from kallithea.lib.celerylib import tasks
 from kallithea.lib.exceptions import HgsubversionImportError
 from kallithea.lib.utils import repo2db_mapper, set_app_settings
-from kallithea.lib.utils2 import safe_unicode
+from kallithea.lib.utils2 import safe_str
 from kallithea.lib.vcs import VCSError
 from kallithea.model.db import Repository, Setting, Ui
 from kallithea.model.forms import ApplicationSettingsForm, ApplicationUiSettingsForm, ApplicationVisualisationForm
@@ -168,10 +168,10 @@
                                             user=request.authuser.username,
                                             overwrite_git_hooks=overwrite_git_hooks)
             added_msg = h.HTML(', ').join(
-                h.link_to(safe_unicode(repo_name), h.url('summary_home', repo_name=repo_name)) for repo_name in added
+                h.link_to(safe_str(repo_name), h.url('summary_home', repo_name=repo_name)) for repo_name in added
             ) or '-'
             removed_msg = h.HTML(', ').join(
-                safe_unicode(repo_name) for repo_name in removed
+                safe_str(repo_name) for repo_name in removed
             ) or '-'
             h.flash(h.HTML(_('Repositories successfully rescanned. Added: %s. Removed: %s.')) %
                     (added_msg, removed_msg), category='success')
--- a/kallithea/controllers/admin/user_groups.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/controllers/admin/user_groups.py	Thu Jan 02 02:22:14 2020 +0100
@@ -43,7 +43,7 @@
 from kallithea.lib.base import BaseController, render
 from kallithea.lib.exceptions import RepoGroupAssignmentError, UserGroupsAssignedException
 from kallithea.lib.utils import action_logger
-from kallithea.lib.utils2 import safe_int, safe_unicode
+from kallithea.lib.utils2 import safe_int, safe_str
 from kallithea.model.db import User, UserGroup, UserGroupRepoGroupToPerm, UserGroupRepoToPerm, UserGroupToPerm
 from kallithea.model.forms import CustomDefaultPermissionsForm, UserGroupForm, UserGroupPermsForm
 from kallithea.model.meta import Session
@@ -161,7 +161,7 @@
         c.active = 'settings'
         self.__load_data(id)
 
-        available_members = [safe_unicode(x[0]) for x in c.available_members]
+        available_members = [safe_str(x[0]) for x in c.available_members]
 
         users_group_form = UserGroupForm(edit=True,
                                          old_data=c.user_group.get_dict(),
--- a/kallithea/controllers/changeset.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/controllers/changeset.py	Thu Jan 02 02:22:14 2020 +0100
@@ -41,7 +41,7 @@
 from kallithea.lib.base import BaseRepoController, jsonify, render
 from kallithea.lib.graphmod import graph_data
 from kallithea.lib.utils import action_logger
-from kallithea.lib.utils2 import ascii_str, safe_unicode
+from kallithea.lib.utils2 import ascii_str, safe_str
 from kallithea.lib.vcs.backends.base import EmptyChangeset
 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError
 from kallithea.model.changeset_status import ChangesetStatusModel
@@ -405,7 +405,7 @@
             return raw_diff
         elif method == 'patch':
             response.content_type = 'text/plain'
-            c.diff = safe_unicode(raw_diff)
+            c.diff = safe_str(raw_diff)
             return render('changeset/patch_changeset.html')
         elif method == 'raw':
             response.content_type = 'text/plain'
--- a/kallithea/controllers/feed.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/controllers/feed.py	Thu Jan 02 02:22:14 2020 +0100
@@ -39,7 +39,7 @@
 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
 from kallithea.lib.base import BaseRepoController
 from kallithea.lib.diffs import DiffProcessor
-from kallithea.lib.utils2 import safe_int, safe_unicode, str2bool
+from kallithea.lib.utils2 import safe_int, safe_str, str2bool
 
 
 log = logging.getLogger(__name__)
@@ -94,7 +94,7 @@
         desc_msg.extend(changes)
         if str2bool(CONFIG.get('rss_include_diff', False)):
             desc_msg.append('\n\n')
-            desc_msg.append(safe_unicode(raw_diff))
+            desc_msg.append(safe_str(raw_diff))
         desc_msg.append('</pre>')
         return desc_msg
 
--- a/kallithea/controllers/files.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/controllers/files.py	Thu Jan 02 02:22:14 2020 +0100
@@ -46,7 +46,7 @@
 from kallithea.lib.base import BaseRepoController, jsonify, render
 from kallithea.lib.exceptions import NonRelativePathError
 from kallithea.lib.utils import action_logger
-from kallithea.lib.utils2 import convert_line_endings, detect_mode, safe_int, safe_unicode, str2bool
+from kallithea.lib.utils2 import convert_line_endings, detect_mode, safe_int, safe_str, str2bool
 from kallithea.lib.vcs.backends.base import EmptyChangeset
 from kallithea.lib.vcs.conf import settings
 from kallithea.lib.vcs.exceptions import (
@@ -364,7 +364,7 @@
         c.f_path = f_path
 
         if r_post:
-            old_content = safe_unicode(c.file.content)
+            old_content = safe_str(c.file.content)
             sl = old_content.splitlines(1)
             first_line = sl[0] if sl else ''
             # modes:  0 - Unix, 1 - Mac, 2 - DOS
--- a/kallithea/controllers/summary.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/controllers/summary.py	Thu Jan 02 02:22:14 2020 +0100
@@ -46,7 +46,7 @@
 from kallithea.lib.celerylib.tasks import get_commits_stats
 from kallithea.lib.markup_renderer import MarkupRenderer
 from kallithea.lib.page import Page
-from kallithea.lib.utils2 import safe_int, safe_unicode
+from kallithea.lib.utils2 import safe_int, safe_str
 from kallithea.lib.vcs.backends.base import EmptyChangeset
 from kallithea.lib.vcs.exceptions import ChangesetError, EmptyRepositoryError, NodeDoesNotExistError
 from kallithea.lib.vcs.nodes import FileNode
@@ -84,7 +84,7 @@
                         readme_file = f
                         log.debug('Found README file `%s` rendering...',
                                   readme_file)
-                        readme_data = renderer.render(safe_unicode(readme.content),
+                        readme_data = renderer.render(safe_str(readme.content),
                                                       filename=f)
                         break
                     except NodeDoesNotExistError:
--- a/kallithea/lib/annotate.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/annotate.py	Thu Jan 02 02:22:14 2020 +0100
@@ -30,7 +30,7 @@
 
 from kallithea.lib.vcs.exceptions import VCSError
 from kallithea.lib.vcs.nodes import FileNode
-from kallithea.lib.vcs.utils import safe_unicode
+from kallithea.lib.vcs.utils import safe_str
 
 
 def annotate_highlight(filenode, annotate_from_changeset_func,
@@ -54,7 +54,7 @@
         annotate_from_changeset_func=annotate_from_changeset_func, order=order,
         headers=headers, **options)
     lexer = get_custom_lexer(filenode.extension) or filenode.lexer
-    highlighted = highlight(safe_unicode(filenode.content), lexer, formatter)
+    highlighted = highlight(safe_str(filenode.content), lexer, formatter)
     return highlighted
 
 
--- a/kallithea/lib/base.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/base.py	Thu Jan 02 02:22:14 2020 +0100
@@ -49,7 +49,7 @@
 from kallithea.lib.auth import AuthUser, HasPermissionAnyMiddleware
 from kallithea.lib.exceptions import UserCreationError
 from kallithea.lib.utils import get_repo_slug, is_valid_repo
-from kallithea.lib.utils2 import AttributeDict, ascii_bytes, safe_int, safe_unicode, set_hook_environment, str2bool
+from kallithea.lib.utils2 import AttributeDict, ascii_bytes, safe_int, safe_str, set_hook_environment, str2bool
 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError
 from kallithea.model import meta
 from kallithea.model.db import PullRequest, Repository, Setting, User
@@ -102,7 +102,7 @@
     org_req = environ.get('tg.original_request')
     if org_req is not None:
         environ = org_req.environ
-    return safe_unicode(environ['PATH_INFO'])
+    return safe_str(environ['PATH_INFO'])
 
 
 def log_in_user(user, remember, is_external_auth, ip_addr):
--- a/kallithea/lib/diffs.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/diffs.py	Thu Jan 02 02:22:14 2020 +0100
@@ -32,7 +32,7 @@
 from tg.i18n import ugettext as _
 
 from kallithea.lib import helpers as h
-from kallithea.lib.utils2 import safe_unicode
+from kallithea.lib.utils2 import safe_str
 from kallithea.lib.vcs.backends.base import EmptyChangeset
 from kallithea.lib.vcs.exceptions import VCSError
 from kallithea.lib.vcs.nodes import FileNode, SubModuleNode
@@ -477,7 +477,7 @@
             return ' <i></i>'
         assert False
 
-    return _escape_re.sub(substitute, safe_unicode(string))
+    return _escape_re.sub(substitute, safe_str(string))
 
 
 _git_header_re = re.compile(br"""
--- a/kallithea/lib/helpers.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/helpers.py	Thu Jan 02 02:22:14 2020 +0100
@@ -48,7 +48,7 @@
 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_bytes, safe_int, safe_unicode, str2bool, time_to_datetime
+from kallithea.lib.utils2 import credentials_filter, safe_bytes, safe_int, safe_str, str2bool, time_to_datetime
 from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError
 #==============================================================================
@@ -328,7 +328,7 @@
     """
     lexer = get_custom_lexer(filenode.extension) or filenode.lexer
     return literal(markup_whitespace(
-        code_highlight(safe_unicode(filenode.content), lexer, CodeHtmlFormatter(**kwargs))))
+        code_highlight(safe_str(filenode.content), lexer, CodeHtmlFormatter(**kwargs))))
 
 
 def hsv_to_rgb(h, s, v):
@@ -1222,7 +1222,7 @@
     Render plain text with revision hashes and issue references urlified
     and with @mention highlighting.
     """
-    s = safe_unicode(source)
+    s = safe_str(source)
     s = urlify_text(s, repo_name=repo_name)
     return literal('<div class="formatted-fixed">%s</div>' % s)
 
--- a/kallithea/lib/indexers/daemon.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/indexers/daemon.py	Thu Jan 02 02:22:14 2020 +0100
@@ -39,7 +39,7 @@
 
 from kallithea.config.conf import INDEX_EXTENSIONS, INDEX_FILENAMES
 from kallithea.lib.indexers import CHGSET_IDX_NAME, CHGSETS_SCHEMA, IDX_NAME, SCHEMA
-from kallithea.lib.utils2 import safe_unicode
+from kallithea.lib.utils2 import safe_str
 from kallithea.lib.vcs.exceptions import ChangesetError, NodeDoesNotExistError, RepositoryError
 from kallithea.model.db import Repository
 from kallithea.model.scm import ScmModel
@@ -184,7 +184,7 @@
                 u_content = u''
             else:
                 log.debug('    >> %s', path)
-                u_content = safe_unicode(bytes_content)
+                u_content = safe_str(bytes_content)
                 indexed_w_content += 1
 
         else:
--- a/kallithea/lib/markup_renderer.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/markup_renderer.py	Thu Jan 02 02:22:14 2020 +0100
@@ -33,7 +33,7 @@
 import bleach
 import markdown as markdown_mod
 
-from kallithea.lib.utils2 import MENTIONS_REGEX, safe_unicode
+from kallithea.lib.utils2 import MENTIONS_REGEX, safe_str
 
 
 log = logging.getLogger(__name__)
@@ -150,7 +150,7 @@
 
     @classmethod
     def plain(cls, source, universal_newline=True):
-        source = safe_unicode(source)
+        source = safe_str(source)
         if universal_newline:
             newline = '\n'
             source = newline.join(source.splitlines())
@@ -191,7 +191,7 @@
         </pre></div>
         </td></tr></table>
         """
-        source = safe_unicode(source)
+        source = safe_str(source)
         try:
             if flavored:
                 source = cls._flavored_markdown(source)
@@ -209,7 +209,7 @@
 
     @classmethod
     def rst(cls, source, safe=True):
-        source = safe_unicode(source)
+        source = safe_str(source)
         try:
             from docutils.core import publish_parts
             from docutils.parsers.rst import directives
--- a/kallithea/lib/middleware/permanent_repo_url.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/middleware/permanent_repo_url.py	Thu Jan 02 02:22:14 2020 +0100
@@ -21,7 +21,7 @@
 
 
 from kallithea.lib.utils import fix_repo_id_name
-from kallithea.lib.utils2 import safe_bytes, safe_unicode
+from kallithea.lib.utils2 import safe_bytes, safe_str
 
 
 class PermanentRepoUrl(object):
@@ -33,7 +33,7 @@
     def __call__(self, environ, start_response):
         # Extract path_info as get_path_info does, but do it explicitly because
         # we also have to do the reverse operation when patching it back in
-        path_info = safe_unicode(environ['PATH_INFO'])
+        path_info = safe_str(environ['PATH_INFO'])
         if path_info.startswith('/'): # it must
             path_info = '/' + fix_repo_id_name(path_info[1:])
             environ['PATH_INFO'] = safe_bytes(path_info)
--- a/kallithea/lib/utils2.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/utils2.py	Thu Jan 02 02:22:14 2020 +0100
@@ -43,7 +43,7 @@
 from tg.i18n import ungettext
 from webhelpers2.text import collapse, remove_formatting, strip_tags
 
-from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, safe_bytes, safe_str, safe_unicode  # re-export
+from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, safe_bytes, safe_str  # re-export
 from kallithea.lib.vcs.utils.lazy import LazyProperty
 
 
--- a/kallithea/lib/vcs/backends/git/changeset.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/vcs/backends/git/changeset.py	Thu Jan 02 02:22:14 2020 +0100
@@ -11,7 +11,7 @@
 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, ChangesetError, ImproperArchiveTypeError, NodeDoesNotExistError, RepositoryError, VCSError
 from kallithea.lib.vcs.nodes import (
     AddedFileNodesGenerator, ChangedFileNodesGenerator, DirNode, FileNode, NodeKind, RemovedFileNodesGenerator, RootNode, SubModuleNode)
-from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, date_fromtimestamp, safe_int, safe_unicode
+from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, date_fromtimestamp, safe_int, safe_str
 from kallithea.lib.vcs.utils.lazy import LazyProperty
 
 
@@ -49,15 +49,15 @@
 
     @LazyProperty
     def message(self):
-        return safe_unicode(self._commit.message)
+        return safe_str(self._commit.message)
 
     @LazyProperty
     def committer(self):
-        return safe_unicode(getattr(self._commit, self._committer_property))
+        return safe_str(getattr(self._commit, self._committer_property))
 
     @LazyProperty
     def author(self):
-        return safe_unicode(getattr(self._commit, self._author_property))
+        return safe_str(getattr(self._commit, self._author_property))
 
     @LazyProperty
     def date(self):
@@ -91,7 +91,7 @@
         heads = self.repository._heads(reverse=False)
         ref = heads.get(self._commit.id)
         if ref:
-            return safe_unicode(ref)
+            return safe_str(ref)
 
     @LazyProperty
     def branches(self):
--- a/kallithea/lib/vcs/backends/git/inmemory.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/vcs/backends/git/inmemory.py	Thu Jan 02 02:22:14 2020 +0100
@@ -39,7 +39,7 @@
         repo = self.repository._repo
         object_store = repo.object_store
 
-        ENCODING = b"UTF-8"  # TODO: should probably be kept in sync with safe_unicode/safe_bytes and vcs/conf/settings.py DEFAULT_ENCODINGS
+        ENCODING = b"UTF-8"  # TODO: should probably be kept in sync with safe_str/safe_bytes and vcs/conf/settings.py DEFAULT_ENCODINGS
 
         # Create tree and populates it with blobs
         commit_tree = self.parents[0] and repo[self.parents[0]._commit.tree] or \
--- a/kallithea/lib/vcs/backends/git/repository.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/vcs/backends/git/repository.py	Thu Jan 02 02:22:14 2020 +0100
@@ -30,7 +30,7 @@
 from kallithea.lib.vcs.conf import settings
 from kallithea.lib.vcs.exceptions import (
     BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, TagAlreadyExistError, TagDoesNotExistError)
-from kallithea.lib.vcs.utils import ascii_str, date_fromtimestamp, makedate, safe_bytes, safe_unicode
+from kallithea.lib.vcs.utils import ascii_str, date_fromtimestamp, makedate, safe_bytes, safe_str
 from kallithea.lib.vcs.utils.lazy import LazyProperty
 from kallithea.lib.vcs.utils.paths import abspath, get_user_home
 
@@ -145,7 +145,7 @@
         if os.path.isdir(self.path):
             cwd = self.path
         stdout, _stderr = self._run_git_command(cmd, cwd=cwd)
-        return safe_unicode(stdout)
+        return safe_str(stdout)
 
     @classmethod
     def _check_url(cls, url):
@@ -347,7 +347,7 @@
 
     @LazyProperty
     def description(self):
-        return safe_unicode(self._repo.get_description() or b'unknown')
+        return safe_str(self._repo.get_description() or b'unknown')
 
     @LazyProperty
     def contact(self):
--- a/kallithea/lib/vcs/backends/hg/changeset.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/vcs/backends/hg/changeset.py	Thu Jan 02 02:22:14 2020 +0100
@@ -10,7 +10,7 @@
 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, ChangesetError, ImproperArchiveTypeError, NodeDoesNotExistError, VCSError
 from kallithea.lib.vcs.nodes import (
     AddedFileNodesGenerator, ChangedFileNodesGenerator, DirNode, FileNode, NodeKind, RemovedFileNodesGenerator, RootNode, SubModuleNode)
-from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, date_fromtimestamp, safe_bytes, safe_unicode
+from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, date_fromtimestamp, safe_bytes, safe_str
 from kallithea.lib.vcs.utils.lazy import LazyProperty
 from kallithea.lib.vcs.utils.paths import get_dirs_for_path
 
@@ -30,15 +30,15 @@
 
     @LazyProperty
     def tags(self):
-        return [safe_unicode(tag) for tag in self._ctx.tags()]
+        return [safe_str(tag) for tag in self._ctx.tags()]
 
     @LazyProperty
     def branch(self):
-        return safe_unicode(self._ctx.branch())
+        return safe_str(self._ctx.branch())
 
     @LazyProperty
     def branches(self):
-        return [safe_unicode(self._ctx.branch())]
+        return [safe_str(self._ctx.branch())]
 
     @LazyProperty
     def closesbranch(self):
@@ -89,19 +89,19 @@
 
     @LazyProperty
     def bookmarks(self):
-        return [safe_unicode(bookmark) for bookmark in self._ctx.bookmarks()]
+        return [safe_str(bookmark) for bookmark in self._ctx.bookmarks()]
 
     @LazyProperty
     def message(self):
-        return safe_unicode(self._ctx.description())
+        return safe_str(self._ctx.description())
 
     @LazyProperty
     def committer(self):
-        return safe_unicode(self.author)
+        return safe_str(self.author)
 
     @LazyProperty
     def author(self):
-        return safe_unicode(self._ctx.user())
+        return safe_str(self._ctx.user())
 
     @LazyProperty
     def date(self):
--- a/kallithea/lib/vcs/backends/hg/repository.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/vcs/backends/hg/repository.py	Thu Jan 02 02:22:14 2020 +0100
@@ -39,7 +39,7 @@
 from kallithea.lib.vcs.backends.base import BaseRepository, CollectionGenerator
 from kallithea.lib.vcs.exceptions import (
     BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, TagAlreadyExistError, TagDoesNotExistError, VCSError)
-from kallithea.lib.vcs.utils import ascii_str, author_email, author_name, date_fromtimestamp, makedate, safe_bytes, safe_unicode
+from kallithea.lib.vcs.utils import ascii_str, author_email, author_name, date_fromtimestamp, makedate, safe_bytes, safe_str
 from kallithea.lib.vcs.utils.lazy import LazyProperty
 from kallithea.lib.vcs.utils.paths import abspath
 
@@ -134,10 +134,10 @@
         for bn, _heads, node, isclosed in sorted(self._repo.branchmap().iterbranches()):
             if isclosed:
                 if closed:
-                    bt[safe_unicode(bn)] = ascii_str(mercurial.node.hex(node))
+                    bt[safe_str(bn)] = ascii_str(mercurial.node.hex(node))
             else:
                 if normal:
-                    bt[safe_unicode(bn)] = ascii_str(mercurial.node.hex(node))
+                    bt[safe_str(bn)] = ascii_str(mercurial.node.hex(node))
         return bt
 
     @LazyProperty
@@ -152,7 +152,7 @@
             return {}
 
         return OrderedDict(sorted(
-            ((safe_unicode(n), ascii_str(mercurial.node.hex(h))) for n, h in self._repo.tags().items()),
+            ((safe_str(n), ascii_str(mercurial.node.hex(h))) for n, h in self._repo.tags().items()),
             reverse=True,
             key=lambda x: x[0],  # sort by name
         ))
@@ -230,7 +230,7 @@
             return {}
 
         return OrderedDict(sorted(
-            ((safe_unicode(n), ascii_str(h)) for n, h in self._repo._bookmarks.items()),
+            ((safe_str(n), ascii_str(h)) for n, h in self._repo._bookmarks.items()),
             reverse=True,
             key=lambda x: x[0],  # sort by name
         ))
@@ -391,11 +391,11 @@
     @LazyProperty
     def description(self):
         _desc = self._repo.ui.config(b'web', b'description', None, untrusted=True)
-        return safe_unicode(_desc or b'unknown')
+        return safe_str(_desc or b'unknown')
 
     @LazyProperty
     def contact(self):
-        return safe_unicode(mercurial.hgweb.common.get_contact(self._repo.ui.config)
+        return safe_str(mercurial.hgweb.common.get_contact(self._repo.ui.config)
                             or b'Unknown')
 
     @LazyProperty
@@ -436,10 +436,10 @@
                 return ascii_str(self._repo[revision].hex())
             return ascii_str(mercurial.scmutil.revsymbol(self._repo, revision).hex())
         except (IndexError, ValueError, mercurial.error.RepoLookupError, TypeError):
-            msg = "Revision %r does not exist for %s" % (safe_unicode(revision), self.name)
+            msg = "Revision %r does not exist for %s" % (safe_str(revision), self.name)
             raise ChangesetDoesNotExistError(msg)
         except (LookupError, ):
-            msg = "Ambiguous identifier `%s` for %s" % (safe_unicode(revision), self.name)
+            msg = "Ambiguous identifier `%s` for %s" % (safe_str(revision), self.name)
             raise ChangesetDoesNotExistError(msg)
 
     def get_ref_revision(self, ref_type, ref_name):
--- a/kallithea/lib/vcs/conf/settings.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/vcs/conf/settings.py	Thu Jan 02 02:22:14 2020 +0100
@@ -18,7 +18,7 @@
 if os.path.isdir(VCSRC_PATH):
     VCSRC_PATH = os.path.join(VCSRC_PATH, '__init__.py')
 
-# list of default encoding used in safe_unicode/safe_bytes methods
+# list of default encoding used in safe_str/safe_bytes methods
 DEFAULT_ENCODINGS = aslist('utf-8')
 
 # path to git executable run by run_git_command function
--- a/kallithea/lib/vcs/nodes.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/vcs/nodes.py	Thu Jan 02 02:22:14 2020 +0100
@@ -16,7 +16,7 @@
 
 from kallithea.lib.vcs.backends.base import EmptyChangeset
 from kallithea.lib.vcs.exceptions import NodeError, RemovedFileNodeError
-from kallithea.lib.vcs.utils import safe_bytes, safe_unicode
+from kallithea.lib.vcs.utils import safe_bytes, safe_str
 from kallithea.lib.vcs.utils.lazy import LazyProperty
 
 
@@ -353,7 +353,7 @@
         """
         from pygments import lexers
         try:
-            lexer = lexers.guess_lexer_for_filename(self.name, safe_unicode(self.content), stripnl=False)
+            lexer = lexers.guess_lexer_for_filename(self.name, safe_str(self.content), stripnl=False)
         except lexers.ClassNotFound:
             lexer = lexers.TextLexer(stripnl=False)
         # returns first alias
--- a/kallithea/lib/vcs/utils/__init__.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/lib/vcs/utils/__init__.py	Thu Jan 02 02:22:14 2020 +0100
@@ -68,7 +68,7 @@
     return val
 
 
-def safe_unicode(s):
+def safe_str(s):
     """
     Safe unicode str function. Use a few tricks to turn s into str:
     In case of UnicodeDecodeError with configured default encodings, try to
@@ -120,9 +120,6 @@
     return s.encode(settings.DEFAULT_ENCODINGS[0], 'replace')
 
 
-safe_str = safe_unicode
-
-
 def ascii_bytes(s):
     """
     Simple conversion from str to bytes, *assuming* all codepoints are
--- a/kallithea/model/db.py	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/model/db.py	Thu Jan 02 02:22:14 2020 +0100
@@ -49,7 +49,7 @@
 from kallithea.lib.caching_query import FromCache
 from kallithea.lib.exceptions import DefaultUserException
 from kallithea.lib.utils2 import (
-    Optional, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_unicode, str2bool, urlreadable)
+    Optional, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_str, 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
@@ -187,7 +187,7 @@
     SETTINGS_TYPES = {
         'str': safe_bytes,
         'int': safe_int,
-        'unicode': safe_unicode,
+        'unicode': safe_str,
         'bool': str2bool,
         'list': functools.partial(aslist, sep=',')
     }
@@ -222,7 +222,7 @@
 
         :param val:
         """
-        self._app_settings_value = safe_unicode(val)
+        self._app_settings_value = safe_str(val)
 
     @hybrid_property
     def app_settings_type(self):
--- a/kallithea/templates/admin/gists/edit.html	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/templates/admin/gists/edit.html	Thu Jan 02 02:22:14 2020 +0100
@@ -73,7 +73,7 @@
                     </div>
                     <div class="panel-body no-padding">
                         <div id="editor_container">
-                            <textarea id="editor_${h.FID('f',file.path)}" name="contents" style="display:none">${safe_unicode(file.content)}</textarea>
+                            <textarea id="editor_${h.FID('f',file.path)}" name="contents" style="display:none">${safe_str(file.content)}</textarea>
                         </div>
                     </div>
                 </div>
--- a/kallithea/templates/files/files_edit.html	Thu Dec 19 22:49:43 2019 +0100
+++ b/kallithea/templates/files/files_edit.html	Thu Jan 02 02:22:14 2020 +0100
@@ -59,7 +59,7 @@
                     </span>
               </div>
               <div class="panel-body no-padding">
-                <textarea id="editor" name="content" style="display:none">${h.escape(h.safe_unicode(c.file.content))|n}</textarea>
+                <textarea id="editor" name="content" style="display:none">${h.escape(h.safe_str(c.file.content))|n}</textarea>
               </div>
             </div>
             <div>