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