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. | |
|
chanli
2017/01/18 22:14:23
A comment of this file in general: I think it'll b
Sharu Jiang
2017/01/19 00:00:52
The ``MetaDict`` and ``Element`` are all ``MetaObj
| |
| 4 | |
| 5 | |
| 6 class MetaObject(object): | |
| 7 """Class that can be eight one element of a collection of elements.""" | |
|
chanli
2017/01/18 22:14:23
I don't understand the docstring... Could you expl
Sharu Jiang
2017/01/19 00:00:52
Sorry, 2 typos... Corrected.
| |
| 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 def IsElement(self): | |
| 17 return True | |
| 18 | |
| 19 | |
| 20 class MetaDict(MetaObject): | |
| 21 """Dict-like object containing a collection of ``MetaObject``s.""" | |
| 22 | |
| 23 def __init__(self, value): | |
| 24 """Construct a meta dict from a dict of meta objects. | |
| 25 | |
| 26 Args: | |
| 27 value (dict): Dict of meta objects. | |
| 28 """ | |
| 29 self._value = value | |
| 30 | |
| 31 def IsElement(self): | |
|
chanli
2017/01/18 22:14:24
How about change this to a parameter function?
Sharu Jiang
2017/01/19 00:00:52
You mean property? Done.
| |
| 32 return False | |
| 33 | |
| 34 def __getitem__(self, key): | |
| 35 return self._value[key] | |
| 36 | |
| 37 def __setitem__(self, key, val): | |
| 38 self._value[key] = val | |
| 39 | |
| 40 def get(self, key, default=None): | |
| 41 return self._value.get(key, default) | |
| 42 | |
| 43 def __iter__(self): | |
| 44 return iter(self._value) | |
| 45 | |
| 46 def __eq__(self, other): | |
| 47 return self._value == other._value | |
| 48 | |
| 49 def iteritems(self): | |
| 50 return self._value.iteritems() | |
| 51 | |
| 52 def itervalues(self): | |
| 53 return self._value.itervalues() | |
| 54 | |
| 55 def keys(self): | |
| 56 return self._value.keys() | |
| 57 | |
| 58 def values(self): | |
| 59 return self._value.values() | |
| OLD | NEW |