comparison rhodecode/lib/__init__.py @ 1136:93b980ebee55

changes for release 1.1.5
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 17 Mar 2011 01:13:48 +0100
parents b2a70582bce3
children 008bdfdd95c8
comparison
equal deleted inserted replaced
1095:3cdacd152b24 1136:93b980ebee55
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 return v.lower() in ["yes", "true", "t", "1"] if v else None 29 if isinstance(v, (str, unicode)):
30 obj = v.strip().lower()
31 if obj in ['true', 'yes', 'on', 'y', 't', '1']:
32 return True
33 elif obj in ['false', 'no', 'off', 'n', 'f', '0']:
34 return False
35 else:
36 raise ValueError("String is not true/false: %r" % obj)
37 return bool(obj)
38
39 def generate_api_key(username, salt=None):
40 from tempfile import _RandomNameSequence
41 import hashlib
42
43 if salt is None:
44 salt = _RandomNameSequence().next()
45
46 return hashlib.sha1(username + salt).hexdigest()