From eed6aa7f80fd158ab88c2b409fc903acbf0d8df8 Mon Sep 17 00:00:00 2001 From: Thibault Vataire Date: Fri, 10 Dec 2021 10:19:13 +0100 Subject: [PATCH] Add implementation of the collections.abc.Mapping abstract class to ZObject class. Allow to use mixin methods of the Mapping container on ZObject instances. --- zimsoap/zobjects.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/zimsoap/zobjects.py b/zimsoap/zobjects.py index 059fa44..61550e2 100644 --- a/zimsoap/zobjects.py +++ b/zimsoap/zobjects.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import unicode_literals +from collections.abc import Mapping """ Zimbra specific objects, handle (un)parsing to/from XML and other glue-code @@ -18,7 +19,7 @@ class NotEnoughInformation(Exception): pass -class ZObject(object): +class ZObject(Mapping, object): """ An abstract class to handle Zimbra Concepts A ZObject map to a tag name (subclasses have to define cls.TAG_NAME) : @@ -90,6 +91,12 @@ def __getitem__(self, k): def __setitem__(self, k, v): self._a_tags[k] = utils.auto_type(v) + def __iter__(self): + return iter(self._a_tags) + + def __len__(self): + return len(self._a_tags) + def __repr__(self): most_significant_id = getattr(self, 'id', hex(id(self)))