##// END OF EJS Templates
py3: rename all existing safe_unicode to safe_str
Mads Kiilerich -
r8078:08eec03c default
parent child Browse files
Show More
@@ -40,7 +40,7 b' from kallithea.lib import helpers as h'
40 40 from kallithea.lib.auth import LoginRequired
41 41 from kallithea.lib.base import BaseController, jsonify, render
42 42 from kallithea.lib.page import Page
43 from kallithea.lib.utils2 import safe_int, safe_unicode, time_to_datetime
43 from kallithea.lib.utils2 import safe_int, safe_str, time_to_datetime
44 44 from kallithea.lib.vcs.exceptions import NodeNotChangedError, VCSError
45 45 from kallithea.model.db import Gist
46 46 from kallithea.model.forms import GistForm
@@ -183,7 +183,7 b' class GistsController(BaseController):'
183 183 raise HTTPNotFound()
184 184 if format == 'raw':
185 185 content = '\n\n'.join(
186 safe_unicode(f.content)
186 safe_str(f.content)
187 187 for f in c.files if (f_path is None or f.path == f_path)
188 188 )
189 189 response.content_type = 'text/plain'
@@ -42,7 +42,7 b' from kallithea.lib.base import BaseContr'
42 42 from kallithea.lib.celerylib import tasks
43 43 from kallithea.lib.exceptions import HgsubversionImportError
44 44 from kallithea.lib.utils import repo2db_mapper, set_app_settings
45 from kallithea.lib.utils2 import safe_unicode
45 from kallithea.lib.utils2 import safe_str
46 46 from kallithea.lib.vcs import VCSError
47 47 from kallithea.model.db import Repository, Setting, Ui
48 48 from kallithea.model.forms import ApplicationSettingsForm, ApplicationUiSettingsForm, ApplicationVisualisationForm
@@ -168,10 +168,10 b' class SettingsController(BaseController)'
168 168 user=request.authuser.username,
169 169 overwrite_git_hooks=overwrite_git_hooks)
170 170 added_msg = h.HTML(', ').join(
171 h.link_to(safe_unicode(repo_name), h.url('summary_home', repo_name=repo_name)) for repo_name in added
171 h.link_to(safe_str(repo_name), h.url('summary_home', repo_name=repo_name)) for repo_name in added
172 172 ) or '-'
173 173 removed_msg = h.HTML(', ').join(
174 safe_unicode(repo_name) for repo_name in removed
174 safe_str(repo_name) for repo_name in removed
175 175 ) or '-'
176 176 h.flash(h.HTML(_('Repositories successfully rescanned. Added: %s. Removed: %s.')) %
177 177 (added_msg, removed_msg), category='success')
@@ -43,7 +43,7 b' from kallithea.lib.auth import HasPermis'
43 43 from kallithea.lib.base import BaseController, render
44 44 from kallithea.lib.exceptions import RepoGroupAssignmentError, UserGroupsAssignedException
45 45 from kallithea.lib.utils import action_logger
46 from kallithea.lib.utils2 import safe_int, safe_unicode
46 from kallithea.lib.utils2 import safe_int, safe_str
47 47 from kallithea.model.db import User, UserGroup, UserGroupRepoGroupToPerm, UserGroupRepoToPerm, UserGroupToPerm
48 48 from kallithea.model.forms import CustomDefaultPermissionsForm, UserGroupForm, UserGroupPermsForm
49 49 from kallithea.model.meta import Session
@@ -161,7 +161,7 b' class UserGroupsController(BaseControlle'
161 161 c.active = 'settings'
162 162 self.__load_data(id)
163 163
164 available_members = [safe_unicode(x[0]) for x in c.available_members]
164 available_members = [safe_str(x[0]) for x in c.available_members]
165 165
166 166 users_group_form = UserGroupForm(edit=True,
167 167 old_data=c.user_group.get_dict(),
@@ -41,7 +41,7 b' from kallithea.lib.auth import HasRepoPe'
41 41 from kallithea.lib.base import BaseRepoController, jsonify, render
42 42 from kallithea.lib.graphmod import graph_data
43 43 from kallithea.lib.utils import action_logger
44 from kallithea.lib.utils2 import ascii_str, safe_unicode
44 from kallithea.lib.utils2 import ascii_str, safe_str
45 45 from kallithea.lib.vcs.backends.base import EmptyChangeset
46 46 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError
47 47 from kallithea.model.changeset_status import ChangesetStatusModel
@@ -405,7 +405,7 b' class ChangesetController(BaseRepoContro'
405 405 return raw_diff
406 406 elif method == 'patch':
407 407 response.content_type = 'text/plain'
408 c.diff = safe_unicode(raw_diff)
408 c.diff = safe_str(raw_diff)
409 409 return render('changeset/patch_changeset.html')
410 410 elif method == 'raw':
411 411 response.content_type = 'text/plain'
@@ -39,7 +39,7 b' from kallithea.lib import helpers as h'
39 39 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
40 40 from kallithea.lib.base import BaseRepoController
41 41 from kallithea.lib.diffs import DiffProcessor
42 from kallithea.lib.utils2 import safe_int, safe_unicode, str2bool
42 from kallithea.lib.utils2 import safe_int, safe_str, str2bool
43 43
44 44
45 45 log = logging.getLogger(__name__)
@@ -94,7 +94,7 b' class FeedController(BaseRepoController)'
94 94 desc_msg.extend(changes)
95 95 if str2bool(CONFIG.get('rss_include_diff', False)):
96 96 desc_msg.append('\n\n')
97 desc_msg.append(safe_unicode(raw_diff))
97 desc_msg.append(safe_str(raw_diff))
98 98 desc_msg.append('</pre>')
99 99 return desc_msg
100 100
@@ -46,7 +46,7 b' from kallithea.lib.auth import HasRepoPe'
46 46 from kallithea.lib.base import BaseRepoController, jsonify, render
47 47 from kallithea.lib.exceptions import NonRelativePathError
48 48 from kallithea.lib.utils import action_logger
49 from kallithea.lib.utils2 import convert_line_endings, detect_mode, safe_int, safe_unicode, str2bool
49 from kallithea.lib.utils2 import convert_line_endings, detect_mode, safe_int, safe_str, str2bool
50 50 from kallithea.lib.vcs.backends.base import EmptyChangeset
51 51 from kallithea.lib.vcs.conf import settings
52 52 from kallithea.lib.vcs.exceptions import (
@@ -364,7 +364,7 b' class FilesController(BaseRepoController'
364 364 c.f_path = f_path
365 365
366 366 if r_post:
367 old_content = safe_unicode(c.file.content)
367 old_content = safe_str(c.file.content)
368 368 sl = old_content.splitlines(1)
369 369 first_line = sl[0] if sl else ''
370 370 # modes: 0 - Unix, 1 - Mac, 2 - DOS
@@ -46,7 +46,7 b' from kallithea.lib.base import BaseRepoC'
46 46 from kallithea.lib.celerylib.tasks import get_commits_stats
47 47 from kallithea.lib.markup_renderer import MarkupRenderer
48 48 from kallithea.lib.page import Page
49 from kallithea.lib.utils2 import safe_int, safe_unicode
49 from kallithea.lib.utils2 import safe_int, safe_str
50 50 from kallithea.lib.vcs.backends.base import EmptyChangeset
51 51 from kallithea.lib.vcs.exceptions import ChangesetError, EmptyRepositoryError, NodeDoesNotExistError
52 52 from kallithea.lib.vcs.nodes import FileNode
@@ -84,7 +84,7 b' class SummaryController(BaseRepoControll'
84 84 readme_file = f
85 85 log.debug('Found README file `%s` rendering...',
86 86 readme_file)
87 readme_data = renderer.render(safe_unicode(readme.content),
87 readme_data = renderer.render(safe_str(readme.content),
88 88 filename=f)
89 89 break
90 90 except NodeDoesNotExistError:
@@ -30,7 +30,7 b' from pygments.formatters import HtmlForm'
30 30
31 31 from kallithea.lib.vcs.exceptions import VCSError
32 32 from kallithea.lib.vcs.nodes import FileNode
33 from kallithea.lib.vcs.utils import safe_unicode
33 from kallithea.lib.vcs.utils import safe_str
34 34
35 35
36 36 def annotate_highlight(filenode, annotate_from_changeset_func,
@@ -54,7 +54,7 b' def annotate_highlight(filenode, annotat'
54 54 annotate_from_changeset_func=annotate_from_changeset_func, order=order,
55 55 headers=headers, **options)
56 56 lexer = get_custom_lexer(filenode.extension) or filenode.lexer
57 highlighted = highlight(safe_unicode(filenode.content), lexer, formatter)
57 highlighted = highlight(safe_str(filenode.content), lexer, formatter)
58 58 return highlighted
59 59
60 60
@@ -49,7 +49,7 b' from kallithea.lib import auth_modules, '
49 49 from kallithea.lib.auth import AuthUser, HasPermissionAnyMiddleware
50 50 from kallithea.lib.exceptions import UserCreationError
51 51 from kallithea.lib.utils import get_repo_slug, is_valid_repo
52 from kallithea.lib.utils2 import AttributeDict, ascii_bytes, safe_int, safe_unicode, set_hook_environment, str2bool
52 from kallithea.lib.utils2 import AttributeDict, ascii_bytes, safe_int, safe_str, set_hook_environment, str2bool
53 53 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError
54 54 from kallithea.model import meta
55 55 from kallithea.model.db import PullRequest, Repository, Setting, User
@@ -102,7 +102,7 b' def get_path_info(environ):'
102 102 org_req = environ.get('tg.original_request')
103 103 if org_req is not None:
104 104 environ = org_req.environ
105 return safe_unicode(environ['PATH_INFO'])
105 return safe_str(environ['PATH_INFO'])
106 106
107 107
108 108 def log_in_user(user, remember, is_external_auth, ip_addr):
@@ -32,7 +32,7 b' import re'
32 32 from tg.i18n import ugettext as _
33 33
34 34 from kallithea.lib import helpers as h
35 from kallithea.lib.utils2 import safe_unicode
35 from kallithea.lib.utils2 import safe_str
36 36 from kallithea.lib.vcs.backends.base import EmptyChangeset
37 37 from kallithea.lib.vcs.exceptions import VCSError
38 38 from kallithea.lib.vcs.nodes import FileNode, SubModuleNode
@@ -477,7 +477,7 b' def _escaper(string):'
477 477 return ' <i></i>'
478 478 assert False
479 479
480 return _escape_re.sub(substitute, safe_unicode(string))
480 return _escape_re.sub(substitute, safe_str(string))
481 481
482 482
483 483 _git_header_re = re.compile(br"""
@@ -48,7 +48,7 b' from kallithea.lib.markup_renderer impor'
48 48 from kallithea.lib.pygmentsutils import get_custom_lexer
49 49 from kallithea.lib.utils2 import MENTIONS_REGEX, AttributeDict
50 50 from kallithea.lib.utils2 import age as _age
51 from kallithea.lib.utils2 import credentials_filter, safe_bytes, safe_int, safe_unicode, str2bool, time_to_datetime
51 from kallithea.lib.utils2 import credentials_filter, safe_bytes, safe_int, safe_str, str2bool, time_to_datetime
52 52 from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
53 53 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError
54 54 #==============================================================================
@@ -328,7 +328,7 b' def pygmentize(filenode, **kwargs):'
328 328 """
329 329 lexer = get_custom_lexer(filenode.extension) or filenode.lexer
330 330 return literal(markup_whitespace(
331 code_highlight(safe_unicode(filenode.content), lexer, CodeHtmlFormatter(**kwargs))))
331 code_highlight(safe_str(filenode.content), lexer, CodeHtmlFormatter(**kwargs))))
332 332
333 333
334 334 def hsv_to_rgb(h, s, v):
@@ -1222,7 +1222,7 b' def render_w_mentions(source, repo_name='
1222 1222 Render plain text with revision hashes and issue references urlified
1223 1223 and with @mention highlighting.
1224 1224 """
1225 s = safe_unicode(source)
1225 s = safe_str(source)
1226 1226 s = urlify_text(s, repo_name=repo_name)
1227 1227 return literal('<div class="formatted-fixed">%s</div>' % s)
1228 1228
@@ -39,7 +39,7 b' from whoosh.qparser import QueryParser'
39 39
40 40 from kallithea.config.conf import INDEX_EXTENSIONS, INDEX_FILENAMES
41 41 from kallithea.lib.indexers import CHGSET_IDX_NAME, CHGSETS_SCHEMA, IDX_NAME, SCHEMA
42 from kallithea.lib.utils2 import safe_unicode
42 from kallithea.lib.utils2 import safe_str
43 43 from kallithea.lib.vcs.exceptions import ChangesetError, NodeDoesNotExistError, RepositoryError
44 44 from kallithea.model.db import Repository
45 45 from kallithea.model.scm import ScmModel
@@ -184,7 +184,7 b' class WhooshIndexingDaemon(object):'
184 184 u_content = u''
185 185 else:
186 186 log.debug(' >> %s', path)
187 u_content = safe_unicode(bytes_content)
187 u_content = safe_str(bytes_content)
188 188 indexed_w_content += 1
189 189
190 190 else:
@@ -33,7 +33,7 b' import traceback'
33 33 import bleach
34 34 import markdown as markdown_mod
35 35
36 from kallithea.lib.utils2 import MENTIONS_REGEX, safe_unicode
36 from kallithea.lib.utils2 import MENTIONS_REGEX, safe_str
37 37
38 38
39 39 log = logging.getLogger(__name__)
@@ -150,7 +150,7 b' class MarkupRenderer(object):'
150 150
151 151 @classmethod
152 152 def plain(cls, source, universal_newline=True):
153 source = safe_unicode(source)
153 source = safe_str(source)
154 154 if universal_newline:
155 155 newline = '\n'
156 156 source = newline.join(source.splitlines())
@@ -191,7 +191,7 b' class MarkupRenderer(object):'
191 191 </pre></div>
192 192 </td></tr></table>
193 193 """
194 source = safe_unicode(source)
194 source = safe_str(source)
195 195 try:
196 196 if flavored:
197 197 source = cls._flavored_markdown(source)
@@ -209,7 +209,7 b' class MarkupRenderer(object):'
209 209
210 210 @classmethod
211 211 def rst(cls, source, safe=True):
212 source = safe_unicode(source)
212 source = safe_str(source)
213 213 try:
214 214 from docutils.core import publish_parts
215 215 from docutils.parsers.rst import directives
@@ -21,7 +21,7 b' middleware to handle permanent repo URLs'
21 21
22 22
23 23 from kallithea.lib.utils import fix_repo_id_name
24 from kallithea.lib.utils2 import safe_bytes, safe_unicode
24 from kallithea.lib.utils2 import safe_bytes, safe_str
25 25
26 26
27 27 class PermanentRepoUrl(object):
@@ -33,7 +33,7 b' class PermanentRepoUrl(object):'
33 33 def __call__(self, environ, start_response):
34 34 # Extract path_info as get_path_info does, but do it explicitly because
35 35 # we also have to do the reverse operation when patching it back in
36 path_info = safe_unicode(environ['PATH_INFO'])
36 path_info = safe_str(environ['PATH_INFO'])
37 37 if path_info.startswith('/'): # it must
38 38 path_info = '/' + fix_repo_id_name(path_info[1:])
39 39 environ['PATH_INFO'] = safe_bytes(path_info)
@@ -43,7 +43,7 b' from tg.i18n import ugettext as _'
43 43 from tg.i18n import ungettext
44 44 from webhelpers2.text import collapse, remove_formatting, strip_tags
45 45
46 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, safe_bytes, safe_str, safe_unicode # re-export
46 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, safe_bytes, safe_str # re-export
47 47 from kallithea.lib.vcs.utils.lazy import LazyProperty
48 48
49 49
@@ -11,7 +11,7 b' from kallithea.lib.vcs.conf import setti'
11 11 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, ChangesetError, ImproperArchiveTypeError, NodeDoesNotExistError, RepositoryError, VCSError
12 12 from kallithea.lib.vcs.nodes import (
13 13 AddedFileNodesGenerator, ChangedFileNodesGenerator, DirNode, FileNode, NodeKind, RemovedFileNodesGenerator, RootNode, SubModuleNode)
14 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, date_fromtimestamp, safe_int, safe_unicode
14 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, date_fromtimestamp, safe_int, safe_str
15 15 from kallithea.lib.vcs.utils.lazy import LazyProperty
16 16
17 17
@@ -49,15 +49,15 b' class GitChangeset(BaseChangeset):'
49 49
50 50 @LazyProperty
51 51 def message(self):
52 return safe_unicode(self._commit.message)
52 return safe_str(self._commit.message)
53 53
54 54 @LazyProperty
55 55 def committer(self):
56 return safe_unicode(getattr(self._commit, self._committer_property))
56 return safe_str(getattr(self._commit, self._committer_property))
57 57
58 58 @LazyProperty
59 59 def author(self):
60 return safe_unicode(getattr(self._commit, self._author_property))
60 return safe_str(getattr(self._commit, self._author_property))
61 61
62 62 @LazyProperty
63 63 def date(self):
@@ -91,7 +91,7 b' class GitChangeset(BaseChangeset):'
91 91 heads = self.repository._heads(reverse=False)
92 92 ref = heads.get(self._commit.id)
93 93 if ref:
94 return safe_unicode(ref)
94 return safe_str(ref)
95 95
96 96 @LazyProperty
97 97 def branches(self):
@@ -39,7 +39,7 b' class GitInMemoryChangeset(BaseInMemoryC'
39 39 repo = self.repository._repo
40 40 object_store = repo.object_store
41 41
42 ENCODING = b"UTF-8" # TODO: should probably be kept in sync with safe_unicode/safe_bytes and vcs/conf/settings.py DEFAULT_ENCODINGS
42 ENCODING = b"UTF-8" # TODO: should probably be kept in sync with safe_str/safe_bytes and vcs/conf/settings.py DEFAULT_ENCODINGS
43 43
44 44 # Create tree and populates it with blobs
45 45 commit_tree = self.parents[0] and repo[self.parents[0]._commit.tree] or \
@@ -30,7 +30,7 b' from kallithea.lib.vcs.backends.base imp'
30 30 from kallithea.lib.vcs.conf import settings
31 31 from kallithea.lib.vcs.exceptions import (
32 32 BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, TagAlreadyExistError, TagDoesNotExistError)
33 from kallithea.lib.vcs.utils import ascii_str, date_fromtimestamp, makedate, safe_bytes, safe_unicode
33 from kallithea.lib.vcs.utils import ascii_str, date_fromtimestamp, makedate, safe_bytes, safe_str
34 34 from kallithea.lib.vcs.utils.lazy import LazyProperty
35 35 from kallithea.lib.vcs.utils.paths import abspath, get_user_home
36 36
@@ -145,7 +145,7 b' class GitRepository(BaseRepository):'
145 145 if os.path.isdir(self.path):
146 146 cwd = self.path
147 147 stdout, _stderr = self._run_git_command(cmd, cwd=cwd)
148 return safe_unicode(stdout)
148 return safe_str(stdout)
149 149
150 150 @classmethod
151 151 def _check_url(cls, url):
@@ -347,7 +347,7 b' class GitRepository(BaseRepository):'
347 347
348 348 @LazyProperty
349 349 def description(self):
350 return safe_unicode(self._repo.get_description() or b'unknown')
350 return safe_str(self._repo.get_description() or b'unknown')
351 351
352 352 @LazyProperty
353 353 def contact(self):
@@ -10,7 +10,7 b' from kallithea.lib.vcs.conf import setti'
10 10 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, ChangesetError, ImproperArchiveTypeError, NodeDoesNotExistError, VCSError
11 11 from kallithea.lib.vcs.nodes import (
12 12 AddedFileNodesGenerator, ChangedFileNodesGenerator, DirNode, FileNode, NodeKind, RemovedFileNodesGenerator, RootNode, SubModuleNode)
13 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, date_fromtimestamp, safe_bytes, safe_unicode
13 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, date_fromtimestamp, safe_bytes, safe_str
14 14 from kallithea.lib.vcs.utils.lazy import LazyProperty
15 15 from kallithea.lib.vcs.utils.paths import get_dirs_for_path
16 16
@@ -30,15 +30,15 b' class MercurialChangeset(BaseChangeset):'
30 30
31 31 @LazyProperty
32 32 def tags(self):
33 return [safe_unicode(tag) for tag in self._ctx.tags()]
33 return [safe_str(tag) for tag in self._ctx.tags()]
34 34
35 35 @LazyProperty
36 36 def branch(self):
37 return safe_unicode(self._ctx.branch())
37 return safe_str(self._ctx.branch())
38 38
39 39 @LazyProperty
40 40 def branches(self):
41 return [safe_unicode(self._ctx.branch())]
41 return [safe_str(self._ctx.branch())]
42 42
43 43 @LazyProperty
44 44 def closesbranch(self):
@@ -89,19 +89,19 b' class MercurialChangeset(BaseChangeset):'
89 89
90 90 @LazyProperty
91 91 def bookmarks(self):
92 return [safe_unicode(bookmark) for bookmark in self._ctx.bookmarks()]
92 return [safe_str(bookmark) for bookmark in self._ctx.bookmarks()]
93 93
94 94 @LazyProperty
95 95 def message(self):
96 return safe_unicode(self._ctx.description())
96 return safe_str(self._ctx.description())
97 97
98 98 @LazyProperty
99 99 def committer(self):
100 return safe_unicode(self.author)
100 return safe_str(self.author)
101 101
102 102 @LazyProperty
103 103 def author(self):
104 return safe_unicode(self._ctx.user())
104 return safe_str(self._ctx.user())
105 105
106 106 @LazyProperty
107 107 def date(self):
@@ -39,7 +39,7 b' import mercurial.util'
39 39 from kallithea.lib.vcs.backends.base import BaseRepository, CollectionGenerator
40 40 from kallithea.lib.vcs.exceptions import (
41 41 BranchDoesNotExistError, ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, TagAlreadyExistError, TagDoesNotExistError, VCSError)
42 from kallithea.lib.vcs.utils import ascii_str, author_email, author_name, date_fromtimestamp, makedate, safe_bytes, safe_unicode
42 from kallithea.lib.vcs.utils import ascii_str, author_email, author_name, date_fromtimestamp, makedate, safe_bytes, safe_str
43 43 from kallithea.lib.vcs.utils.lazy import LazyProperty
44 44 from kallithea.lib.vcs.utils.paths import abspath
45 45
@@ -134,10 +134,10 b' class MercurialRepository(BaseRepository'
134 134 for bn, _heads, node, isclosed in sorted(self._repo.branchmap().iterbranches()):
135 135 if isclosed:
136 136 if closed:
137 bt[safe_unicode(bn)] = ascii_str(mercurial.node.hex(node))
137 bt[safe_str(bn)] = ascii_str(mercurial.node.hex(node))
138 138 else:
139 139 if normal:
140 bt[safe_unicode(bn)] = ascii_str(mercurial.node.hex(node))
140 bt[safe_str(bn)] = ascii_str(mercurial.node.hex(node))
141 141 return bt
142 142
143 143 @LazyProperty
@@ -152,7 +152,7 b' class MercurialRepository(BaseRepository'
152 152 return {}
153 153
154 154 return OrderedDict(sorted(
155 ((safe_unicode(n), ascii_str(mercurial.node.hex(h))) for n, h in self._repo.tags().items()),
155 ((safe_str(n), ascii_str(mercurial.node.hex(h))) for n, h in self._repo.tags().items()),
156 156 reverse=True,
157 157 key=lambda x: x[0], # sort by name
158 158 ))
@@ -230,7 +230,7 b' class MercurialRepository(BaseRepository'
230 230 return {}
231 231
232 232 return OrderedDict(sorted(
233 ((safe_unicode(n), ascii_str(h)) for n, h in self._repo._bookmarks.items()),
233 ((safe_str(n), ascii_str(h)) for n, h in self._repo._bookmarks.items()),
234 234 reverse=True,
235 235 key=lambda x: x[0], # sort by name
236 236 ))
@@ -391,11 +391,11 b' class MercurialRepository(BaseRepository'
391 391 @LazyProperty
392 392 def description(self):
393 393 _desc = self._repo.ui.config(b'web', b'description', None, untrusted=True)
394 return safe_unicode(_desc or b'unknown')
394 return safe_str(_desc or b'unknown')
395 395
396 396 @LazyProperty
397 397 def contact(self):
398 return safe_unicode(mercurial.hgweb.common.get_contact(self._repo.ui.config)
398 return safe_str(mercurial.hgweb.common.get_contact(self._repo.ui.config)
399 399 or b'Unknown')
400 400
401 401 @LazyProperty
@@ -436,10 +436,10 b' class MercurialRepository(BaseRepository'
436 436 return ascii_str(self._repo[revision].hex())
437 437 return ascii_str(mercurial.scmutil.revsymbol(self._repo, revision).hex())
438 438 except (IndexError, ValueError, mercurial.error.RepoLookupError, TypeError):
439 msg = "Revision %r does not exist for %s" % (safe_unicode(revision), self.name)
439 msg = "Revision %r does not exist for %s" % (safe_str(revision), self.name)
440 440 raise ChangesetDoesNotExistError(msg)
441 441 except (LookupError, ):
442 msg = "Ambiguous identifier `%s` for %s" % (safe_unicode(revision), self.name)
442 msg = "Ambiguous identifier `%s` for %s" % (safe_str(revision), self.name)
443 443 raise ChangesetDoesNotExistError(msg)
444 444
445 445 def get_ref_revision(self, ref_type, ref_name):
@@ -18,7 +18,7 b' VCSRC_PATH = VCSRC_PATH or abspath(HOME_'
18 18 if os.path.isdir(VCSRC_PATH):
19 19 VCSRC_PATH = os.path.join(VCSRC_PATH, '__init__.py')
20 20
21 # list of default encoding used in safe_unicode/safe_bytes methods
21 # list of default encoding used in safe_str/safe_bytes methods
22 22 DEFAULT_ENCODINGS = aslist('utf-8')
23 23
24 24 # path to git executable run by run_git_command function
@@ -16,7 +16,7 b' import stat'
16 16
17 17 from kallithea.lib.vcs.backends.base import EmptyChangeset
18 18 from kallithea.lib.vcs.exceptions import NodeError, RemovedFileNodeError
19 from kallithea.lib.vcs.utils import safe_bytes, safe_unicode
19 from kallithea.lib.vcs.utils import safe_bytes, safe_str
20 20 from kallithea.lib.vcs.utils.lazy import LazyProperty
21 21
22 22
@@ -353,7 +353,7 b' class FileNode(Node):'
353 353 """
354 354 from pygments import lexers
355 355 try:
356 lexer = lexers.guess_lexer_for_filename(self.name, safe_unicode(self.content), stripnl=False)
356 lexer = lexers.guess_lexer_for_filename(self.name, safe_str(self.content), stripnl=False)
357 357 except lexers.ClassNotFound:
358 358 lexer = lexers.TextLexer(stripnl=False)
359 359 # returns first alias
@@ -68,7 +68,7 b' def safe_int(val, default=None):'
68 68 return val
69 69
70 70
71 def safe_unicode(s):
71 def safe_str(s):
72 72 """
73 73 Safe unicode str function. Use a few tricks to turn s into str:
74 74 In case of UnicodeDecodeError with configured default encodings, try to
@@ -120,9 +120,6 b' def safe_bytes(s):'
120 120 return s.encode(settings.DEFAULT_ENCODINGS[0], 'replace')
121 121
122 122
123 safe_str = safe_unicode
124
125
126 123 def ascii_bytes(s):
127 124 """
128 125 Simple conversion from str to bytes, *assuming* all codepoints are
@@ -49,7 +49,7 b' from kallithea.lib import ext_json'
49 49 from kallithea.lib.caching_query import FromCache
50 50 from kallithea.lib.exceptions import DefaultUserException
51 51 from kallithea.lib.utils2 import (
52 Optional, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_unicode, str2bool, urlreadable)
52 Optional, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_str, str2bool, urlreadable)
53 53 from kallithea.lib.vcs import get_backend
54 54 from kallithea.lib.vcs.backends.base import EmptyChangeset
55 55 from kallithea.lib.vcs.utils.helpers import get_scm
@@ -187,7 +187,7 b' class Setting(Base, BaseDbModel):'
187 187 SETTINGS_TYPES = {
188 188 'str': safe_bytes,
189 189 'int': safe_int,
190 'unicode': safe_unicode,
190 'unicode': safe_str,
191 191 'bool': str2bool,
192 192 'list': functools.partial(aslist, sep=',')
193 193 }
@@ -222,7 +222,7 b' class Setting(Base, BaseDbModel):'
222 222
223 223 :param val:
224 224 """
225 self._app_settings_value = safe_unicode(val)
225 self._app_settings_value = safe_str(val)
226 226
227 227 @hybrid_property
228 228 def app_settings_type(self):
@@ -73,7 +73,7 b''
73 73 </div>
74 74 <div class="panel-body no-padding">
75 75 <div id="editor_container">
76 <textarea id="editor_${h.FID('f',file.path)}" name="contents" style="display:none">${safe_unicode(file.content)}</textarea>
76 <textarea id="editor_${h.FID('f',file.path)}" name="contents" style="display:none">${safe_str(file.content)}</textarea>
77 77 </div>
78 78 </div>
79 79 </div>
@@ -59,7 +59,7 b''
59 59 </span>
60 60 </div>
61 61 <div class="panel-body no-padding">
62 <textarea id="editor" name="content" style="display:none">${h.escape(h.safe_unicode(c.file.content))|n}</textarea>
62 <textarea id="editor" name="content" style="display:none">${h.escape(h.safe_str(c.file.content))|n}</textarea>
63 63 </div>
64 64 </div>
65 65 <div>
General Comments 0
You need to be logged in to leave comments. Login now