diff --git a/kallithea/controllers/admin/gists.py b/kallithea/controllers/admin/gists.py
--- a/kallithea/controllers/admin/gists.py
+++ b/kallithea/controllers/admin/gists.py
@@ -40,7 +40,7 @@ from kallithea.lib import helpers as h
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 @@ class GistsController(BaseController):
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'
diff --git a/kallithea/controllers/admin/settings.py b/kallithea/controllers/admin/settings.py
--- a/kallithea/controllers/admin/settings.py
+++ b/kallithea/controllers/admin/settings.py
@@ -42,7 +42,7 @@ from kallithea.lib.base import BaseContr
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 @@ class SettingsController(BaseController)
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')
diff --git a/kallithea/controllers/admin/user_groups.py b/kallithea/controllers/admin/user_groups.py
--- a/kallithea/controllers/admin/user_groups.py
+++ b/kallithea/controllers/admin/user_groups.py
@@ -43,7 +43,7 @@ from kallithea.lib.auth import HasPermis
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 @@ class UserGroupsController(BaseControlle
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(),
diff --git a/kallithea/controllers/changeset.py b/kallithea/controllers/changeset.py
--- a/kallithea/controllers/changeset.py
+++ b/kallithea/controllers/changeset.py
@@ -41,7 +41,7 @@ from kallithea.lib.auth import HasRepoPe
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 @@ class ChangesetController(BaseRepoContro
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'
diff --git a/kallithea/controllers/feed.py b/kallithea/controllers/feed.py
--- a/kallithea/controllers/feed.py
+++ b/kallithea/controllers/feed.py
@@ -39,7 +39,7 @@ from kallithea.lib import helpers as h
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 @@ class FeedController(BaseRepoController)
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('')
return desc_msg
diff --git a/kallithea/controllers/files.py b/kallithea/controllers/files.py
--- a/kallithea/controllers/files.py
+++ b/kallithea/controllers/files.py
@@ -46,7 +46,7 @@ from kallithea.lib.auth import HasRepoPe
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 @@ class FilesController(BaseRepoController
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
diff --git a/kallithea/controllers/summary.py b/kallithea/controllers/summary.py
--- a/kallithea/controllers/summary.py
+++ b/kallithea/controllers/summary.py
@@ -46,7 +46,7 @@ from kallithea.lib.base import BaseRepoC
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 @@ class SummaryController(BaseRepoControll
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:
diff --git a/kallithea/lib/annotate.py b/kallithea/lib/annotate.py
--- a/kallithea/lib/annotate.py
+++ b/kallithea/lib/annotate.py
@@ -30,7 +30,7 @@ from pygments.formatters import HtmlForm
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 @@ def annotate_highlight(filenode, annotat
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
diff --git a/kallithea/lib/base.py b/kallithea/lib/base.py
--- a/kallithea/lib/base.py
+++ b/kallithea/lib/base.py
@@ -49,7 +49,7 @@ from kallithea.lib import auth_modules,
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 @@ def get_path_info(environ):
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):
diff --git a/kallithea/lib/diffs.py b/kallithea/lib/diffs.py
--- a/kallithea/lib/diffs.py
+++ b/kallithea/lib/diffs.py
@@ -32,7 +32,7 @@ import re
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 @@ def _escaper(string):
return ' '
assert False
- return _escape_re.sub(substitute, safe_unicode(string))
+ return _escape_re.sub(substitute, safe_str(string))
_git_header_re = re.compile(br"""
diff --git a/kallithea/lib/helpers.py b/kallithea/lib/helpers.py
--- a/kallithea/lib/helpers.py
+++ b/kallithea/lib/helpers.py
@@ -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_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 @@ def pygmentize(filenode, **kwargs):
"""
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 @@ def render_w_mentions(source, repo_name=
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('
%s
' % s)
diff --git a/kallithea/lib/indexers/daemon.py b/kallithea/lib/indexers/daemon.py
--- a/kallithea/lib/indexers/daemon.py
+++ b/kallithea/lib/indexers/daemon.py
@@ -39,7 +39,7 @@ from whoosh.qparser import QueryParser
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 @@ class WhooshIndexingDaemon(object):
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:
diff --git a/kallithea/lib/markup_renderer.py b/kallithea/lib/markup_renderer.py
--- a/kallithea/lib/markup_renderer.py
+++ b/kallithea/lib/markup_renderer.py
@@ -33,7 +33,7 @@ import traceback
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 @@ class MarkupRenderer(object):
@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 @@ class MarkupRenderer(object):
"""
- source = safe_unicode(source)
+ source = safe_str(source)
try:
if flavored:
source = cls._flavored_markdown(source)
@@ -209,7 +209,7 @@ class MarkupRenderer(object):
@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
diff --git a/kallithea/lib/middleware/permanent_repo_url.py b/kallithea/lib/middleware/permanent_repo_url.py
--- a/kallithea/lib/middleware/permanent_repo_url.py
+++ b/kallithea/lib/middleware/permanent_repo_url.py
@@ -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_bytes, safe_unicode
+from kallithea.lib.utils2 import safe_bytes, safe_str
class PermanentRepoUrl(object):
@@ -33,7 +33,7 @@ class PermanentRepoUrl(object):
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)
diff --git a/kallithea/lib/utils2.py b/kallithea/lib/utils2.py
--- a/kallithea/lib/utils2.py
+++ b/kallithea/lib/utils2.py
@@ -43,7 +43,7 @@ from tg.i18n import ugettext as _
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
diff --git a/kallithea/lib/vcs/backends/git/changeset.py b/kallithea/lib/vcs/backends/git/changeset.py
--- a/kallithea/lib/vcs/backends/git/changeset.py
+++ b/kallithea/lib/vcs/backends/git/changeset.py
@@ -11,7 +11,7 @@ from kallithea.lib.vcs.conf import setti
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 @@ class GitChangeset(BaseChangeset):
@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 @@ class GitChangeset(BaseChangeset):
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):
diff --git a/kallithea/lib/vcs/backends/git/inmemory.py b/kallithea/lib/vcs/backends/git/inmemory.py
--- a/kallithea/lib/vcs/backends/git/inmemory.py
+++ b/kallithea/lib/vcs/backends/git/inmemory.py
@@ -39,7 +39,7 @@ class GitInMemoryChangeset(BaseInMemoryC
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 \
diff --git a/kallithea/lib/vcs/backends/git/repository.py b/kallithea/lib/vcs/backends/git/repository.py
--- a/kallithea/lib/vcs/backends/git/repository.py
+++ b/kallithea/lib/vcs/backends/git/repository.py
@@ -30,7 +30,7 @@ from kallithea.lib.vcs.backends.base imp
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 @@ class GitRepository(BaseRepository):
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 @@ class GitRepository(BaseRepository):
@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):
diff --git a/kallithea/lib/vcs/backends/hg/changeset.py b/kallithea/lib/vcs/backends/hg/changeset.py
--- a/kallithea/lib/vcs/backends/hg/changeset.py
+++ b/kallithea/lib/vcs/backends/hg/changeset.py
@@ -10,7 +10,7 @@ from kallithea.lib.vcs.conf import setti
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 @@ class MercurialChangeset(BaseChangeset):
@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 @@ class MercurialChangeset(BaseChangeset):
@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):
diff --git a/kallithea/lib/vcs/backends/hg/repository.py b/kallithea/lib/vcs/backends/hg/repository.py
--- a/kallithea/lib/vcs/backends/hg/repository.py
+++ b/kallithea/lib/vcs/backends/hg/repository.py
@@ -39,7 +39,7 @@ import mercurial.util
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 @@ class MercurialRepository(BaseRepository
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 @@ class MercurialRepository(BaseRepository
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 @@ class MercurialRepository(BaseRepository
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 @@ class MercurialRepository(BaseRepository
@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 @@ class MercurialRepository(BaseRepository
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):
diff --git a/kallithea/lib/vcs/conf/settings.py b/kallithea/lib/vcs/conf/settings.py
--- a/kallithea/lib/vcs/conf/settings.py
+++ b/kallithea/lib/vcs/conf/settings.py
@@ -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_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
diff --git a/kallithea/lib/vcs/nodes.py b/kallithea/lib/vcs/nodes.py
--- a/kallithea/lib/vcs/nodes.py
+++ b/kallithea/lib/vcs/nodes.py
@@ -16,7 +16,7 @@ import stat
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 @@ class FileNode(Node):
"""
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
diff --git a/kallithea/lib/vcs/utils/__init__.py b/kallithea/lib/vcs/utils/__init__.py
--- a/kallithea/lib/vcs/utils/__init__.py
+++ b/kallithea/lib/vcs/utils/__init__.py
@@ -68,7 +68,7 @@ def safe_int(val, default=None):
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 @@ def safe_bytes(s):
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
diff --git a/kallithea/model/db.py b/kallithea/model/db.py
--- a/kallithea/model/db.py
+++ b/kallithea/model/db.py
@@ -49,7 +49,7 @@ from kallithea.lib import ext_json
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 @@ class Setting(Base, BaseDbModel):
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 @@ class Setting(Base, BaseDbModel):
:param val:
"""
- self._app_settings_value = safe_unicode(val)
+ self._app_settings_value = safe_str(val)
@hybrid_property
def app_settings_type(self):
diff --git a/kallithea/templates/admin/gists/edit.html b/kallithea/templates/admin/gists/edit.html
--- a/kallithea/templates/admin/gists/edit.html
+++ b/kallithea/templates/admin/gists/edit.html
@@ -73,7 +73,7 @@
diff --git a/kallithea/templates/files/files_edit.html b/kallithea/templates/files/files_edit.html
--- a/kallithea/templates/files/files_edit.html
+++ b/kallithea/templates/files/files_edit.html
@@ -59,7 +59,7 @@
-
+