| 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 copy | 5 import copy |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 from collections import defaultdict, Mapping | 9 from collections import defaultdict, Mapping |
| 10 | 10 |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 | 546 |
| 547 | 547 |
| 548 class APIDataSource(object): | 548 class APIDataSource(object): |
| 549 '''This class fetches and loads JSON APIs from the FileSystem passed in with | 549 '''This class fetches and loads JSON APIs from the FileSystem passed in with |
| 550 |compiled_fs_factory|, so the APIs can be plugged into templates. | 550 |compiled_fs_factory|, so the APIs can be plugged into templates. |
| 551 ''' | 551 ''' |
| 552 | 552 |
| 553 class Factory(object): | 553 class Factory(object): |
| 554 def __init__(self, | 554 def __init__(self, |
| 555 compiled_fs_factory, | 555 compiled_fs_factory, |
| 556 file_system, |
| 556 base_path, | 557 base_path, |
| 557 availability_finder, | 558 availability_finder, |
| 558 branch_utility): | 559 branch_utility): |
| 559 def create_compiled_fs(fn, category): | 560 def create_compiled_fs(fn, category): |
| 560 return compiled_fs_factory.Create(fn, APIDataSource, category=category) | 561 return compiled_fs_factory.Create( |
| 562 file_system, fn, APIDataSource, category=category) |
| 561 | 563 |
| 562 self._json_cache = create_compiled_fs( | 564 self._json_cache = create_compiled_fs( |
| 563 lambda api_name, api: self._LoadJsonAPI(api, False), | 565 lambda api_name, api: self._LoadJsonAPI(api, False), |
| 564 'json') | 566 'json') |
| 565 self._idl_cache = create_compiled_fs( | 567 self._idl_cache = create_compiled_fs( |
| 566 lambda api_name, api: self._LoadIdlAPI(api, False), | 568 lambda api_name, api: self._LoadIdlAPI(api, False), |
| 567 'idl') | 569 'idl') |
| 568 | 570 |
| 569 # These caches are used if an APIDataSource does not want to resolve the | 571 # These caches are used if an APIDataSource does not want to resolve the |
| 570 # $refs in an API. This is needed to prevent infinite recursion in | 572 # $refs in an API. This is needed to prevent infinite recursion in |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 | 724 |
| 723 if self._disable_refs: | 725 if self._disable_refs: |
| 724 cache, ext = ( | 726 cache, ext = ( |
| 725 (self._idl_cache_no_refs, '.idl') if (unix_name in idl_names) else | 727 (self._idl_cache_no_refs, '.idl') if (unix_name in idl_names) else |
| 726 (self._json_cache_no_refs, '.json')) | 728 (self._json_cache_no_refs, '.json')) |
| 727 else: | 729 else: |
| 728 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else | 730 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else |
| 729 (self._json_cache, '.json')) | 731 (self._json_cache, '.json')) |
| 730 return self._GenerateHandlebarContext( | 732 return self._GenerateHandlebarContext( |
| 731 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)).Get()) | 733 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)).Get()) |
| OLD | NEW |