Show More
@@ -1,46 +1,46 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | rhodecode.lib.__init__ |
|
3 | rhodecode.lib.__init__ | |
4 | ~~~~~~~~~~~~~~~~~~~~~~~ |
|
4 | ~~~~~~~~~~~~~~~~~~~~~~~ | |
5 |
|
5 | |||
6 | Some simple helper functions |
|
6 | Some simple helper functions | |
7 |
|
7 | |||
8 | :created_on: Jan 5, 2011 |
|
8 | :created_on: Jan 5, 2011 | |
9 | :author: marcink |
|
9 | :author: marcink | |
10 |
:copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
10 | :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
11 | :license: GPLv3, see COPYING for more details. |
|
11 | :license: GPLv3, see COPYING for more details. | |
12 | """ |
|
12 | """ | |
13 | # This program is free software; you can redistribute it and/or |
|
13 | # This program is free software; you can redistribute it and/or | |
14 | # modify it under the terms of the GNU General Public License |
|
14 | # modify it under the terms of the GNU General Public License | |
15 | # as published by the Free Software Foundation; version 2 |
|
15 | # as published by the Free Software Foundation; version 2 | |
16 | # of the License or (at your opinion) any later version of the license. |
|
16 | # of the License or (at your opinion) any later version of the license. | |
17 |
# |
|
17 | # | |
18 | # This program is distributed in the hope that it will be useful, |
|
18 | # This program is distributed in the hope that it will be useful, | |
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | # GNU General Public License for more details. |
|
21 | # GNU General Public License for more details. | |
22 |
# |
|
22 | # | |
23 | # You should have received a copy of the GNU General Public License |
|
23 | # You should have received a copy of the GNU General Public License | |
24 | # along with this program; if not, write to the Free Software |
|
24 | # along with this program; if not, write to the Free Software | |
25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
26 | # MA 02110-1301, USA. |
|
26 | # MA 02110-1301, USA. | |
27 |
|
27 | |||
28 | def str2bool(v): |
|
28 | def str2bool(v): | |
29 | if isinstance(v, (str, unicode)): |
|
29 | if isinstance(v, (str, unicode)): | |
30 | obj = v.strip().lower() |
|
30 | obj = v.strip().lower() | |
31 | if obj in ['true', 'yes', 'on', 'y', 't', '1']: |
|
31 | if obj in ['true', 'yes', 'on', 'y', 't', '1']: | |
32 | return True |
|
32 | return True | |
33 | elif obj in ['false', 'no', 'off', 'n', 'f', '0']: |
|
33 | elif obj in ['false', 'no', 'off', 'n', 'f', '0']: | |
34 | return False |
|
34 | return False | |
35 | else: |
|
35 | else: | |
36 | raise ValueError("String is not true/false: %r" % obj) |
|
36 | raise ValueError("String is not true/false: %r" % obj) | |
37 |
return bool( |
|
37 | return bool(v) | |
38 |
|
38 | |||
39 | def generate_api_key(username, salt=None): |
|
39 | def generate_api_key(username, salt=None): | |
40 | from tempfile import _RandomNameSequence |
|
40 | from tempfile import _RandomNameSequence | |
41 | import hashlib |
|
41 | import hashlib | |
42 |
|
42 | |||
43 | if salt is None: |
|
43 | if salt is None: | |
44 | salt = _RandomNameSequence().next() |
|
44 | salt = _RandomNameSequence().next() | |
45 |
|
45 | |||
46 | return hashlib.sha1(username + salt).hexdigest() |
|
46 | return hashlib.sha1(username + salt).hexdigest() |
General Comments 0
You need to be logged in to leave comments.
Login now