Commit cfe23d5f authored by Yury's avatar Yury

document, document_dict: return inner dicts and lists as document_type

parent a1a5a444
Pipeline #336 passed with stages
in 4 minutes and 10 seconds
......@@ -182,7 +182,7 @@ class Document(metaclass=MetaDocument):
def __repr__(self):
return "{0}({1})".format(
", ".join(f"{key}={value}" for key, value in self._document_.items())
", ".join(f"{key}={value}" for key, value in self.items())
def __getattribute__(self, item):
from collections import MutableMapping
from collections import MutableMapping, ItemsView
class DocumentDict(MutableMapping):
......@@ -100,3 +100,32 @@ class DocumentDict(MutableMapping):
del self.__data__[item]
except KeyError as e:
raise AttributeError(e)
def items(self):
from mdocument.document_array import DocumentArray
result = []
for name, value in super().items():
if isinstance(value, dict):
result.append((name, DocumentDict(value)))
elif isinstance(value, list):
result.append((name, DocumentArray(value)))
result.append((name, value))
return result
def values(self):
from mdocument.document_array import DocumentArray
result = []
for value in super().values():
if isinstance(value, dict):
elif isinstance(value, list):
return result
def __eq__(self, other):
if isinstance(other, DocumentDict):
return self.__data__ == other.__data__
return self.__data__ == other
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment