Show More
@@ -36,7 +36,7 b' from rhodecode import events' | |||
|
36 | 36 | from rhodecode.lib import helpers as h |
|
37 | 37 | from rhodecode.lib.auth import ( |
|
38 | 38 | LoginRequired, HasPermissionAllDecorator, CSRFRequired) |
|
39 |
from rhodecode.lib.utils2 import aslist, safe_ |
|
|
39 | from rhodecode.lib.utils2 import aslist, safe_str | |
|
40 | 40 | from rhodecode.model.db import ( |
|
41 | 41 | or_, coalesce, User, UserIpMap, UserSshKeys) |
|
42 | 42 | from rhodecode.model.forms import ( |
@@ -410,7 +410,7 b' class AdminPermissionsView(BaseAppView, ' | |||
|
410 | 410 | base_q = UserSshKeys.query().join(UserSshKeys.user) |
|
411 | 411 | |
|
412 | 412 | if search_q: |
|
413 |
like_expression = u'%{}%'.format(safe_ |
|
|
413 | like_expression = u'%{}%'.format(safe_str(search_q)) | |
|
414 | 414 | base_q = base_q.filter(or_( |
|
415 | 415 | User.username.ilike(like_expression), |
|
416 | 416 | UserSshKeys.ssh_key_fingerprint.ilike(like_expression), |
@@ -36,7 +36,7 b' from rhodecode.lib.auth import (' | |||
|
36 | 36 | LoginRequired, CSRFRequired, NotAnonymous, |
|
37 | 37 | HasPermissionAny, HasRepoGroupPermissionAny) |
|
38 | 38 | from rhodecode.lib import helpers as h, audit_logger |
|
39 |
from rhodecode.lib.utils |
|
|
39 | from rhodecode.lib.str_utils import safe_int, safe_str | |
|
40 | 40 | from rhodecode.model.forms import RepoGroupForm |
|
41 | 41 | from rhodecode.model.permission import PermissionModel |
|
42 | 42 | from rhodecode.model.repo_group import RepoGroupModel |
@@ -36,7 +36,7 b' from rhodecode.lib.auth import (' | |||
|
36 | 36 | HasPermissionAny, HasRepoGroupPermissionAny) |
|
37 | 37 | from rhodecode.lib import helpers as h |
|
38 | 38 | from rhodecode.lib.utils import repo_name_slug |
|
39 |
from rhodecode.lib.utils2 import safe_int, safe_ |
|
|
39 | from rhodecode.lib.utils2 import safe_int, safe_str | |
|
40 | 40 | from rhodecode.model.forms import RepoForm |
|
41 | 41 | from rhodecode.model.permission import PermissionModel |
|
42 | 42 | from rhodecode.model.repo import RepoModel |
@@ -58,7 +58,7 b' class AdminReposView(BaseAppView, DataGr' | |||
|
58 | 58 | acl_groups = RepoGroupList(RepoGroup.query().all(), |
|
59 | 59 | perm_set=['group.write', 'group.admin']) |
|
60 | 60 | c.repo_groups = RepoGroup.groups_choices(groups=acl_groups) |
|
61 |
c.repo_groups_choices = map(lambda k: safe_ |
|
|
61 | c.repo_groups_choices = list(map(lambda k: safe_str(k[0]), c.repo_groups)) | |
|
62 | 62 | c.personal_repo_group = self._rhodecode_user.personal_repo_group |
|
63 | 63 | |
|
64 | 64 | @LoginRequired() |
@@ -114,7 +114,7 b' class AdminReposView(BaseAppView, DataGr' | |||
|
114 | 114 | .group_by(Repository, User) |
|
115 | 115 | |
|
116 | 116 | if search_q: |
|
117 |
like_expression = u'%{}%'.format(safe_ |
|
|
117 | like_expression = u'%{}%'.format(safe_str(search_q)) | |
|
118 | 118 | base_q = base_q.filter(or_( |
|
119 | 119 | Repository.repo_name.ilike(like_expression), |
|
120 | 120 | )) |
@@ -38,8 +38,9 b' from rhodecode.lib import helpers as h' | |||
|
38 | 38 | from rhodecode.lib.auth import ( |
|
39 | 39 | LoginRequired, HasPermissionAllDecorator, CSRFRequired) |
|
40 | 40 | from rhodecode.lib.celerylib import tasks, run_task |
|
41 | from rhodecode.lib.str_utils import safe_str | |
|
41 | 42 | from rhodecode.lib.utils import repo2db_mapper |
|
42 |
from rhodecode.lib.utils2 import str2bool, |
|
|
43 | from rhodecode.lib.utils2 import str2bool, AttributeDict | |
|
43 | 44 | from rhodecode.lib.index import searcher_from_config |
|
44 | 45 | |
|
45 | 46 | from rhodecode.model.db import RhodeCodeUi, Repository |
@@ -248,7 +249,8 b' class AdminSettingsView(BaseAppView):' | |||
|
248 | 249 | added, removed = repo2db_mapper(filesystem_repos, rm_obsolete) |
|
249 | 250 | PermissionModel().trigger_permission_flush() |
|
250 | 251 | |
|
251 | _repr = lambda l: ', '.join(map(safe_unicode, l)) or '-' | |
|
252 | def _repr(l): | |
|
253 | return ', '.join(map(safe_str, l)) or '-' | |
|
252 | 254 | h.flash(_('Repositories successfully ' |
|
253 | 255 | 'rescanned added: %s ; removed: %s') % |
|
254 | 256 | (_repr(added), _repr(removed)), |
@@ -311,6 +313,7 b' class AdminSettingsView(BaseAppView):' | |||
|
311 | 313 | ('create_personal_repo_group', 'rhodecode_create_personal_repo_group', 'bool'), |
|
312 | 314 | ('personal_repo_group_pattern', 'rhodecode_personal_repo_group_pattern', 'unicode'), |
|
313 | 315 | ] |
|
316 | ||
|
314 | 317 | try: |
|
315 | 318 | for setting, form_key, type_ in settings: |
|
316 | 319 | sett = SettingsModel().create_or_update_setting( |
@@ -19,7 +19,9 b'' | |||
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import logging |
|
22 |
import urllib.request |
|
|
22 | import urllib.request | |
|
23 | import urllib.error | |
|
24 | import urllib.parse | |
|
23 | 25 | import os |
|
24 | 26 | |
|
25 | 27 | import rhodecode |
@@ -206,7 +208,8 b' class AdminSystemInfoSettingsView(BaseAp' | |||
|
206 | 208 | |
|
207 | 209 | update_url = UpdateModel().get_update_url() |
|
208 | 210 | |
|
209 | _err = lambda s: '<div style="color:#ff8888; padding:4px 0px">{}</div>'.format(s) | |
|
211 | def _err(s): | |
|
212 | return '<div style="color:#ff8888; padding:4px 0px">{}</div>'.format(s) | |
|
210 | 213 | try: |
|
211 | 214 | data = UpdateModel().get_update_data(update_url) |
|
212 | 215 | except urllib.error.URLError as e: |
@@ -33,11 +33,10 b' from rhodecode.apps._base import BaseApp' | |||
|
33 | 33 | from rhodecode.lib.auth import ( |
|
34 | 34 | LoginRequired, NotAnonymous, CSRFRequired, HasPermissionAnyDecorator) |
|
35 | 35 | from rhodecode.lib import helpers as h, audit_logger |
|
36 |
from rhodecode.lib.utils |
|
|
36 | from rhodecode.lib.str_utils import safe_str | |
|
37 | 37 | |
|
38 | 38 | from rhodecode.model.forms import UserGroupForm |
|
39 | 39 | from rhodecode.model.permission import PermissionModel |
|
40 | from rhodecode.model.scm import UserGroupList | |
|
41 | 40 | from rhodecode.model.db import ( |
|
42 | 41 | or_, count, User, UserGroup, UserGroupMember, in_filter_generator) |
|
43 | 42 | from rhodecode.model.meta import Session |
@@ -129,7 +128,7 b' class AdminUserGroupsView(BaseAppView, D' | |||
|
129 | 128 | base_q_inactive = base_q.filter(UserGroup.users_group_active != true()) |
|
130 | 129 | |
|
131 | 130 | if search_q: |
|
132 |
like_expression = u'%{}%'.format(safe_ |
|
|
131 | like_expression = u'%{}%'.format(safe_str(search_q)) | |
|
133 | 132 | base_q = base_q.filter(or_( |
|
134 | 133 | UserGroup.users_group_name.ilike(like_expression), |
|
135 | 134 | )) |
@@ -45,7 +45,7 b' from rhodecode.lib.auth import (' | |||
|
45 | 45 | LoginRequired, HasPermissionAllDecorator, CSRFRequired) |
|
46 | 46 | from rhodecode.lib import helpers as h |
|
47 | 47 | from rhodecode.lib.helpers import SqlPage |
|
48 |
from rhodecode.lib.utils2 import safe_int, safe_ |
|
|
48 | from rhodecode.lib.utils2 import safe_int, safe_str, AttributeDict | |
|
49 | 49 | from rhodecode.model.auth_token import AuthTokenModel |
|
50 | 50 | from rhodecode.model.forms import ( |
|
51 | 51 | UserForm, UserIndividualPermissionsForm, UserPermissionsForm, |
@@ -106,7 +106,7 b' class AdminUsersView(BaseAppView, DataGr' | |||
|
106 | 106 | base_inactive_q = base_q.filter(User.active != true()) |
|
107 | 107 | |
|
108 | 108 | if search_q: |
|
109 |
like_expression = '%{}%'.format(safe_ |
|
|
109 | like_expression = '%{}%'.format(safe_str(search_q)) | |
|
110 | 110 | base_q = base_q.filter(or_( |
|
111 | 111 | User.username.ilike(like_expression), |
|
112 | 112 | User._email.ilike(like_expression), |
@@ -223,7 +223,7 b' class AdminUsersView(BaseAppView, DataGr' | |||
|
223 | 223 | ) |
|
224 | 224 | return Response(html) |
|
225 | 225 | except UserCreationError as e: |
|
226 |
h.flash(safe_ |
|
|
226 | h.flash(safe_str(e), 'error') | |
|
227 | 227 | except Exception: |
|
228 | 228 | log.exception("Exception creation of user") |
|
229 | 229 | h.flash(_('Error occurred during creation of user %s') |
@@ -347,7 +347,7 b' class UsersView(UserAppView):' | |||
|
347 | 347 | ) |
|
348 | 348 | return Response(html) |
|
349 | 349 | except UserCreationError as e: |
|
350 |
h.flash(safe_ |
|
|
350 | h.flash(safe_str(e), 'error') | |
|
351 | 351 | except Exception: |
|
352 | 352 | log.exception("Exception updating user") |
|
353 | 353 | h.flash(_('Error occurred during update of user %s') |
@@ -470,7 +470,8 b' class UsersView(UserAppView):' | |||
|
470 | 470 | except (UserOwnsReposException, UserOwnsRepoGroupsException, |
|
471 | 471 | UserOwnsUserGroupsException, UserOwnsPullRequestsException, |
|
472 | 472 | UserOwnsArtifactsException, DefaultUserException) as e: |
|
473 | h.flash(e, category='warning') | |
|
473 | ||
|
474 | h.flash(safe_str(e), category='warning') | |
|
474 | 475 | except Exception: |
|
475 | 476 | log.exception("Exception during deletion of user") |
|
476 | 477 | h.flash(_('An error occurred during deletion of user'), |
@@ -23,8 +23,8 b' from pyramid.events import ApplicationCr' | |||
|
23 | 23 | from pyramid.settings import asbool |
|
24 | 24 | |
|
25 | 25 | from rhodecode.apps._base import ADMIN_PREFIX |
|
26 | from rhodecode.lib.ext_json import json | |
|
27 | from rhodecode.lib.str_utils import safe_str | |
|
26 | from rhodecode.lib.ext_json import str_json | |
|
27 | ||
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | def url_gen(request): |
@@ -38,7 +38,7 b' def url_gen(request):' | |||
|
38 | 38 | 'longpoll': longpoll_url or proxy_url, |
|
39 | 39 | 'ws': ws_url or proxy_url.replace('http', 'ws') |
|
40 | 40 | } |
|
41 |
return s |
|
|
41 | return str_json(urls) | |
|
42 | 42 | |
|
43 | 43 | |
|
44 | 44 | PLUGIN_DEFINITION = { |
@@ -25,7 +25,7 b' class VCSCallPredicate(object):' | |||
|
25 | 25 | self.val = val |
|
26 | 26 | |
|
27 | 27 | def text(self): |
|
28 |
return 'vcs_call route = |
|
|
28 | return f'vcs_call route = {self.val}' | |
|
29 | 29 | |
|
30 | 30 | phash = text |
|
31 | 31 |
@@ -31,7 +31,7 b' from rhodecode.lib.auth import (' | |||
|
31 | 31 | HasRepoGroupPermissionAny, AuthUser) |
|
32 | 32 | from rhodecode.lib.codeblocks import filenode_as_lines_tokens |
|
33 | 33 | from rhodecode.lib.index import searcher_from_config |
|
34 |
from rhodecode.lib.utils2 import |
|
|
34 | from rhodecode.lib.utils2 import str2bool, safe_int, safe_str | |
|
35 | 35 | from rhodecode.lib.vcs.nodes import FileNode |
|
36 | 36 | from rhodecode.model.db import ( |
|
37 | 37 | func, true, or_, case, cast, in_filter_generator, String, Session, |
@@ -129,7 +129,7 b' class HomeView(BaseAppView, DataGridAppV' | |||
|
129 | 129 | query = query.filter(Repository.repo_type == repo_type) |
|
130 | 130 | |
|
131 | 131 | if name_contains: |
|
132 |
ilike_expression = |
|
|
132 | ilike_expression = '%{}%'.format(safe_str(name_contains)) | |
|
133 | 133 | query = query.filter( |
|
134 | 134 | Repository.repo_name.ilike(ilike_expression)) |
|
135 | 135 | query = query.limit(limit) |
@@ -174,7 +174,7 b' class HomeView(BaseAppView, DataGridAppV' | |||
|
174 | 174 | query = query.order_by(RepoGroup.group_name) |
|
175 | 175 | |
|
176 | 176 | if name_contains: |
|
177 |
ilike_expression = u'%{}%'.format(safe_ |
|
|
177 | ilike_expression = u'%{}%'.format(safe_str(name_contains)) | |
|
178 | 178 | query = query.filter( |
|
179 | 179 | RepoGroup.group_name.ilike(ilike_expression)) |
|
180 | 180 | query = query.limit(limit) |
@@ -216,7 +216,7 b' class HomeView(BaseAppView, DataGridAppV' | |||
|
216 | 216 | .filter(User.username != User.DEFAULT_USER) |
|
217 | 217 | |
|
218 | 218 | if name_contains: |
|
219 |
ilike_expression = u'%{}%'.format(safe_ |
|
|
219 | ilike_expression = u'%{}%'.format(safe_str(name_contains)) | |
|
220 | 220 | query = query.filter( |
|
221 | 221 | User.username.ilike(ilike_expression)) |
|
222 | 222 | query = query.limit(limit) |
@@ -256,7 +256,7 b' class HomeView(BaseAppView, DataGridAppV' | |||
|
256 | 256 | .order_by(UserGroup.users_group_name) |
|
257 | 257 | |
|
258 | 258 | if name_contains: |
|
259 |
ilike_expression = u'%{}%'.format(safe_ |
|
|
259 | ilike_expression = u'%{}%'.format(safe_str(name_contains)) | |
|
260 | 260 | query = query.filter( |
|
261 | 261 | UserGroup.users_group_name.ilike(ilike_expression)) |
|
262 | 262 | query = query.limit(limit) |
@@ -308,7 +308,7 b' class HomeView(BaseAppView, DataGridAppV' | |||
|
308 | 308 | query = query.order_by(PullRequest.pull_request_id) |
|
309 | 309 | |
|
310 | 310 | if name_contains: |
|
311 |
ilike_expression = u'%{}%'.format(safe_ |
|
|
311 | ilike_expression = u'%{}%'.format(safe_str(name_contains)) | |
|
312 | 312 | query = query.filter(or_( |
|
313 | 313 | cast(PullRequest.pull_request_id, String).ilike(ilike_expression), |
|
314 | 314 | PullRequest.title.ilike(ilike_expression), |
@@ -32,7 +32,7 b' from rhodecode.lib.auth import (' | |||
|
32 | 32 | HasRepoPermissionAnyDecorator) |
|
33 | 33 | from rhodecode.lib.codeblocks import filenode_as_lines_tokens |
|
34 | 34 | from rhodecode.lib.index import searcher_from_config |
|
35 |
from rhodecode.lib.utils2 import |
|
|
35 | from rhodecode.lib.utils2 import str2bool, safe_int | |
|
36 | 36 | from rhodecode.lib.ext_json import json |
|
37 | 37 | from rhodecode.lib.vcs.exceptions import CommitDoesNotExistError, EmptyRepositoryError |
|
38 | 38 | from rhodecode.lib.vcs.nodes import FileNode |
@@ -118,7 +118,7 b' class JournalView(BaseAppView):' | |||
|
118 | 118 | return journal |
|
119 | 119 | |
|
120 | 120 | def feed_uid(self, entry_id): |
|
121 | return '{}:{}'.format('journal', md5_safe(entry_id)) | |
|
121 | return '{}:{}'.format('journal', md5_safe(str(entry_id))) | |
|
122 | 122 | |
|
123 | 123 | def _atom_feed(self, repos, search_term, public=True): |
|
124 | 124 | _ = self.request.translate |
@@ -37,6 +37,7 b' from rhodecode.lib.auth import (' | |||
|
37 | 37 | HasRepoPermissionAny, HasRepoGroupPermissionAny, AuthUser) |
|
38 | 38 | from rhodecode.lib.channelstream import ( |
|
39 | 39 | channelstream_request, ChannelstreamException) |
|
40 | from rhodecode.lib.hash_utils import md5_safe | |
|
40 | 41 | from rhodecode.lib.utils2 import safe_int, md5, str2bool |
|
41 | 42 | from rhodecode.model.auth_token import AuthTokenModel |
|
42 | 43 | from rhodecode.model.comment import CommentsModel |
@@ -114,7 +115,7 b' class MyAccountView(BaseAppView, DataGri' | |||
|
114 | 115 | form = forms.RcForm( |
|
115 | 116 | schema, buttons=(forms.buttons.save, forms.buttons.reset)) |
|
116 | 117 | |
|
117 | controls = self.request.POST.items() | |
|
118 | controls = list(self.request.POST.items()) | |
|
118 | 119 | try: |
|
119 | 120 | valid_data = form.validate(controls) |
|
120 | 121 | skip_attrs = ['admin', 'active', 'extern_type', 'extern_name', |
@@ -179,7 +180,7 b' class MyAccountView(BaseAppView, DataGri' | |||
|
179 | 180 | if c.extern_type != 'rhodecode': |
|
180 | 181 | raise HTTPFound(self.request.route_path('my_account_password')) |
|
181 | 182 | |
|
182 | controls = self.request.POST.items() | |
|
183 | controls = list(self.request.POST.items()) | |
|
183 | 184 | try: |
|
184 | 185 | valid_data = form.validate(controls) |
|
185 | 186 | UserModel().update_user(c.user.user_id, **valid_data) |
@@ -196,7 +197,7 b' class MyAccountView(BaseAppView, DataGri' | |||
|
196 | 197 | else: |
|
197 | 198 | instance = c.auth_user.get_instance() |
|
198 | 199 | self.session.setdefault('rhodecode_user', {}).update( |
|
199 | {'password': md5(instance.password)}) | |
|
200 | {'password': md5_safe(instance.password)}) | |
|
200 | 201 | self.session.save() |
|
201 | 202 | h.flash(_("Successfully updated password"), category='success') |
|
202 | 203 | |
@@ -326,7 +327,7 b' class MyAccountView(BaseAppView, DataGri' | |||
|
326 | 327 | schema, action=h.route_path('my_account_emails_add'), |
|
327 | 328 | buttons=(forms.buttons.save, forms.buttons.reset)) |
|
328 | 329 | |
|
329 | controls = self.request.POST.items() | |
|
330 | controls = list(self.request.POST.items()) | |
|
330 | 331 | try: |
|
331 | 332 | valid_data = form.validate(controls) |
|
332 | 333 | UserModel().add_extra_email(c.user.user_id, valid_data['email']) |
@@ -52,7 +52,7 b' class RepoCachesView(RepoAppView):' | |||
|
52 | 52 | c.cached_diff_size = system_info.get_storage_size(cached_diffs_dir) |
|
53 | 53 | c.shadow_repos = c.rhodecode_db_repo.shadow_repos() |
|
54 | 54 | |
|
55 |
cache_namespace_uid = ' |
|
|
55 | cache_namespace_uid = 'repo.{}'.format(self.db_repo.repo_id) | |
|
56 | 56 | c.region = rc_cache.get_or_create_region('cache_repo', cache_namespace_uid) |
|
57 | 57 | c.backend = c.region.backend |
|
58 | 58 | c.repo_keys = sorted(c.region.backend.list_keys(prefix=cache_namespace_uid)) |
@@ -31,10 +31,10 b' from rhodecode.lib import ext_json' | |||
|
31 | 31 | from rhodecode.lib.auth import ( |
|
32 | 32 | LoginRequired, HasRepoPermissionAnyDecorator) |
|
33 | 33 | |
|
34 | from rhodecode.lib.ext_json import json | |
|
35 | 34 | from rhodecode.lib.graphmod import _colored, _dagwalker |
|
36 | 35 | from rhodecode.lib.helpers import RepoPage |
|
37 |
from rhodecode.lib.utils2 import |
|
|
36 | from rhodecode.lib.utils2 import str2bool | |
|
37 | from rhodecode.lib.str_utils import safe_int, safe_str | |
|
38 | 38 | from rhodecode.lib.vcs.exceptions import ( |
|
39 | 39 | RepositoryError, CommitDoesNotExistError, |
|
40 | 40 | CommitError, NodeDoesNotExistError, EmptyRepositoryError) |
@@ -83,7 +83,7 b' class RepoChangelogView(RepoAppView):' | |||
|
83 | 83 | :param commits: list of commits |
|
84 | 84 | """ |
|
85 | 85 | if not commits: |
|
86 |
return json. |
|
|
86 | return ext_json.str_json([]), ext_json.str_json([]) | |
|
87 | 87 | |
|
88 | 88 | def serialize(commit, parents=True): |
|
89 | 89 | data = dict( |
@@ -100,6 +100,7 b' class RepoChangelogView(RepoAppView):' | |||
|
100 | 100 | next_data = next_data or [] |
|
101 | 101 | |
|
102 | 102 | current = [serialize(x) for x in commits] |
|
103 | ||
|
103 | 104 | commits = prev_data + current + next_data |
|
104 | 105 | |
|
105 | 106 | dag = _dagwalker(repo, commits) |
@@ -110,7 +111,7 b' class RepoChangelogView(RepoAppView):' | |||
|
110 | 111 | |
|
111 | 112 | def _check_if_valid_branch(self, branch_name, repo_name, f_path): |
|
112 | 113 | if branch_name not in self.rhodecode_vcs_repo.branches_all: |
|
113 |
h.flash(u'Branch {} is not found.'.format(h.escape(safe_ |
|
|
114 | h.flash(u'Branch {} is not found.'.format(h.escape(safe_str(branch_name))), | |
|
114 | 115 | category='warning') |
|
115 | 116 | redirect_url = h.route_path( |
|
116 | 117 | 'repo_commits_file', repo_name=repo_name, |
@@ -334,8 +335,8 b' class RepoChangelogView(RepoAppView):' | |||
|
334 | 335 | next_data = None |
|
335 | 336 | |
|
336 | 337 | try: |
|
337 | prev_graph = json.loads(self.request.POST.get('graph') or '{}') | |
|
338 | except json.JSONDecodeError: | |
|
338 | prev_graph = ext_json.json.loads(self.request.POST.get('graph') or '{}') | |
|
339 | except ext_json.json.JSONDecodeError: | |
|
339 | 340 | prev_graph = {} |
|
340 | 341 | |
|
341 | 342 | if self.request.GET.get('chunk') == 'prev': |
@@ -39,7 +39,7 b' from rhodecode.lib.diffs import (' | |||
|
39 | 39 | get_diff_whitespace_flag) |
|
40 | 40 | from rhodecode.lib.exceptions import StatusChangeOnClosedPullRequestError, CommentVersionMismatch |
|
41 | 41 | import rhodecode.lib.helpers as h |
|
42 |
from rhodecode.lib.utils2 import |
|
|
42 | from rhodecode.lib.utils2 import str2bool, StrictAttributeDict, safe_str | |
|
43 | 43 | from rhodecode.lib.vcs.backends.base import EmptyCommit |
|
44 | 44 | from rhodecode.lib.vcs.exceptions import ( |
|
45 | 45 | RepositoryError, CommitDoesNotExistError) |
@@ -308,7 +308,8 b' class RepoCommitsView(RepoAppView):' | |||
|
308 | 308 | 'attachment; filename=%s.diff' % commit_id_range[:12]) |
|
309 | 309 | return response |
|
310 | 310 | elif method == 'patch': |
|
311 | c.diff = safe_unicode(diff) | |
|
311 | ||
|
312 | c.diff = safe_str(diff) | |
|
312 | 313 | patch = render( |
|
313 | 314 | 'rhodecode:templates/changeset/patch_changeset.mako', |
|
314 | 315 | self._get_template_context(c), self.request) |
@@ -381,7 +382,7 b' class RepoCommitsView(RepoAppView):' | |||
|
381 | 382 | resolves_comment_id = entry['resolves_comment_id'] |
|
382 | 383 | f_path = entry['f_path'] |
|
383 | 384 | line_no = entry['line'] |
|
384 |
target_elem_id = 'file-{}'.format(h.safeid(h.safe_ |
|
|
385 | target_elem_id = 'file-{}'.format(h.safeid(h.safe_str(f_path))) | |
|
385 | 386 | |
|
386 | 387 | if status: |
|
387 | 388 | text = text or (_('Status change %(transition_icon)s %(status)s') |
@@ -626,7 +627,7 b' class RepoCommitsView(RepoAppView):' | |||
|
626 | 627 | file_uid=store_uid, filename=metadata["filename"], |
|
627 | 628 | file_hash=metadata["sha256"], file_size=metadata["size"], |
|
628 | 629 | file_display_name=file_display_name, |
|
629 |
file_description=u'comment attachment `{}`'.format(safe_ |
|
|
630 | file_description=u'comment attachment `{}`'.format(safe_str(filename)), | |
|
630 | 631 | hidden=True, check_acl=True, user_id=self._rhodecode_user.user_id, |
|
631 | 632 | scope_repo_id=self.db_repo.repo_id |
|
632 | 633 | ) |
@@ -32,7 +32,7 b' from rhodecode.lib import helpers as h' | |||
|
32 | 32 | from rhodecode.lib import diffs, codeblocks |
|
33 | 33 | from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
|
34 | 34 | from rhodecode.lib.utils import safe_str |
|
35 |
from rhodecode.lib.utils2 import |
|
|
35 | from rhodecode.lib.utils2 import str2bool | |
|
36 | 36 | from rhodecode.lib.view_utils import parse_path_ref, get_commit_from_ref_name |
|
37 | 37 | from rhodecode.lib.vcs.exceptions import ( |
|
38 | 38 | EmptyRepositoryError, RepositoryError, RepositoryRequirementError, |
@@ -259,9 +259,10 b' class RepoCompareView(RepoAppView):' | |||
|
259 | 259 | log.debug('calculating diff between ' |
|
260 | 260 | 'source_ref:%s and target_ref:%s for repo `%s`', |
|
261 | 261 | source_commit, target_commit, |
|
262 |
safe_ |
|
|
262 | safe_str(source_repo.scm_instance().path)) | |
|
263 | 263 | |
|
264 | 264 | if source_commit.repository != target_commit.repository: |
|
265 | ||
|
265 | 266 | msg = _( |
|
266 | 267 | "Repositories unrelated. " |
|
267 | 268 | "Cannot compare commit %(commit1)s from repository %(repo1)s " |
@@ -34,13 +34,13 b' from rhodecode.lib.auth import (' | |||
|
34 | 34 | LoginRequired, HasRepoPermissionAnyDecorator, NotAnonymous, |
|
35 | 35 | HasRepoPermissionAny, HasPermissionAnyDecorator, CSRFRequired) |
|
36 | 36 | import rhodecode.lib.helpers as h |
|
37 | from rhodecode.lib.str_utils import safe_str | |
|
37 | 38 | from rhodecode.lib.celerylib.utils import get_task_id |
|
38 | 39 | from rhodecode.model.db import coalesce, or_, Repository, RepoGroup |
|
39 | 40 | from rhodecode.model.permission import PermissionModel |
|
40 | 41 | from rhodecode.model.repo import RepoModel |
|
41 | 42 | from rhodecode.model.forms import RepoForkForm |
|
42 | 43 | from rhodecode.model.scm import ScmModel, RepoGroupList |
|
43 | from rhodecode.lib.utils2 import safe_int, safe_unicode | |
|
44 | 44 | |
|
45 | 45 | log = logging.getLogger(__name__) |
|
46 | 46 | |
@@ -55,7 +55,7 b' class RepoForksView(RepoAppView, DataGri' | |||
|
55 | 55 | RepoGroup.query().all(), |
|
56 | 56 | perm_set=['group.write', 'group.admin']) |
|
57 | 57 | c.repo_groups = RepoGroup.groups_choices(groups=acl_groups) |
|
58 |
c.repo_groups_choices = map(lambda k: safe_ |
|
|
58 | c.repo_groups_choices = list(map(lambda k: safe_str(k[0]), c.repo_groups)) | |
|
59 | 59 | |
|
60 | 60 | c.personal_repo_group = c.rhodecode_user.personal_repo_group |
|
61 | 61 | |
@@ -102,7 +102,7 b' class RepoForksView(RepoAppView, DataGri' | |||
|
102 | 102 | .filter(Repository.repo_id.in_(allowed_ids))\ |
|
103 | 103 | |
|
104 | 104 | if search_q: |
|
105 |
like_expression = u'%{}%'.format(safe_ |
|
|
105 | like_expression = u'%{}%'.format(safe_str(search_q)) | |
|
106 | 106 | base_q = base_q.filter(or_( |
|
107 | 107 | Repository.repo_name.ilike(like_expression), |
|
108 | 108 | Repository.description.ilike(like_expression), |
@@ -39,7 +39,7 b' from rhodecode.lib import ext_json' | |||
|
39 | 39 | from rhodecode.lib.auth import ( |
|
40 | 40 | LoginRequired, HasRepoPermissionAny, HasRepoPermissionAnyDecorator, |
|
41 | 41 | NotAnonymous, CSRFRequired) |
|
42 |
from rhodecode.lib.utils2 import str2bool, safe_str, |
|
|
42 | from rhodecode.lib.utils2 import str2bool, safe_str, safe_int, aslist, retry | |
|
43 | 43 | from rhodecode.lib.vcs.backends.base import ( |
|
44 | 44 | EmptyCommit, UpdateFailureReason, unicode_to_reference) |
|
45 | 45 | from rhodecode.lib.vcs.exceptions import ( |
@@ -953,7 +953,7 b' class RepoPullRequestsView(RepoAppView, ' | |||
|
953 | 953 | .filter(~Repository.repo_id.in_([x.repo_id for x in parent_target_repos])) |
|
954 | 954 | |
|
955 | 955 | if filter_query: |
|
956 |
ilike_expression = u'%{}%'.format(safe_ |
|
|
956 | ilike_expression = u'%{}%'.format(safe_str(filter_query)) | |
|
957 | 957 | query = query.filter(Repository.repo_name.ilike(ilike_expression)) |
|
958 | 958 | |
|
959 | 959 | limit = max(20 - len(parent_target_repos), 5) # not less then 5 |
@@ -1120,7 +1120,7 b' class RepoPullRequestsView(RepoAppView, ' | |||
|
1120 | 1120 | _form = form.to_python(controls) |
|
1121 | 1121 | except formencode.Invalid as errors: |
|
1122 | 1122 | if errors.error_dict.get('revisions'): |
|
1123 |
msg = 'Revisions: |
|
|
1123 | msg = 'Revisions: {}'.format(errors.error_dict['revisions']) | |
|
1124 | 1124 | elif errors.error_dict.get('pullrequest_title'): |
|
1125 | 1125 | msg = errors.error_dict.get('pullrequest_title') |
|
1126 | 1126 | else: |
@@ -1567,7 +1567,7 b' class RepoPullRequestsView(RepoAppView, ' | |||
|
1567 | 1567 | close_pull_request = entry['close_pull_request'] |
|
1568 | 1568 | f_path = entry['f_path'] |
|
1569 | 1569 | line_no = entry['line'] |
|
1570 |
target_elem_id = 'file-{}'.format(h.safeid(h.safe_ |
|
|
1570 | target_elem_id = 'file-{}'.format(h.safeid(h.safe_str(f_path))) | |
|
1571 | 1571 | |
|
1572 | 1572 | # the logic here should work like following, if we submit close |
|
1573 | 1573 | # pr comment, use `close_pull_request_with_comment` function |
@@ -1867,7 +1867,7 b' class RepoPullRequestsView(RepoAppView, ' | |||
|
1867 | 1867 | 'comment_id': comment.comment_id, |
|
1868 | 1868 | 'comment_version': comment_history.version, |
|
1869 | 1869 | 'comment_author_username': comment_history.author.username, |
|
1870 | 'comment_author_gravatar': h.gravatar_url(comment_history.author.email, 16), | |
|
1870 | 'comment_author_gravatar': h.gravatar_url(comment_history.author.email, 16, request=self.request), | |
|
1871 | 1871 | 'comment_created_on': h.age_component(comment_history.created_on, |
|
1872 | 1872 | time_is_local=True), |
|
1873 | 1873 | } |
@@ -49,7 +49,7 b' class RepoSettingsView(RepoAppView):' | |||
|
49 | 49 | RepoGroup.query().all(), |
|
50 | 50 | perm_set=['group.write', 'group.admin']) |
|
51 | 51 | c.repo_groups = RepoGroup.groups_choices(groups=acl_groups) |
|
52 | c.repo_groups_choices = map(lambda k: k[0], c.repo_groups) | |
|
52 | c.repo_groups_choices = list(map(lambda k: k[0], c.repo_groups)) | |
|
53 | 53 | |
|
54 | 54 | # in case someone no longer have a group.write access to a repository |
|
55 | 55 | # pre fill the list with this entry, we don't care if this is the same |
@@ -114,7 +114,7 b' class RepoSettingsView(RepoAppView):' | |||
|
114 | 114 | schema = self._get_schema(c, old_values=old_values) |
|
115 | 115 | |
|
116 | 116 | c.form = RcForm(schema) |
|
117 | pstruct = self.request.POST.items() | |
|
117 | pstruct = list(self.request.POST.items()) | |
|
118 | 118 | pstruct.append(('repo_type', self.db_repo.repo_type)) |
|
119 | 119 | try: |
|
120 | 120 | schema_data = c.form.validate(pstruct) |
@@ -161,7 +161,7 b' class RepoSummaryView(RepoAppView):' | |||
|
161 | 161 | 'with caching: %s[TTL: %ss]' % ( |
|
162 | 162 | repo_id, landing_commit, cache_on, cache_seconds or 0)) |
|
163 | 163 | |
|
164 |
cache_namespace_uid = ' |
|
|
164 | cache_namespace_uid = 'repo.{}'.format(repo_id) | |
|
165 | 165 | region = rc_cache.get_or_create_region('cache_repo', cache_namespace_uid) |
|
166 | 166 | |
|
167 | 167 | @region.conditional_cache_on_arguments(namespace=cache_namespace_uid, |
@@ -19,7 +19,9 b'' | |||
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import logging |
|
22 |
import urllib.request |
|
|
22 | import urllib.request | |
|
23 | import urllib.parse | |
|
24 | import urllib.error | |
|
23 | 25 | |
|
24 | 26 | from webhelpers2.html.tools import update_params |
|
25 | 27 |
@@ -20,10 +20,10 b'' | |||
|
20 | 20 | |
|
21 | 21 | import os |
|
22 | 22 | import sys |
|
23 | import json | |
|
24 | 23 | import logging |
|
25 | 24 | |
|
26 | 25 | from rhodecode.lib.hooks_daemon import prepare_callback_daemon |
|
26 | from rhodecode.lib.ext_json import sjson as json | |
|
27 | 27 | from rhodecode.lib.vcs.conf import settings as vcs_settings |
|
28 | 28 | from rhodecode.model.scm import ScmModel |
|
29 | 29 |
@@ -24,6 +24,7 b' import datetime' | |||
|
24 | 24 | from rhodecode.lib.jsonalchemy import JsonRaw |
|
25 | 25 | from rhodecode.model import meta |
|
26 | 26 | from rhodecode.model.db import User, UserLog, Repository |
|
27 | from rhodecode.lib.str_utils import safe_str | |
|
27 | 28 | |
|
28 | 29 | |
|
29 | 30 | log = logging.getLogger(__name__) |
@@ -215,7 +216,6 b' def store(action, user, action_data=None' | |||
|
215 | 216 | ip_addr=self.request.remote_addr)) |
|
216 | 217 | |
|
217 | 218 | """ |
|
218 | from rhodecode.lib.utils2 import safe_unicode | |
|
219 | 219 | from rhodecode.lib.auth import AuthUser |
|
220 | 220 | |
|
221 | 221 | action_spec = ACTIONS.get(action, None) |
@@ -257,8 +257,8 b' def store(action, user, action_data=None' | |||
|
257 | 257 | repository_id = getattr( |
|
258 | 258 | Repository.get_by_repo_name(repository_name), 'repo_id', None) |
|
259 | 259 | |
|
260 |
action_name = safe_ |
|
|
261 |
ip_address = safe_ |
|
|
260 | action_name = safe_str(action) | |
|
261 | ip_address = safe_str(ip_addr) | |
|
262 | 262 | |
|
263 | 263 | with sa_session.no_autoflush: |
|
264 | 264 |
@@ -17,8 +17,6 b'' | |||
|
17 | 17 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | 18 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | 19 | |
|
20 | import os | |
|
21 | import json | |
|
22 | 20 | import logging |
|
23 | 21 | import datetime |
|
24 | 22 | import time |
@@ -30,6 +28,8 b' from celery.result import AsyncResult' | |||
|
30 | 28 | import celery.loaders.base |
|
31 | 29 | import celery.schedules |
|
32 | 30 | |
|
31 | from rhodecode.lib.ext_json import sjson as json | |
|
32 | ||
|
33 | 33 | log = logging.getLogger(__name__) |
|
34 | 34 | |
|
35 | 35 |
@@ -64,7 +64,7 b' def date_to_timestamp_plus_offset(value)' | |||
|
64 | 64 | assert not is_aware(value), ( |
|
65 | 65 | "This code is not prepared to handle aware datetime instances") |
|
66 | 66 | value = date_astimestamp(value) |
|
67 |
return |
|
|
67 | return value, time.timezone | |
|
68 | 68 | |
|
69 | 69 | |
|
70 | 70 | def is_aware(value): |
@@ -6,7 +6,7 b' import six' | |||
|
6 | 6 | |
|
7 | 7 | from xml.sax.saxutils import XMLGenerator, quoteattr |
|
8 | 8 | from urllib.parse import quote |
|
9 |
from rhodecode.lib.utils import safe_str |
|
|
9 | from rhodecode.lib.str_utils import safe_str | |
|
10 | 10 | |
|
11 | 11 | |
|
12 | 12 | class SimplerXMLGenerator(XMLGenerator): |
@@ -54,4 +54,4 b' def iri_to_uri(iri):' | |||
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | def force_text(text, strings_only=False): |
|
57 |
return safe_ |
|
|
57 | return safe_str(text) |
@@ -20,6 +20,6 b'' | |||
|
20 | 20 | |
|
21 | 21 | # base64 filter e.g ${ example | base64,n } |
|
22 | 22 | def base64(text): |
|
23 | import base64 | |
|
24 | from rhodecode.lib.helpers import safe_str, safe_bytes | |
|
25 | return safe_str(base64.encodebytes(safe_bytes(text))) | |
|
23 | from rhodecode.lib.str_utils import base64_to_str | |
|
24 | return base64_to_str(text) | |
|
25 |
@@ -34,7 +34,7 b' from whoosh.qparser import QueryParser, ' | |||
|
34 | 34 | |
|
35 | 35 | import rhodecode.lib.helpers as h |
|
36 | 36 | from rhodecode.lib.index import BaseSearcher |
|
37 |
from rhodecode.lib.utils |
|
|
37 | from rhodecode.lib.str_utils import safe_str | |
|
38 | 38 | |
|
39 | 39 | log = logging.getLogger(__name__) |
|
40 | 40 | |
@@ -144,7 +144,7 b' class WhooshSearcher(BaseSearcher):' | |||
|
144 | 144 | allowed_repos_filter = self._get_repo_filter( |
|
145 | 145 | search_user, repo_name) |
|
146 | 146 | try: |
|
147 |
query = qp.parse(safe_ |
|
|
147 | query = qp.parse(safe_str(query)) | |
|
148 | 148 | log.debug('query: %s (%s)', query, repr(query)) |
|
149 | 149 | |
|
150 | 150 | reverse, sorted_by = False, None |
@@ -19,7 +19,9 b'' | |||
|
19 | 19 | |
|
20 | 20 | import base64 |
|
21 | 21 | import logging |
|
22 |
import urllib.request |
|
|
22 | import urllib.request | |
|
23 | import urllib.parse | |
|
24 | import urllib.error | |
|
23 | 25 | import urllib.parse |
|
24 | 26 | |
|
25 | 27 | import requests |
@@ -29,7 +31,8 b' from rhodecode.lib import rc_cache' | |||
|
29 | 31 | from rhodecode.lib.middleware import simplevcs |
|
30 | 32 | from rhodecode.lib.middleware.utils import get_path_info |
|
31 | 33 | from rhodecode.lib.utils import is_valid_repo |
|
32 |
from rhodecode.lib.utils |
|
|
34 | from rhodecode.lib.str_utils import safe_str, safe_int | |
|
35 | from rhodecode.lib.type_utils import str2bool | |
|
33 | 36 | from rhodecode.lib.ext_json import json |
|
34 | 37 | from rhodecode.lib.hooks_daemon import store_txn_id_data |
|
35 | 38 | |
@@ -99,7 +102,6 b' class SimpleSvnApp(object):' | |||
|
99 | 102 | raise |
|
100 | 103 | |
|
101 | 104 | if response.status_code not in [200, 401]: |
|
102 | from rhodecode.lib.utils2 import safe_str | |
|
103 | 105 | text = '\n{}'.format(safe_str(response.text)) if response.text else '' |
|
104 | 106 | if response.status_code >= 500: |
|
105 | 107 | log.error('Got SVN response:%s with text:`%s`', response, text) |
@@ -50,7 +50,7 b' from rhodecode.lib.middleware import app' | |||
|
50 | 50 | from rhodecode.lib.middleware.utils import scm_app_http |
|
51 | 51 | from rhodecode.lib.str_utils import safe_bytes |
|
52 | 52 | from rhodecode.lib.utils import is_valid_repo, SLUG_RE |
|
53 |
from rhodecode.lib.utils2 import safe_str, fix_PATH, str2bool |
|
|
53 | from rhodecode.lib.utils2 import safe_str, fix_PATH, str2bool | |
|
54 | 54 | from rhodecode.lib.vcs.conf import settings as vcs_settings |
|
55 | 55 | from rhodecode.lib.vcs.backends import base |
|
56 | 56 | |
@@ -194,7 +194,7 b' class SimpleVCS(object):' | |||
|
194 | 194 | match_dict = match.groupdict() |
|
195 | 195 | |
|
196 | 196 | # Build acl repo name from regex match. |
|
197 |
acl_repo_name = safe_ |
|
|
197 | acl_repo_name = safe_str('{groups}{target}'.format( | |
|
198 | 198 | groups=match_dict['groups'] or '', |
|
199 | 199 | target=match_dict['target'])) |
|
200 | 200 | |
@@ -471,8 +471,9 b' class SimpleVCS(object):' | |||
|
471 | 471 | 'authentication') |
|
472 | 472 | |
|
473 | 473 | if not anonymous_perm: |
|
474 |
log.debug('Not enough credentials to access |
|
|
475 | 'repository as anonymous user') | |
|
474 | log.debug('Not enough credentials to access repo: `%s` ' | |
|
475 | 'repository as anonymous user', self.acl_repo_name) | |
|
476 | ||
|
476 | 477 | |
|
477 | 478 | username = None |
|
478 | 479 | # ============================================================== |
@@ -481,13 +482,16 b' class SimpleVCS(object):' | |||
|
481 | 482 | # ============================================================== |
|
482 | 483 | |
|
483 | 484 | # try to auth based on environ, container auth methods |
|
484 | log.debug('Running PRE-AUTH for container based authentication') | |
|
485 | log.debug('Running PRE-AUTH for container|headers based authentication') | |
|
486 | ||
|
487 | # headers auth, by just reading special headers and bypass the auth with user/passwd | |
|
485 | 488 | pre_auth = authenticate( |
|
486 | 489 | '', '', environ, VCS_TYPE, registry=self.registry, |
|
487 | 490 | acl_repo_name=self.acl_repo_name) |
|
491 | ||
|
488 | 492 | if pre_auth and pre_auth.get('username'): |
|
489 | 493 | username = pre_auth['username'] |
|
490 | log.debug('PRE-AUTH got %s as username', username) | |
|
494 | log.debug('PRE-AUTH got `%s` as username', username) | |
|
491 | 495 | if pre_auth: |
|
492 | 496 | log.debug('PRE-AUTH successful from %s', |
|
493 | 497 | pre_auth.get('auth_data', {}).get('_plugin')) |
@@ -498,6 +502,8 b' class SimpleVCS(object):' | |||
|
498 | 502 | |
|
499 | 503 | plugin_cache_active, cache_ttl = False, 0 |
|
500 | 504 | plugin = None |
|
505 | ||
|
506 | # regular auth chain | |
|
501 | 507 | if not username: |
|
502 | 508 | self.authenticate.realm = self.authenticate.get_rc_realm() |
|
503 | 509 | |
@@ -546,7 +552,7 b' class SimpleVCS(object):' | |||
|
546 | 552 | plugin, plugin_cache_active, cache_ttl) |
|
547 | 553 | if not perm: |
|
548 | 554 | return HTTPForbidden()(environ, start_response) |
|
549 | environ['rc_auth_user_id'] = user_id | |
|
555 | environ['rc_auth_user_id'] = str(user_id) | |
|
550 | 556 | |
|
551 | 557 | if action == 'push': |
|
552 | 558 | perms = auth_user.get_branch_permissions(self.acl_repo_name) |
@@ -870,7 +870,6 b' class _Page(list):' | |||
|
870 | 870 | return make_html_tag("a", text=text, href=target_url, **item["attrs"]) |
|
871 | 871 | |
|
872 | 872 | # Below is RhodeCode custom code |
|
873 | ||
|
874 | 873 | # Copyright (C) 2010-2020 RhodeCode GmbH |
|
875 | 874 | # |
|
876 | 875 | # This program is free software: you can redistribute it and/or modify |
@@ -17,11 +17,15 b'' | |||
|
17 | 17 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | 18 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | 19 | |
|
20 | import typing | |
|
21 | import base64 | |
|
20 | 22 | import logging |
|
23 | from unidecode import unidecode | |
|
24 | ||
|
21 | 25 | import rhodecode |
|
22 | import unicodedata | |
|
23 | 26 | from rhodecode.lib.type_utils import aslist |
|
24 | 27 | |
|
28 | ||
|
25 | 29 | log = logging.getLogger(__name__) |
|
26 | 30 | |
|
27 | 31 | |
@@ -42,18 +46,40 b' def safe_int(val, default=None) -> int:' | |||
|
42 | 46 | return val |
|
43 | 47 | |
|
44 | 48 | |
|
45 | def get_default_encodings(): | |
|
49 | def safe_float(val, default=None) -> float: | |
|
50 | """ | |
|
51 | Returns float() of val if val is not convertable to float use default | |
|
52 | instead | |
|
53 | ||
|
54 | :param val: | |
|
55 | :param default: | |
|
56 | """ | |
|
57 | ||
|
58 | try: | |
|
59 | val = float(val) | |
|
60 | except (ValueError, TypeError): | |
|
61 | val = default | |
|
62 | ||
|
63 | return val | |
|
64 | ||
|
65 | ||
|
66 | def base64_to_str(text) -> str: | |
|
67 | return safe_str(base64.encodebytes(safe_bytes(text))).strip() | |
|
68 | ||
|
69 | ||
|
70 | def get_default_encodings() -> typing.List[str]: | |
|
46 | 71 | return aslist(rhodecode.CONFIG.get('default_encoding', 'utf8'), sep=',') |
|
47 | 72 | |
|
48 | 73 | |
|
74 | DEFAULT_ENCODINGS = get_default_encodings() | |
|
75 | ||
|
76 | ||
|
49 | 77 | def safe_str(str_, to_encoding=None) -> str: |
|
50 | 78 | """ |
|
51 | 79 | safe str function. Does few trick to turn unicode_ into string |
|
52 | 80 | |
|
53 | 81 | :param str_: str to encode |
|
54 | 82 | :param to_encoding: encode to this type UTF8 default |
|
55 | :rtype: str | |
|
56 | :returns: str object | |
|
57 | 83 | """ |
|
58 | 84 | if isinstance(str_, str): |
|
59 | 85 | return str_ |
@@ -62,7 +88,7 b' def safe_str(str_, to_encoding=None) -> ' | |||
|
62 | 88 | if not isinstance(str_, bytes): |
|
63 | 89 | return str(str_) |
|
64 | 90 | |
|
65 |
to_encoding = to_encoding or |
|
|
91 | to_encoding = to_encoding or DEFAULT_ENCODINGS | |
|
66 | 92 | if not isinstance(to_encoding, (list, tuple)): |
|
67 | 93 | to_encoding = [to_encoding] |
|
68 | 94 | |
@@ -81,14 +107,12 b' def safe_bytes(str_, from_encoding=None)' | |||
|
81 | 107 | |
|
82 | 108 | :param str_: string to decode |
|
83 | 109 | :param from_encoding: encode from this type UTF8 default |
|
84 | :rtype: unicode | |
|
85 | :returns: unicode object | |
|
86 | 110 | """ |
|
87 | 111 | if isinstance(str_, bytes): |
|
88 | 112 | return str_ |
|
89 | 113 | |
|
90 | 114 | if not isinstance(str_, str): |
|
91 |
raise ValueError('safe_bytes cannot convert other types than str: got: { |
|
|
115 | raise ValueError(f'safe_bytes cannot convert other types than str: got: {type(str_)}') | |
|
92 | 116 | |
|
93 | 117 | from_encoding = from_encoding or get_default_encodings() |
|
94 | 118 | if not isinstance(from_encoding, (list, tuple)): |
@@ -116,11 +140,11 b' def ascii_bytes(str_, allow_bytes=False)' | |||
|
116 | 140 | return str_ |
|
117 | 141 | |
|
118 | 142 | if not isinstance(str_, str): |
|
119 |
raise ValueError('ascii_bytes cannot convert other types than str: got: { |
|
|
143 | raise ValueError(f'ascii_bytes cannot convert other types than str: got: {type(str_)}') | |
|
120 | 144 | return str_.encode('ascii') |
|
121 | 145 | |
|
122 | 146 | |
|
123 | def ascii_str(str_): | |
|
147 | def ascii_str(str_) -> str: | |
|
124 | 148 | """ |
|
125 | 149 | Simple conversion from bytes to str, with assumption that str_ is pure ASCII. |
|
126 | 150 | Fails with UnicodeError on invalid input. |
@@ -131,16 +155,16 b' def ascii_str(str_):' | |||
|
131 | 155 | """ |
|
132 | 156 | |
|
133 | 157 | if not isinstance(str_, bytes): |
|
134 |
raise ValueError('ascii_str cannot convert other types than bytes: got: { |
|
|
158 | raise ValueError(f'ascii_str cannot convert other types than bytes: got: {type(str_)}') | |
|
135 | 159 | return str_.decode('ascii') |
|
136 | 160 | |
|
137 | 161 | |
|
138 | def convert_special_chars(str_): | |
|
162 | def convert_special_chars(str_) -> str: | |
|
139 | 163 | """ |
|
140 | 164 | trie to replace non-ascii letters to their ascii representation eg:: |
|
141 | 165 | |
|
142 | 166 | `żołw` converts into `zolw` |
|
143 | 167 | """ |
|
144 | 168 | value = safe_str(str_) |
|
145 | converted_value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode() | |
|
169 | converted_value = unidecode(value) | |
|
146 | 170 | return converted_value |
@@ -191,7 +191,7 b' def locale_info():' | |||
|
191 | 191 | return f'FAILED_LOCALE_GET:{locale_name}' |
|
192 | 192 | |
|
193 | 193 | value = dict( |
|
194 |
locale_default=locale.get |
|
|
194 | locale_default=locale.getlocale(), | |
|
195 | 195 | locale_lc_all=safe_get_locale(locale.LC_ALL), |
|
196 | 196 | locale_lc_ctype=safe_get_locale(locale.LC_CTYPE), |
|
197 | 197 | lang_env=os.environ.get('LANG'), |
@@ -404,9 +404,9 b' def storage_archives():' | |||
|
404 | 404 | from rhodecode.lib.utils import safe_str |
|
405 | 405 | from rhodecode.lib.helpers import format_byte_size_binary |
|
406 | 406 | |
|
407 | msg = 'Enable this by setting ' \ | |
|
408 | 'archive_cache_dir=/path/to/cache option in the .ini file' | |
|
409 | path = safe_str(rhodecode.CONFIG.get('archive_cache_dir', msg)) | |
|
407 | msg = 'Archive cache storage is controlled by ' \ | |
|
408 | 'archive_cache.store_dir=/path/to/cache option in the .ini file' | |
|
409 | path = safe_str(rhodecode.CONFIG.get('archive_cache.store_dir', msg)) | |
|
410 | 410 | |
|
411 | 411 | value = dict(percent=0, used=0, total=0, items=0, path=path, text='') |
|
412 | 412 | state = STATE_OK_DEFAULT |
@@ -415,7 +415,7 b' def storage_archives():' | |||
|
415 | 415 | used = 0 |
|
416 | 416 | for root, dirs, files in os.walk(path): |
|
417 | 417 | if root == path: |
|
418 |
items_count = len( |
|
|
418 | items_count = len(dirs) | |
|
419 | 419 | |
|
420 | 420 | for f in files: |
|
421 | 421 | try: |
@@ -726,7 +726,8 b' def rhodecode_config():' | |||
|
726 | 726 | def database_info(): |
|
727 | 727 | import rhodecode |
|
728 | 728 | from sqlalchemy.engine import url as engine_url |
|
729 |
from rhodecode.model |
|
|
729 | from rhodecode.model import meta | |
|
730 | from rhodecode.model.meta import Session | |
|
730 | 731 | from rhodecode.model.db import DbMigrateVersion |
|
731 | 732 | |
|
732 | 733 | state = STATE_OK_DEFAULT |
@@ -737,7 +738,7 b' def database_info():' | |||
|
737 | 738 | db_url_obj = engine_url.make_url(rhodecode.CONFIG['sqlalchemy.db1.url']) |
|
738 | 739 | |
|
739 | 740 | try: |
|
740 |
engine = |
|
|
741 | engine = meta.get_engine() | |
|
741 | 742 | db_server_info = engine.dialect._get_server_version_info( |
|
742 | 743 | Session.connection(bind=engine)) |
|
743 | 744 | db_version = '.'.join(map(str, db_server_info)) |
@@ -40,7 +40,7 b' def str2bool(str_):' | |||
|
40 | 40 | return str_ in ('t', 'true', 'y', 'yes', 'on', '1') |
|
41 | 41 | |
|
42 | 42 | |
|
43 | def aslist(obj, sep=None, strip=True): | |
|
43 | def aslist(obj, sep=None, strip=True) -> list: | |
|
44 | 44 | """ |
|
45 | 45 | Returns given string separated by sep as list |
|
46 | 46 | |
@@ -49,6 +49,9 b' def aslist(obj, sep=None, strip=True):' | |||
|
49 | 49 | :param strip: |
|
50 | 50 | """ |
|
51 | 51 | if isinstance(obj, str): |
|
52 | if obj in ['', ""]: | |
|
53 | return [] | |
|
54 | ||
|
52 | 55 | lst = obj.split(sep) |
|
53 | 56 | if strip: |
|
54 | 57 | lst = [v.strip() for v in lst] |
@@ -59,3 +62,32 b' def aslist(obj, sep=None, strip=True):' | |||
|
59 | 62 | return [] |
|
60 | 63 | else: |
|
61 | 64 | return [obj] |
|
65 | ||
|
66 | ||
|
67 | class AttributeDictBase(dict): | |
|
68 | def __getstate__(self): | |
|
69 | odict = self.__dict__ # get attribute dictionary | |
|
70 | return odict | |
|
71 | ||
|
72 | def __setstate__(self, dict): | |
|
73 | self.__dict__ = dict | |
|
74 | ||
|
75 | __setattr__ = dict.__setitem__ | |
|
76 | __delattr__ = dict.__delitem__ | |
|
77 | ||
|
78 | ||
|
79 | class StrictAttributeDict(AttributeDictBase): | |
|
80 | """ | |
|
81 | Strict Version of Attribute dict which raises an Attribute error when | |
|
82 | requested attribute is not set | |
|
83 | """ | |
|
84 | def __getattr__(self, attr): | |
|
85 | try: | |
|
86 | return self[attr] | |
|
87 | except KeyError: | |
|
88 | raise AttributeError(f'{self.__class__} object has no attribute {attr}') | |
|
89 | ||
|
90 | ||
|
91 | class AttributeDict(AttributeDictBase): | |
|
92 | def __getattr__(self, attr): | |
|
93 | return self.get(attr, None) |
@@ -25,7 +25,9 b' from whoosh.fields import (TEXT, Schema,' | |||
|
25 | 25 | from sqlalchemy.sql.expression import or_, and_, not_, func |
|
26 | 26 | |
|
27 | 27 | from rhodecode.model.db import UserLog |
|
28 |
from rhodecode.lib.utils2 import remove_prefix, remove_suffix |
|
|
28 | from rhodecode.lib.utils2 import remove_prefix, remove_suffix | |
|
29 | from rhodecode.lib.str_utils import safe_str | |
|
30 | ||
|
29 | 31 | |
|
30 | 32 | # JOURNAL SCHEMA used only to generate queries in journal. We use whoosh |
|
31 | 33 | # querylang to build sql queries and filter journals |
@@ -54,7 +56,7 b' def user_log_filter(user_log, search_ter' | |||
|
54 | 56 | if search_term: |
|
55 | 57 | qp = QueryParser('repository', schema=AUDIT_LOG_SCHEMA) |
|
56 | 58 | qp.add_plugin(DateParserPlugin()) |
|
57 |
qry = qp.parse(safe_ |
|
|
59 | qry = qp.parse(safe_str(search_term)) | |
|
58 | 60 | log.debug('Filtering using parsed query %r', qry) |
|
59 | 61 | |
|
60 | 62 | def wildcard_handler(col, wc_term): |
@@ -38,7 +38,7 b' class BaseAuthSessions(object):' | |||
|
38 | 38 | |
|
39 | 39 | def __init__(self, config): |
|
40 | 40 | session_conf = {} |
|
41 | for k, v in config.items(): | |
|
41 | for k, v in list(config.items()): | |
|
42 | 42 | if k.startswith('beaker.session'): |
|
43 | 43 | session_conf[k] = v |
|
44 | 44 | self.config = session_conf |
@@ -30,7 +30,9 b' import logging' | |||
|
30 | 30 | import re |
|
31 | 31 | import sys |
|
32 | 32 | import time |
|
33 |
import urllib.request |
|
|
33 | import urllib.request | |
|
34 | import urllib.parse | |
|
35 | import urllib.error | |
|
34 | 36 | import urlobject |
|
35 | 37 | import uuid |
|
36 | 38 | import getpass |
@@ -37,8 +37,7 b' from zope.cachedescriptors.property impo' | |||
|
37 | 37 | |
|
38 | 38 | import rhodecode |
|
39 | 39 | from rhodecode.translation import lazy_ugettext |
|
40 |
from rhodecode.lib.utils2 import safe_str, |
|
|
41 | from rhodecode.lib.vcs import connection | |
|
40 | from rhodecode.lib.utils2 import safe_str, CachedProperty | |
|
42 | 41 | from rhodecode.lib.vcs.utils import author_name, author_email |
|
43 | 42 | from rhodecode.lib.vcs.conf import settings |
|
44 | 43 | from rhodecode.lib.vcs.exceptions import ( |
@@ -72,7 +71,7 b' class Reference(_Reference):' | |||
|
72 | 71 | return self.name |
|
73 | 72 | |
|
74 | 73 | @property |
|
75 |
def to_ |
|
|
74 | def to_str(self): | |
|
76 | 75 | return reference_to_unicode(self) |
|
77 | 76 | |
|
78 | 77 | |
@@ -88,13 +87,13 b' def unicode_to_reference(raw):' | |||
|
88 | 87 | return None |
|
89 | 88 | |
|
90 | 89 | |
|
91 | def reference_to_unicode(ref): | |
|
90 | def reference_to_unicode(ref: Reference): | |
|
92 | 91 | """ |
|
93 | 92 | Convert a reference object to unicode. |
|
94 | 93 | If reference is None it returns None. |
|
95 | 94 | """ |
|
96 | 95 | if ref: |
|
97 |
return |
|
|
96 | return ':'.join(ref) | |
|
98 | 97 | else: |
|
99 | 98 | return None |
|
100 | 99 | |
@@ -187,37 +186,37 b' class MergeResponse(object):' | |||
|
187 | 186 | # uses .format(**metadata) for variables |
|
188 | 187 | MERGE_STATUS_MESSAGES = { |
|
189 | 188 | MergeFailureReason.NONE: lazy_ugettext( |
|
190 |
|
|
|
189 | 'This pull request can be automatically merged.'), | |
|
191 | 190 | MergeFailureReason.UNKNOWN: lazy_ugettext( |
|
192 |
|
|
|
193 |
|
|
|
191 | 'This pull request cannot be merged because of an unhandled exception. ' | |
|
192 | '{exception}'), | |
|
194 | 193 | MergeFailureReason.MERGE_FAILED: lazy_ugettext( |
|
195 |
|
|
|
194 | 'This pull request cannot be merged because of merge conflicts. {unresolved_files}'), | |
|
196 | 195 | MergeFailureReason.PUSH_FAILED: lazy_ugettext( |
|
197 |
|
|
|
198 |
|
|
|
196 | 'This pull request could not be merged because push to ' | |
|
197 | 'target:`{target}@{merge_commit}` failed.'), | |
|
199 | 198 | MergeFailureReason.TARGET_IS_NOT_HEAD: lazy_ugettext( |
|
200 |
|
|
|
201 |
|
|
|
199 | 'This pull request cannot be merged because the target ' | |
|
200 | '`{target_ref.name}` is not a head.'), | |
|
202 | 201 | MergeFailureReason.HG_SOURCE_HAS_MORE_BRANCHES: lazy_ugettext( |
|
203 |
|
|
|
204 |
|
|
|
202 | 'This pull request cannot be merged because the source contains ' | |
|
203 | 'more branches than the target.'), | |
|
205 | 204 | MergeFailureReason.HG_TARGET_HAS_MULTIPLE_HEADS: lazy_ugettext( |
|
206 |
|
|
|
207 |
|
|
|
205 | 'This pull request cannot be merged because the target `{target_ref.name}` ' | |
|
206 | 'has multiple heads: `{heads}`.'), | |
|
208 | 207 | MergeFailureReason.TARGET_IS_LOCKED: lazy_ugettext( |
|
209 |
|
|
|
210 |
|
|
|
208 | 'This pull request cannot be merged because the target repository is ' | |
|
209 | 'locked by {locked_by}.'), | |
|
211 | 210 | |
|
212 | 211 | MergeFailureReason.MISSING_TARGET_REF: lazy_ugettext( |
|
213 |
|
|
|
214 |
|
|
|
212 | 'This pull request cannot be merged because the target ' | |
|
213 | 'reference `{target_ref.name}` is missing.'), | |
|
215 | 214 | MergeFailureReason.MISSING_SOURCE_REF: lazy_ugettext( |
|
216 |
|
|
|
217 |
|
|
|
215 | 'This pull request cannot be merged because the source ' | |
|
216 | 'reference `{source_ref.name}` is missing.'), | |
|
218 | 217 | MergeFailureReason.SUBREPO_MERGE_FAILED: lazy_ugettext( |
|
219 |
|
|
|
220 |
|
|
|
218 | 'This pull request cannot be merged because of conflicts related ' | |
|
219 | 'to sub repositories.'), | |
|
221 | 220 | |
|
222 | 221 | # Deprecations |
|
223 | 222 | MergeFailureReason._DEPRECATED_MISSING_COMMIT: lazy_ugettext( |
@@ -254,7 +253,7 b' class MergeResponse(object):' | |||
|
254 | 253 | """ |
|
255 | 254 | Return a human friendly error message for the given merge status code. |
|
256 | 255 | """ |
|
257 |
msg = safe_ |
|
|
256 | msg = safe_str(self.MERGE_STATUS_MESSAGES[self.failure_reason]) | |
|
258 | 257 | |
|
259 | 258 | try: |
|
260 | 259 | return msg.format(**self.metadata) |
@@ -379,7 +378,7 b' class BaseRepository(object):' | |||
|
379 | 378 | |
|
380 | 379 | @LazyProperty |
|
381 | 380 | def name(self): |
|
382 |
return safe_ |
|
|
381 | return safe_str(os.path.basename(self.path)) | |
|
383 | 382 | |
|
384 | 383 | @LazyProperty |
|
385 | 384 | def description(self): |
@@ -785,11 +784,11 b' class BaseRepository(object):' | |||
|
785 | 784 | |
|
786 | 785 | def _validate_commit_id(self, commit_id): |
|
787 | 786 | if not isinstance(commit_id, str): |
|
788 |
raise TypeError("commit_id must be a string value got { |
|
|
787 | raise TypeError(f"commit_id must be a string value got {type(commit_id)} instead") | |
|
789 | 788 | |
|
790 | 789 | def _validate_commit_idx(self, commit_idx): |
|
791 | 790 | if not isinstance(commit_idx, int): |
|
792 | raise TypeError("commit_idx must be a numeric value") | |
|
791 | raise TypeError(f"commit_idx must be a numeric value, got {type(commit_idx)}") | |
|
793 | 792 | |
|
794 | 793 | def _validate_branch_name(self, branch_name): |
|
795 | 794 | if branch_name and branch_name not in self.branches_all: |
@@ -931,21 +930,17 b' class BaseCommit(object):' | |||
|
931 | 930 | value as ``None``. |
|
932 | 931 | """ |
|
933 | 932 | |
|
934 |
_ARCHIVE_PREFIX_TEMPLATE = |
|
|
933 | _ARCHIVE_PREFIX_TEMPLATE = '{repo_name}-{short_id}' | |
|
935 | 934 | """ |
|
936 | 935 | This template is used to generate a default prefix for repository archives |
|
937 | 936 | if no prefix has been specified. |
|
938 | 937 | """ |
|
939 | 938 | |
|
940 | def __str__(self): | |
|
941 | return '<%s at %s:%s>' % ( | |
|
942 | self.__class__.__name__, self.idx, self.short_id) | |
|
943 | ||
|
944 | 939 | def __repr__(self): |
|
945 | 940 | return self.__str__() |
|
946 | 941 | |
|
947 |
def __ |
|
|
948 |
return |
|
|
942 | def __str__(self): | |
|
943 | return f'<{self.__class__.__name__} at {self.idx}:{self.short_id}>' | |
|
949 | 944 | |
|
950 | 945 | def __eq__(self, other): |
|
951 | 946 | same_instance = isinstance(other, self.__class__) |
General Comments 0
You need to be logged in to leave comments.
Login now