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