OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from base64 import b64encode | 5 from base64 import b64encode |
6 from hashlib import sha1 | 6 from hashlib import sha1 |
7 import os | 7 import os |
8 | 8 |
9 def FormatKey(key): | 9 def FormatKey(key): |
10 '''Normalize a key by making sure it has a .html extension, and convert any | 10 '''Normalize a key by making sure it has a .html extension, and convert any |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 | 47 |
48 def MarkFirstAndLast(dicts): | 48 def MarkFirstAndLast(dicts): |
49 '''Marks the first and last element in a list of dicts. | 49 '''Marks the first and last element in a list of dicts. |
50 ''' | 50 ''' |
51 MarkFirst(dicts) | 51 MarkFirst(dicts) |
52 MarkLast(dicts) | 52 MarkLast(dicts) |
53 | 53 |
54 def ToUnicode(data): | 54 def ToUnicode(data): |
55 '''Returns the str |data| as a unicode object. It's expected to be utf8, but | 55 '''Returns the str |data| as a unicode object. It's expected to be utf8, but |
56 there are also latin-1 encodings in there for some reason. Fall back to that. | 56 there are also latin-1 encodings in there for some reason. Fall back to that. |
57 | |
58 Returns None if given None. | |
not at google - send to devlin
2015/06/04 22:40:45
I would prefer if call sites checked for this. sen
Ken Rockot(use gerrit already)
2015/06/05 00:21:50
Upon further inspection the bug which was causing
| |
57 ''' | 59 ''' |
60 if data is None: | |
61 return None | |
58 try: | 62 try: |
59 return unicode(data, 'utf-8') | 63 return unicode(data, 'utf-8') |
60 except: | 64 except: |
61 return unicode(data, 'latin-1') | 65 return unicode(data, 'latin-1') |
OLD | NEW |