Mercurial > kallithea
comparison rhodecode/lib/__init__.py @ 1199:268fa0b6b2ef beta
Added os.sep in models for better win support
fixed safe unicode function to not use str as param, and skip execution on unicode
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 02 Apr 2011 21:19:16 +0200 |
parents | 36fe593dfe4b |
children | 6832ef664673 |
comparison
equal
deleted
inserted
replaced
1198:02a7f263a849 | 1199:268fa0b6b2ef |
---|---|
46 if salt is None: | 46 if salt is None: |
47 salt = _RandomNameSequence().next() | 47 salt = _RandomNameSequence().next() |
48 | 48 |
49 return hashlib.sha1(username + salt).hexdigest() | 49 return hashlib.sha1(username + salt).hexdigest() |
50 | 50 |
51 def safe_unicode(str): | 51 def safe_unicode(_str): |
52 """ | 52 """ |
53 safe unicode function. In case of UnicodeDecode error we try to return | 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 | 54 unicode with errors replace, if this fails we return unicode with |
55 string_escape decoding | 55 string_escape decoding |
56 """ | 56 """ |
57 | 57 |
58 if isinstance(_str, unicode): | |
59 return _str | |
60 | |
58 try: | 61 try: |
59 u_str = unicode(str) | 62 u_str = unicode(_str) |
60 except UnicodeDecodeError: | 63 except UnicodeDecodeError: |
61 try: | 64 try: |
62 u_str = unicode(str, 'utf-8', 'replace') | 65 u_str = _str.decode('utf-8', 'replace') |
63 except UnicodeDecodeError: | 66 except UnicodeDecodeError: |
64 #incase we have a decode error just represent as byte string | 67 #incase we have a decode error just represent as byte string |
65 u_str = unicode(str(str).encode('string_escape')) | 68 u_str = unicode(_str.encode('string_escape')) |
66 | 69 |
67 return u_str | 70 return u_str |