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