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