Index: chrome/common/extensions/docs/server2/features_model.py |
diff --git a/chrome/common/extensions/docs/server2/features_model.py b/chrome/common/extensions/docs/server2/features_model.py |
index b66bcd332686fae1eae555b639ffb71064d2f1e5..88c57d3bea90ca197baf7641d0ae426af4bb8ddb 100644 |
--- a/chrome/common/extensions/docs/server2/features_model.py |
+++ b/chrome/common/extensions/docs/server2/features_model.py |
@@ -2,8 +2,61 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
+from collections import MutableMapping |
from copy import deepcopy |
+class Feature(MutableMapping): |
+ def __init__(self, inital_dict=None): |
+ inital_dict = inital_dict or dict() |
+ if not 'platform' in inital_dict: |
+ inital_dict['platform'] = [] |
+ inital_dict = inital_dict |
+ self._dict = inital_dict |
+ |
+ def __getitem__(self, key): |
+ return self._dict[key] |
+ |
+ def __setitem__(self, key, value): |
+ self._dict[key] = value |
+ |
+ def __delitem__(self, key): |
+ del self._dict[key] |
+ |
+ def __iter__(self): |
+ return iter(self._dict) |
+ |
+ def __len__(self): |
+ return len(self._dict) |
not at google - send to devlin
2013/08/05 22:23:49
Ok so now this just looks like a super magical dic
|
+ |
+ def __eq__(self, other): |
not at google - send to devlin
2013/08/05 22:23:49
cos python is crap you need to define __ne__ as we
|
+ if isinstance(other, Feature): |
+ return self._dict.__eq__(other._dict) |
+ else: |
+ return self._dict.__eq__(other) |
+ return False |
+ |
+ def __repr__(self): |
+ return '<Feature(%s)>' % self._dict.__repr__() |
not at google - send to devlin
2013/08/05 22:23:49
also override __str__
|
+ |
+ @property |
+ def name(self): |
+ return self._dict['name'] |
+ |
+ @name.setter |
+ def name(self, value): |
+ self._dict['name'] = value |
not at google - send to devlin
2013/08/05 22:23:49
features are supposed to be immutable; why do you
|
+ |
+ @property |
+ def platform(self): |
not at google - send to devlin
2013/08/05 22:23:49
should this be "platforms"?
|
+ return self._dict['platform'] |
+ |
+ @platform.setter |
+ def platform(self, value): |
+ self._dict['platform'] = value |
not at google - send to devlin
2013/08/05 22:23:49
likewise
|
+ |
+ def add_platform(self, value): |
+ self._dict['platform'].append(value) |
not at google - send to devlin
2013/08/05 22:23:49
likewise
|
+ |
class FeaturesModel(object): |
'''Load and manipulate the contents of a features file. FeaturesModel is |
immutable. All features are guaranteed to have 'name' and 'platform' |
@@ -35,16 +88,14 @@ class FeaturesModel(object): |
if 'whitelist' in value: |
continue |
- features[name] = { 'platform': [] } |
+ features[name] = Feature() |
+ features[name].name = name |
platforms = value.pop('extension_types') |
if platforms == 'all' or 'extension' in platforms: |
- features[name]['platform'].append('extension') |
+ features[name].add_platform('extension') |
if platforms == 'all' or 'platform_app' in platforms: |
- features[name]['platform'].append('app') |
- |
- features[name]['name'] = name |
- features[name].update(value) |
+ features[name].add_platform('app') |
not at google - send to devlin
2013/08/05 22:23:49
these should be passed into feature's constructor
|
return FeaturesModel(features) |
@@ -55,7 +106,7 @@ class FeaturesModel(object): |
features = {} |
for name, feature in self._features.items(): |
- if not platform or platform in feature['platform']: |
+ if not platform or platform in feature.platform: |
features[name] = feature |
return FeaturesModel(features) |