Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2017 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 | |
| 6 class MetaObject(object): | |
| 7 """Class that can be either one element or a collection of elements.""" | |
| 8 | |
| 9 def IsElement(self): # pragma: no cover | |
| 10 return NotImplementedError() | |
| 11 | |
| 12 | |
| 13 class Element(MetaObject): | |
| 14 """Element class that cannot be divided anymore.""" | |
| 15 | |
| 16 @property | |
| 17 def is_element(self): | |
| 18 return True | |
| 19 | |
| 20 | |
| 21 class MetaDict(MetaObject): | |
| 22 """Dict-like object containing a collection of ``MetaObject``s.""" | |
| 23 | |
| 24 def __init__(self, value): | |
| 25 """Construct a meta dict from a dict of meta objects. | |
| 26 | |
| 27 Args: | |
| 28 value (dict): Dict of meta objects. | |
| 29 """ | |
| 30 self._value = value | |
|
chanli
2017/01/22 00:07:20
So what I meant in meta_object_test.py is that I d
Sharu Jiang
2017/01/23 20:45:40
Good point, it is safer to make deepcopy here.
| |
| 31 | |
| 32 @property | |
| 33 def is_element(self): | |
| 34 return False | |
| 35 | |
| 36 def __getitem__(self, key): | |
| 37 return self._value[key] | |
| 38 | |
| 39 def __setitem__(self, key, val): | |
| 40 self._value[key] = val | |
| 41 | |
| 42 def get(self, key, default=None): | |
| 43 return self._value.get(key, default) | |
| 44 | |
| 45 def __iter__(self): | |
| 46 return iter(self._value) | |
| 47 | |
| 48 def __eq__(self, other): | |
| 49 return self._value == other._value | |
| 50 | |
| 51 def iteritems(self): | |
| 52 return self._value.iteritems() | |
| 53 | |
| 54 def itervalues(self): | |
| 55 return self._value.itervalues() | |
| 56 | |
| 57 def keys(self): | |
| 58 return self._value.keys() | |
| 59 | |
| 60 def values(self): | |
| 61 return self._value.values() | |
| OLD | NEW |