Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: chrome/common/extensions/docs/server2/api_data_source.py

Issue 10546078: Extension docs server: APIDataSource (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: FetcherCache Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 import json
6 import os
7
8 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater
9 import third_party.json_schema_compiler.model as model
10
11 class APIDataSource(object):
12 """This class fetches and loads JSON APIs with the fetcher passed in with
13 |cache_builder|, so the APIs can be plugged into templates.
14 """
15 def _LoadAPI(self, api):
16 return json.loads(json_comment_eater.Nom(api))[0]
not at google - send to devlin 2012/06/18 19:30:40 nit: either make static / pull outside the class (
cduvall 2012/06/18 19:48:46 Done.
17
18 def __init__(self, cache_builder, base_paths):
19 self._cache = cache_builder.build(self._LoadAPI)
not at google - send to devlin 2012/06/18 19:30:40 nice
20 self._base_paths = base_paths
21
22 def __getitem__(self, key):
23 return self.get(key)
24
25 def get(self, key):
26 path, ext = os.path.splitext(key)
27 unix_name = model.UnixName(path)
28 json_path = unix_name + '.json'
29 for base_path in self._base_paths:
30 try:
31 return self._cache.get(base_path + '/' + json_path)
32 except:
33 pass
34 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698