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 import json | 5 import json |
6 import logging | 6 import logging |
7 import re | 7 import re |
8 | 8 |
9 DEFAULT_ICON_PATH = '/images/sample-default-icon.png' | 9 DEFAULT_ICON_PATH = '/images/sample-default-icon.png' |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 def _GetAcceptedLanguages(self): | 114 def _GetAcceptedLanguages(self): |
115 accept_language = self._request.headers.get('Accept-Language', None) | 115 accept_language = self._request.headers.get('Accept-Language', None) |
116 if accept_language is None: | 116 if accept_language is None: |
117 return [] | 117 return [] |
118 return [lang_with_q.split(';')[0].strip() | 118 return [lang_with_q.split(';')[0].strip() |
119 for lang_with_q in accept_language.split(',')] | 119 for lang_with_q in accept_language.split(',')] |
120 | 120 |
121 def __getitem__(self, key): | 121 def __getitem__(self, key): |
122 return self.get(key) | 122 return self.get(key) |
123 | 123 |
124 def values(self): | 124 def GetAll(self): |
125 return self.get('') | 125 return self.get('') |
126 | 126 |
127 def get(self, key): | 127 def get(self, key): |
128 samples_list = self._cache.GetFromFileListing(self._samples_path + '/') | 128 samples_list = self._cache.GetFromFileListing(self._samples_path + '/') |
129 return_list = [] | 129 return_list = [] |
130 for dict_ in samples_list: | 130 for dict_ in samples_list: |
131 name = dict_['name'] | 131 name = dict_['name'] |
132 description = dict_['description'] | 132 description = dict_['description'] |
133 if name.startswith('__MSG_') or description.startswith('__MSG_'): | 133 if name.startswith('__MSG_') or description.startswith('__MSG_'): |
134 try: | 134 try: |
(...skipping 10 matching lines...) Expand all Loading... |
145 sample_data['name'] = locale_data[name_key]['message'] | 145 sample_data['name'] = locale_data[name_key]['message'] |
146 sample_data['description'] = locale_data[description_key]['message'] | 146 sample_data['description'] = locale_data[description_key]['message'] |
147 except Exception as e: | 147 except Exception as e: |
148 logging.error(e) | 148 logging.error(e) |
149 # Revert the sample to the original dict. | 149 # Revert the sample to the original dict. |
150 sample_data = dict_ | 150 sample_data = dict_ |
151 return_list.append(sample_data) | 151 return_list.append(sample_data) |
152 else: | 152 else: |
153 return_list.append(dict_) | 153 return_list.append(dict_) |
154 return return_list | 154 return return_list |
OLD | NEW |