diff options
author | Aarni Koskela <akx@iki.fi> | 2019-05-27 11:19:08 +0300 |
---|---|---|
committer | Aarni Koskela <akx@iki.fi> | 2019-05-27 11:37:12 +0300 |
commit | 1d7a4da9e1a563e800dc6475bc95e1fa58a07473 (patch) | |
tree | e3ed63a3a3524727f33265cf4dd8cfea84f227cb /babel | |
parent | 4fa0c6e5a2d3ae4c10ca160dabe4e3d169dace81 (diff) | |
download | babel-1d7a4da9e1a563e800dc6475bc95e1fa58a07473.tar.gz |
Add comparison operators to _NormalizedString
Based on @hoangduytranuk's original implementation.
Fixes #612
Diffstat (limited to 'babel')
-rw-r--r-- | babel/messages/pofile.py | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py index fe37631..2943fa2 100644 --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -16,8 +16,7 @@ import re from babel.messages.catalog import Catalog, Message from babel.util import wraptext -from babel._compat import text_type - +from babel._compat import text_type, cmp def unescape(string): @@ -99,6 +98,36 @@ class _NormalizedString(object): def __nonzero__(self): return bool(self._strs) + __bool__ = __nonzero__ + + def __repr__(self): + return os.linesep.join(self._strs) + + def __cmp__(self, other): + if not other: + return 1 + + return cmp(text_type(self), text_type(other)) + + def __gt__(self, other): + return self.__cmp__(other) > 0 + + def __lt__(self, other): + return self.__cmp__(other) < 0 + + def __ge__(self, other): + return self.__cmp__(other) >= 0 + + def __le__(self, other): + return self.__cmp__(other) <= 0 + + def __eq__(self, other): + return self.__cmp__(other) == 0 + + def __ne__(self, other): + return self.__cmp__(other) != 0 + + class PoFileParser(object): """Support class to read messages from a ``gettext`` PO (portable object) file |