Show More
@@ -34,7 +34,6 b' import beaker' | |||
|
34 | 34 | |
|
35 | 35 | from tg import request, response |
|
36 | 36 | from tg.i18n import ugettext as _ |
|
37 | from webhelpers.text import collapse, remove_formatting, strip_tags | |
|
38 | 37 | from beaker.cache import _cache_decorate |
|
39 | 38 | |
|
40 | 39 | from kallithea.lib.vcs.utils.hgcompat import ui, config |
@@ -54,42 +53,6 b' log = logging.getLogger(__name__)' | |||
|
54 | 53 | REMOVED_REPO_PAT = re.compile(r'rm__\d{8}_\d{6}_\d{6}_.*') |
|
55 | 54 | |
|
56 | 55 | |
|
57 | def recursive_replace(str_, replace=' '): | |
|
58 | """ | |
|
59 | Recursive replace of given sign to just one instance | |
|
60 | ||
|
61 | :param str_: given string | |
|
62 | :param replace: char to find and replace multiple instances | |
|
63 | ||
|
64 | Examples:: | |
|
65 | >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-') | |
|
66 | 'Mighty-Mighty-Bo-sstones' | |
|
67 | """ | |
|
68 | ||
|
69 | if str_.find(replace * 2) == -1: | |
|
70 | return str_ | |
|
71 | else: | |
|
72 | str_ = str_.replace(replace * 2, replace) | |
|
73 | return recursive_replace(str_, replace) | |
|
74 | ||
|
75 | ||
|
76 | def repo_name_slug(value): | |
|
77 | """ | |
|
78 | Return slug of name of repository | |
|
79 | This function is called on each creation/modification | |
|
80 | of repository to prevent bad names in repo | |
|
81 | """ | |
|
82 | ||
|
83 | slug = remove_formatting(value) | |
|
84 | slug = strip_tags(slug) | |
|
85 | ||
|
86 | for c in """`?=[]\;'"<>,/~!@#$%^&*()+{}|: """: | |
|
87 | slug = slug.replace(c, '-') | |
|
88 | slug = recursive_replace(slug, '-') | |
|
89 | slug = collapse(slug, '-') | |
|
90 | return slug | |
|
91 | ||
|
92 | ||
|
93 | 56 | #============================================================================== |
|
94 | 57 | # PERM DECORATOR HELPERS FOR EXTRACTING NAMES FOR PERM CHECKS |
|
95 | 58 | #============================================================================== |
@@ -15,7 +15,9 b'' | |||
|
15 | 15 | kallithea.lib.utils2 |
|
16 | 16 | ~~~~~~~~~~~~~~~~~~~~ |
|
17 | 17 | |
|
18 | Some simple helper functions | |
|
18 | Some simple helper functions. | |
|
19 | Note: all these functions should be independent of Kallithea classes, i.e. | |
|
20 | models, controllers, etc. to prevent import cycles. | |
|
19 | 21 | |
|
20 | 22 | This file was forked by the Kallithea project in July 2014. |
|
21 | 23 | Original author and date, and relevant copyright and licensing information is below: |
@@ -37,6 +39,7 b' import binascii' | |||
|
37 | 39 | |
|
38 | 40 | import webob |
|
39 | 41 | import urlobject |
|
42 | from webhelpers.text import collapse, remove_formatting, strip_tags | |
|
40 | 43 | |
|
41 | 44 | from tg.i18n import ugettext as _, ungettext |
|
42 | 45 | from kallithea.lib.vcs.utils.lazy import LazyProperty |
@@ -646,3 +649,39 b' class Optional(object):' | |||
|
646 | 649 | |
|
647 | 650 | def urlreadable(s, _cleanstringsub=re.compile('[^-a-zA-Z0-9./]+').sub): |
|
648 | 651 | return _cleanstringsub('_', safe_str(s)).rstrip('_') |
|
652 | ||
|
653 | ||
|
654 | def recursive_replace(str_, replace=' '): | |
|
655 | """ | |
|
656 | Recursive replace of given sign to just one instance | |
|
657 | ||
|
658 | :param str_: given string | |
|
659 | :param replace: char to find and replace multiple instances | |
|
660 | ||
|
661 | Examples:: | |
|
662 | >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-') | |
|
663 | 'Mighty-Mighty-Bo-sstones' | |
|
664 | """ | |
|
665 | ||
|
666 | if str_.find(replace * 2) == -1: | |
|
667 | return str_ | |
|
668 | else: | |
|
669 | str_ = str_.replace(replace * 2, replace) | |
|
670 | return recursive_replace(str_, replace) | |
|
671 | ||
|
672 | ||
|
673 | def repo_name_slug(value): | |
|
674 | """ | |
|
675 | Return slug of name of repository | |
|
676 | This function is called on each creation/modification | |
|
677 | of repository to prevent bad names in repo | |
|
678 | """ | |
|
679 | ||
|
680 | slug = remove_formatting(value) | |
|
681 | slug = strip_tags(slug) | |
|
682 | ||
|
683 | for c in """`?=[]\;'"<>,/~!@#$%^&*()+{}|: """: | |
|
684 | slug = slug.replace(c, '-') | |
|
685 | slug = recursive_replace(slug, '-') | |
|
686 | slug = collapse(slug, '-') | |
|
687 | return slug |
@@ -33,7 +33,7 b' import traceback' | |||
|
33 | 33 | from datetime import datetime |
|
34 | 34 | from sqlalchemy.orm import subqueryload |
|
35 | 35 | |
|
36 | import kallithea.lib.utils | |
|
36 | import kallithea.lib.utils2 | |
|
37 | 37 | from kallithea.lib.utils import make_ui, is_valid_repo_uri |
|
38 | 38 | from kallithea.lib.vcs.backends import get_backend |
|
39 | 39 | from kallithea.lib.utils2 import LazyProperty, safe_str, safe_unicode, \ |
@@ -316,7 +316,7 b' class RepoModel(object):' | |||
|
316 | 316 | |
|
317 | 317 | if 'repo_name' in kwargs: |
|
318 | 318 | repo_name = kwargs['repo_name'] |
|
319 | if kallithea.lib.utils.repo_name_slug(repo_name) != repo_name: | |
|
319 | if kallithea.lib.utils2.repo_name_slug(repo_name) != repo_name: | |
|
320 | 320 | raise Exception('invalid repo name %s' % repo_name) |
|
321 | 321 | cur_repo.repo_name = cur_repo.get_new_name(repo_name) |
|
322 | 322 | |
@@ -367,7 +367,7 b' class RepoModel(object):' | |||
|
367 | 367 | # with name and path of group |
|
368 | 368 | repo_name_full = repo_name |
|
369 | 369 | repo_name = repo_name.split(self.URL_SEPARATOR)[-1] |
|
370 | if kallithea.lib.utils.repo_name_slug(repo_name) != repo_name: | |
|
370 | if kallithea.lib.utils2.repo_name_slug(repo_name) != repo_name: | |
|
371 | 371 | raise Exception('invalid repo name %s' % repo_name) |
|
372 | 372 | |
|
373 | 373 | new_repo = Repository() |
@@ -32,7 +32,7 b' import traceback' | |||
|
32 | 32 | import shutil |
|
33 | 33 | import datetime |
|
34 | 34 | |
|
35 | import kallithea.lib.utils | |
|
35 | import kallithea.lib.utils2 | |
|
36 | 36 | from kallithea.lib.utils2 import LazyProperty |
|
37 | 37 | |
|
38 | 38 | from kallithea.model.db import RepoGroup, Session, Ui, UserRepoGroupToPerm, \ |
@@ -136,7 +136,7 b' class RepoGroupModel(object):' | |||
|
136 | 136 | def create(self, group_name, group_description, owner, parent=None, |
|
137 | 137 | just_db=False, copy_permissions=False): |
|
138 | 138 | try: |
|
139 | if kallithea.lib.utils.repo_name_slug(group_name) != group_name: | |
|
139 | if kallithea.lib.utils2.repo_name_slug(group_name) != group_name: | |
|
140 | 140 | raise Exception('invalid repo group name %s' % group_name) |
|
141 | 141 | |
|
142 | 142 | owner = User.guess_instance(owner) |
@@ -295,7 +295,7 b' class RepoGroupModel(object):' | |||
|
295 | 295 | repo_group.parent_group = RepoGroup.get(kwargs['parent_group_id']) |
|
296 | 296 | if 'group_name' in kwargs: |
|
297 | 297 | group_name = kwargs['group_name'] |
|
298 | if kallithea.lib.utils.repo_name_slug(group_name) != group_name: | |
|
298 | if kallithea.lib.utils2.repo_name_slug(group_name) != group_name: | |
|
299 | 299 | raise Exception('invalid repo group name %s' % group_name) |
|
300 | 300 | repo_group.group_name = repo_group.get_new_name(group_name) |
|
301 | 301 | new_path = repo_group.full_path |
@@ -31,8 +31,8 b' from formencode.validators import (' | |||
|
31 | 31 | ) |
|
32 | 32 | from kallithea.lib.compat import OrderedSet |
|
33 | 33 | from kallithea.lib import ipaddr |
|
34 |
from kallithea.lib.utils import |
|
|
35 | from kallithea.lib.utils2 import str2bool, aslist | |
|
34 | from kallithea.lib.utils import is_valid_repo_uri | |
|
35 | from kallithea.lib.utils2 import str2bool, aslist, repo_name_slug | |
|
36 | 36 | from kallithea.model.db import RepoGroup, Repository, UserGroup, User |
|
37 | 37 | from kallithea.lib.exceptions import LdapImportError |
|
38 | 38 | from kallithea.config.routing import ADMIN_PREFIX |
General Comments 0
You need to be logged in to leave comments.
Login now