Show More
@@ -25,19 +25,21 b'' | |||
|
25 | 25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
26 | 26 | # MA 02110-1301, USA. |
|
27 | 27 | |
|
28 |
def str2bool( |
|
|
29 | if isinstance(v, (str, unicode)): | |
|
30 | obj = v.strip().lower() | |
|
31 | if obj in ['true', 'yes', 'on', 'y', 't', '1']: | |
|
32 |
|
|
|
33 | elif obj in ['false', 'no', 'off', 'n', 'f', '0']: | |
|
34 | return False | |
|
35 | else: | |
|
36 | if not safe: | |
|
37 | raise ValueError("String is not true/false: %r" % obj) | |
|
38 | return bool(obj) | |
|
28 | def str2bool(s): | |
|
29 | if s is None: | |
|
30 | return False | |
|
31 | if s in (True, False): | |
|
32 | return s | |
|
33 | s = str(s).strip().lower() | |
|
34 | return s in ('t', 'true', 'y', 'yes', 'on', '1') | |
|
39 | 35 | |
|
40 | 36 | def generate_api_key(username, salt=None): |
|
37 | """ | |
|
38 | Generates uniq API key for given username | |
|
39 | ||
|
40 | :param username: username as string | |
|
41 | :param salt: salt to hash generate KEY | |
|
42 | """ | |
|
41 | 43 | from tempfile import _RandomNameSequence |
|
42 | 44 | import hashlib |
|
43 | 45 | |
@@ -45,3 +47,21 b' def generate_api_key(username, salt=None' | |||
|
45 | 47 | salt = _RandomNameSequence().next() |
|
46 | 48 | |
|
47 | 49 | return hashlib.sha1(username + salt).hexdigest() |
|
50 | ||
|
51 | def safe_unicode(str): | |
|
52 | """ | |
|
53 | safe unicode function. In case of UnicodeDecode error we try to return | |
|
54 | unicode with errors replace, if this fails we return unicode with | |
|
55 | string_escape decoding | |
|
56 | """ | |
|
57 | ||
|
58 | try: | |
|
59 | u_str = unicode(str) | |
|
60 | except UnicodeDecodeError: | |
|
61 | try: | |
|
62 | u_str = unicode(str, 'utf-8', 'replace') | |
|
63 | except UnicodeDecodeError: | |
|
64 | #incase we have a decode error just represent as byte string | |
|
65 | u_str = unicode(str(str).encode('string_escape')) | |
|
66 | ||
|
67 | return u_str |
@@ -8,6 +8,7 b' import hashlib' | |||
|
8 | 8 | import StringIO |
|
9 | 9 | import urllib |
|
10 | 10 | |
|
11 | from datetime import datetime | |
|
11 | 12 | from pygments.formatters import HtmlFormatter |
|
12 | 13 | from pygments import highlight as code_highlight |
|
13 | 14 | from pylons import url, request, config |
@@ -38,7 +39,8 b' from rhodecode.lib.utils import repo_nam' | |||
|
38 | 39 | from rhodecode.lib import str2bool |
|
39 | 40 | |
|
40 | 41 | def _reset(name, value=None, id=NotGiven, type="reset", **attrs): |
|
41 | """Reset button | |
|
42 | """ | |
|
43 | Reset button | |
|
42 | 44 | """ |
|
43 | 45 | _set_input_attrs(attrs, type, name, value) |
|
44 | 46 | _set_id_attr(attrs, id, name) |
@@ -380,8 +382,6 b' def _age(curdate):' | |||
|
380 | 382 | if not curdate: |
|
381 | 383 | return '' |
|
382 | 384 | |
|
383 | from datetime import timedelta, datetime | |
|
384 | ||
|
385 | 385 | agescales = [("year", 3600 * 24 * 365), |
|
386 | 386 | ("month", 3600 * 24 * 30), |
|
387 | 387 | ("day", 3600 * 24), |
@@ -671,22 +671,6 b' class RepoPage(Page):' | |||
|
671 | 671 | list.__init__(self, self.items) |
|
672 | 672 | |
|
673 | 673 | |
|
674 | def safe_unicode(str): | |
|
675 | """safe unicode function. In case of UnicodeDecode error we try to return | |
|
676 | unicode with errors replace, if this failes we return unicode with | |
|
677 | string_escape decoding """ | |
|
678 | ||
|
679 | try: | |
|
680 | u_str = unicode(str) | |
|
681 | except UnicodeDecodeError: | |
|
682 | try: | |
|
683 | u_str = unicode(str, 'utf-8', 'replace') | |
|
684 | except UnicodeDecodeError: | |
|
685 | #incase we have a decode error just represent as byte string | |
|
686 | u_str = unicode(str(str).encode('string_escape')) | |
|
687 | ||
|
688 | return u_str | |
|
689 | ||
|
690 | 674 | def changed_tooltip(nodes): |
|
691 | 675 | if nodes: |
|
692 | 676 | pref = ': <br/> ' |
@@ -25,9 +25,14 b'' | |||
|
25 | 25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
26 | 26 | # MA 02110-1301, USA. |
|
27 | 27 | |
|
28 | import os | |
|
28 | 29 | import sys |
|
29 |
import |
|
|
30 | import logging | |
|
30 | 31 | import traceback |
|
32 | ||
|
33 | from shutil import rmtree | |
|
34 | from time import mktime | |
|
35 | ||
|
31 | 36 | from os.path import dirname as dn |
|
32 | 37 | from os.path import join as jn |
|
33 | 38 | |
@@ -37,15 +42,14 b' sys.path.append(project_path)' | |||
|
37 | 42 | |
|
38 | 43 | |
|
39 | 44 | from rhodecode.model.scm import ScmModel |
|
40 |
from rhodecode.lib |
|
|
41 | from whoosh.index import create_in, open_dir | |
|
42 | from shutil import rmtree | |
|
45 | from rhodecode.lib import safe_unicode | |
|
43 | 46 | from rhodecode.lib.indexers import INDEX_EXTENSIONS, SCHEMA, IDX_NAME |
|
44 | 47 | |
|
45 | from time import mktime | |
|
46 | 48 | from vcs.exceptions import ChangesetError, RepositoryError |
|
47 | 49 | |
|
48 | import logging | |
|
50 | from whoosh.index import create_in, open_dir | |
|
51 | ||
|
52 | ||
|
49 | 53 | |
|
50 | 54 | log = logging.getLogger('whooshIndexer') |
|
51 | 55 | # create logger |
General Comments 0
You need to be logged in to leave comments.
Login now