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