Skip to content
Snippets Groups Projects

MAINT: refactor _Messages class

Merged Henrik tom Wörden requested to merge f-messages into dev
All threads resolved!
Files
3
@@ -2400,9 +2400,8 @@ class _ParentList(list):
class Messages(list):
"""This 'kind of dictionary' stores error, warning, info, and other
messages. The mentioned three messages types are messages of special use.
"""This specialization of list stores error, warning, info, and other
messages. The mentioned three messages types play a special role.
They are generated by the client and the server while processing the entity
to which the message in question belongs. It is RECOMMENDED NOT to specify
such messages manually. The other messages are ignored by the server unless
@@ -2413,13 +2412,6 @@ class Messages(list):
<$Type code=$code description=$description>$body</$Type>
Messages are treated as 'equal' if and only if both they have the same type (case-insensitive),
and the same code (or no code). Every message
MUST NOT occur more than once per entity (to which the message in question belongs).
If a message m2 is added while a messages m1 is already in this Message object m2 will
OVERRIDE m1.
Error, warning, and info messages will be deleted before any transaction.
Examples:
@@ -2442,30 +2434,12 @@ class Messages(list):
<<< msgs.append(msg)
<<< # get it back via get(...) and the key tuple (type, code)
<<< assert id(msgs.get("HelloWorld",1))==id(msg)
<<< # delete Message via remove and the (type,code) tuple
<<< msgs.remove("HelloWorld",1)
<<< assert msgs.get("HelloWorld",1) == None
<<< # short version of adding/setting/resetting a new Message
<<< msgs["HelloWorld",2] = "Greeting the world in German", "Hallo, Welt!"
<<< assert msgs["HelloWorld",2] == ("Greeting the world in German","Hallo, Welt!")
<<< msgs["HelloWorld",2] = "Greeting the world in German", "Huhu, Welt!"
<<< assert msgs["HelloWorld",2] == ("Greeting the world in German","Huhu, Welt!")
<<< del msgs["HelloWorld",2]
<<< assert msgs.get("HelloWorld",2) == None
# this Message has no code and no description (make easy things easy...)
<<<
<<< msgs["HelloWorld"] = "Hello!"
<<< assert msgs["HelloWorld"] == "Hello!"
(to be continued...)
"""
def clear_server_messages(self):
"""Removes all messages of type error, warning and info."""
# TODO Why do we not remove ALL messages?
"""Removes all messages of type error, warning and info. All other
messages types are custom types which should be handled by custom
code."""
rem = []
for m in self:
@@ -2637,7 +2611,8 @@ class Messages(list):
return self.__hash__() == obj.__hash__()
def __hash__(self):
return
return hash(str(self._type).lower() + (str(",") + str(self._code)
if self._code is not None else ''))
def __repr__(self):
return str(self._type) + (str(",") + str(self._code)
Loading