Chromium Code Reviews| Index: appengine/findit/libs/meta_object.py |
| diff --git a/appengine/findit/libs/meta_object.py b/appengine/findit/libs/meta_object.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1fe46d9c8569caa27f55863d0a8d6e00256ff40a |
| --- /dev/null |
| +++ b/appengine/findit/libs/meta_object.py |
| @@ -0,0 +1,59 @@ |
| +# Copyright 2017 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# 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
|
| + |
| + |
| +class MetaObject(object): |
| + """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.
|
| + |
| + def IsElement(self): # pragma: no cover |
| + return NotImplementedError() |
| + |
| + |
| +class Element(MetaObject): |
| + """Element class that cannot be divided anymore.""" |
| + |
| + def IsElement(self): |
| + return True |
| + |
| + |
| +class MetaDict(MetaObject): |
| + """Dict-like object containing a collection of ``MetaObject``s.""" |
| + |
| + def __init__(self, value): |
| + """Construct a meta dict from a dict of meta objects. |
| + |
| + Args: |
| + value (dict): Dict of meta objects. |
| + """ |
| + self._value = value |
| + |
| + 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.
|
| + return False |
| + |
| + def __getitem__(self, key): |
| + return self._value[key] |
| + |
| + def __setitem__(self, key, val): |
| + self._value[key] = val |
| + |
| + def get(self, key, default=None): |
| + return self._value.get(key, default) |
| + |
| + def __iter__(self): |
| + return iter(self._value) |
| + |
| + def __eq__(self, other): |
| + return self._value == other._value |
| + |
| + def iteritems(self): |
| + return self._value.iteritems() |
| + |
| + def itervalues(self): |
| + return self._value.itervalues() |
| + |
| + def keys(self): |
| + return self._value.keys() |
| + |
| + def values(self): |
| + return self._value.values() |