| 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 |
| 11 '.'s to '_'s. | 11 '.'s to '_'s. |
| 12 ''' | 12 ''' |
| 13 if key.endswith('.html'): | 13 if key.endswith('.html'): |
| 14 key = key[:-len('.html')] | 14 key = key[:-len('.html')] |
| 15 safe_key = key.replace('.', '_') | 15 safe_key = key.replace('.', '_') |
| 16 return '%s.html' % safe_key | 16 return '%s.html' % safe_key |
| 17 | 17 |
| 18 def SanitizeAPIName(name): | 18 def SanitizeAPIName(name): |
| 19 '''Sanitizes API filenames that are in subdirectories. | 19 '''Sanitizes API filenames that are in subdirectories. |
| 20 ''' | 20 ''' |
| 21 filename = os.path.splitext(name)[0].replace(os.sep, '_') | 21 filename = os.path.splitext(name)[0].replace(os.sep, '_') |
| 22 if 'experimental' in filename: | 22 if 'experimental' in filename: |
| 23 filename = 'experimental_' + filename.replace('experimental_', '') | 23 filename = 'experimental_' + filename.replace('experimental_', '') |
| 24 return filename | 24 return filename |
| 25 | 25 |
| 26 def StringIdentity(string): | 26 def StringIdentity(string): |
| 27 '''Creates a small hash of a string. | 27 '''Creates a small hash of a string. |
| 28 ''' | 28 ''' |
| 29 return b64encode(sha1(string).digest())[:8] | 29 return b64encode(sha1(string).digest())[:8] |
| 30 |
| 31 def MarkLast(dicts): |
| 32 '''Adds a property 'last' == True to the last element in a list of dicts. |
| 33 ''' |
| 34 if len(dicts) > 0: |
| 35 dicts[-1]['last'] = True |
| OLD | NEW |