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 hashlib | 5 import hashlib |
6 import json | 6 import json |
7 import logging | 7 import logging |
8 import posixpath | 8 import posixpath |
9 import re | 9 import re |
10 import traceback | 10 import traceback |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 if accept_language is None: | 184 if accept_language is None: |
185 return [] | 185 return [] |
186 return [lang_with_q.split(';')[0].strip() | 186 return [lang_with_q.split(';')[0].strip() |
187 for lang_with_q in accept_language.split(',')] | 187 for lang_with_q in accept_language.split(',')] |
188 | 188 |
189 def FilterSamples(self, key, api_name): | 189 def FilterSamples(self, key, api_name): |
190 '''Fetches and filters the list of samples specified by |key|, returning | 190 '''Fetches and filters the list of samples specified by |key|, returning |
191 only the samples that use the API |api_name|. |key| is either 'apps' or | 191 only the samples that use the API |api_name|. |key| is either 'apps' or |
192 'extensions'. | 192 'extensions'. |
193 ''' | 193 ''' |
194 api_search = api_name.replace('.', '_') + '_' | 194 api_search = api_name + '.' |
195 samples_list = [] | 195 samples_list = [] |
196 try: | 196 try: |
197 for sample in self.get(key): | 197 for sample in self.get(key): |
198 api_calls_unix = [model.UnixName(call['name']) | 198 api_calls_unix = [call['name'] for call in sample['api_calls']] |
199 for call in sample['api_calls']] | |
200 for call in api_calls_unix: | 199 for call in api_calls_unix: |
201 if call.startswith(api_search): | 200 if call.startswith(api_search): |
202 samples_list.append(sample) | 201 samples_list.append(sample) |
203 break | 202 break |
not at google - send to devlin
2013/10/24 20:27:54
thanks for this fix. It can be much simpler:
try:
方觉(Fang Jue)
2013/10/25 00:59:46
It's not actually correct but I got what you meant
| |
204 except NotImplementedError: | 203 except NotImplementedError: |
205 # If we're testing, the GithubFileSystem can't fetch samples. | 204 # If we're testing, the GithubFileSystem can't fetch samples. |
206 # Bug: http://crbug.com/141910 | 205 # Bug: http://crbug.com/141910 |
207 return [] | 206 return [] |
208 return samples_list | 207 return samples_list |
209 | 208 |
210 def _CreateSamplesDict(self, key): | 209 def _CreateSamplesDict(self, key): |
211 if key == 'apps': | 210 if key == 'apps': |
212 samples_list = self._apps_cache.GetFromFileListing('/').Get() | 211 samples_list = self._apps_cache.GetFromFileListing('/').Get() |
213 else: | 212 else: |
(...skipping 28 matching lines...) Expand all Loading... | |
242 else: | 241 else: |
243 dict_['id'] = self._GetSampleId(name) | 242 dict_['id'] = self._GetSampleId(name) |
244 return_list.append(dict_) | 243 return_list.append(dict_) |
245 return return_list | 244 return return_list |
246 | 245 |
247 def get(self, key): | 246 def get(self, key): |
248 return { | 247 return { |
249 'apps': lambda: self._CreateSamplesDict('apps'), | 248 'apps': lambda: self._CreateSamplesDict('apps'), |
250 'extensions': lambda: self._CreateSamplesDict('extensions') | 249 'extensions': lambda: self._CreateSamplesDict('extensions') |
251 }.get(key, lambda: {})() | 250 }.get(key, lambda: {})() |
OLD | NEW |