strings_data_source.py revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
1# Copyright 2013 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 5from data_source import DataSource 6from third_party.json_schema_compiler.json_parse import Parse 7 8class StringsDataSource(DataSource): 9 '''Provides templates with access to a key to string mapping defined in a 10 JSON configuration file. 11 ''' 12 def __init__(self, server_instance, _): 13 self._cache = server_instance.compiled_fs_factory.Create( 14 server_instance.host_file_system_provider.GetTrunk(), 15 lambda _, strings_json: Parse(strings_json), 16 StringsDataSource) 17 self._strings_json_path = server_instance.strings_json_path 18 19 def Cron(self): 20 self._cache.GetFromFile(self._strings_json_path).Get() 21 22 def get(self, key): 23 return self._cache.GetFromFile(self._strings_json_path).Get()[key] 24