| 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 logging | 5 import logging |
| 6 | 6 |
| 7 from data_source import DataSource | 7 from data_source import DataSource |
| 8 from docs_server_utils import StringIdentity | 8 from docs_server_utils import StringIdentity |
| 9 from environment import IsPreviewServer | 9 from environment import IsPreviewServer |
| 10 from file_system import FileNotFoundError | 10 from file_system import FileNotFoundError |
| 11 from future import All, Future | 11 from future import All, Future |
| 12 from jsc_view import CreateJSCView, GetEventByNameFromEvents | 12 from jsc_view import CreateJSCView, GetEventByNameFromEvents |
| 13 from platform_util import GetPlatforms | 13 from platform_util import GetPlatforms |
| 14 from third_party.json_schema_compiler.model import UnixName | |
| 15 | 14 |
| 16 | 15 |
| 17 class APIDataSource(DataSource): | 16 class APIDataSource(DataSource): |
| 18 '''This class fetches and loads JSON APIs from the FileSystem passed in with | 17 '''This class fetches and loads JSON APIs from the FileSystem passed in with |
| 19 |compiled_fs_factory|, so the APIs can be plugged into templates. | 18 |compiled_fs_factory|, so the APIs can be plugged into templates. |
| 20 ''' | 19 ''' |
| 21 def __init__(self, server_instance, request): | 20 def __init__(self, server_instance, request): |
| 22 file_system = server_instance.host_file_system_provider.GetMaster() | 21 file_system = server_instance.host_file_system_provider.GetMaster() |
| 23 self._json_cache = server_instance.compiled_fs_factory.ForJson(file_system) | 22 self._json_cache = server_instance.compiled_fs_factory.ForJson(file_system) |
| 24 self._template_cache = server_instance.compiled_fs_factory.ForTemplates( | 23 self._template_cache = server_instance.compiled_fs_factory.ForTemplates( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 ''' | 82 ''' |
| 84 getter = lambda: 0 | 83 getter = lambda: 0 |
| 85 getter.get = lambda api_name: self._GetSchemaView(platform, api_name).Get() | 84 getter.get = lambda api_name: self._GetSchemaView(platform, api_name).Get() |
| 86 return getter | 85 return getter |
| 87 | 86 |
| 88 def Refresh(self): | 87 def Refresh(self): |
| 89 def get_api_schema(platform, api): | 88 def get_api_schema(platform, api): |
| 90 return self._GetSchemaView(platform, api) | 89 return self._GetSchemaView(platform, api) |
| 91 | 90 |
| 92 def get_platform_schemas(platform): | 91 def get_platform_schemas(platform): |
| 92 # Internal APIs are an internal implementation detail. Do not pass them to |
| 93 # templates. |
| 93 return All([get_api_schema(platform, api) | 94 return All([get_api_schema(platform, api) |
| 94 for api in self._platform_bundle.GetAPIModels(platform) | 95 for api in self._platform_bundle.GetAPIModels(platform) |
| 95 .GetNames()], | 96 .GetNames() |
| 97 if self._platform_bundle.GetAPICategorizer(platform) |
| 98 .GetCategory(api) != 'internal'], |
| 96 except_pass=FileNotFoundError) | 99 except_pass=FileNotFoundError) |
| 97 | 100 |
| 98 return All([get_platform_schemas(platform) for platform in GetPlatforms()]) | 101 return All([get_platform_schemas(platform) for platform in GetPlatforms()]) |
| OLD | NEW |