OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 | 5 |
6 class DataSource(object): | 6 class DataSource(object): |
7 ''' | 7 ''' |
8 Defines an abstraction for all DataSources. | 8 Defines an abstraction for all DataSources. |
9 | 9 |
10 DataSources must have two public methods, get and Cron. A DataSource is | 10 DataSources must have two public methods, get and Cron. A DataSource is |
11 initialized with a ServerInstance. Anything in the ServerInstance can be used | 11 initialized with a ServerInstance and a Request (defined in servlet.py). |
12 by the DataSource. | 12 Anything in the ServerInstance can be used by the DataSource. Request is None |
| 13 when DataSources are created for Cron. |
13 | 14 |
14 DataSources are used to provide templates with access to data. DataSources may | 15 DataSources are used to provide templates with access to data. DataSources may |
15 not access other DataSources and any logic or data that is useful to other | 16 not access other DataSources and any logic or data that is useful to other |
16 DataSources must be moved to a different class. | 17 DataSources must be moved to a different class. |
17 ''' | 18 ''' |
| 19 def __init__(self, server_instance, request): |
| 20 pass |
| 21 |
18 def Cron(self): | 22 def Cron(self): |
19 '''Must cache all files needed by |get| to persist them. Called on a live | 23 '''Must cache all files needed by |get| to persist them. Called on a live |
20 file system and can access files not in cache. | 24 file system and can access files not in cache. |request| will be None. |
21 ''' | 25 ''' |
22 raise NotImplementedError(self.__class__) | 26 raise NotImplementedError(self.__class__) |
23 | 27 |
24 def get(self, key): | 28 def get(self, key): |
25 '''Returns a dictionary or list that can be consumed by a template. Called | 29 '''Returns a dictionary or list that can be consumed by a template. Called |
26 on an offline file system and can only access files in the cache. | 30 on an offline file system and can only access files in the cache. |
27 ''' | 31 ''' |
28 raise NotImplementedError(self.__class__) | 32 raise NotImplementedError(self.__class__) |
OLD | NEW |