summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/PythonUtil.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2012-11-28 18:47:24 -0800
committerMark Spruiell <mes@zeroc.com>2012-11-28 18:47:24 -0800
commit9fb578ab0af6565d6dc3e97eb1fbfdfe8623f0cb (patch)
treec40730351fbaca97f8ac7b9b15ff6d3b24ef50e7 /cpp/src/Slice/PythonUtil.cpp
parentICE-5018 - Python3 failure in py/test/Slice/structure (diff)
downloadice-9fb578ab0af6565d6dc3e97eb1fbfdfe8623f0cb.tar.bz2
ice-9fb578ab0af6565d6dc3e97eb1fbfdfe8623f0cb.tar.xz
ice-9fb578ab0af6565d6dc3e97eb1fbfdfe8623f0cb.zip
ICE-5018 - more fixes for Python mapping
Diffstat (limited to 'cpp/src/Slice/PythonUtil.cpp')
-rw-r--r--cpp/src/Slice/PythonUtil.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index 557d7738250..a9efb9c9e63 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -1352,6 +1352,43 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p)
_out.dec();
_out.dec();
}
+ else
+ {
+ //
+ // Only generate the rich equality operators __eq__ and __ne__.
+ //
+
+ _out << sp << nl << "def __eq__(self, other):";
+ _out.inc();
+ _out << nl << "if other is None:";
+ _out.inc();
+ _out << nl << "return False";
+ _out.dec();
+ _out << nl << "elif not isinstance(other, _M_" << abs << "):";
+ _out.inc();
+ _out << nl << "return NotImplemented";
+ _out.dec();
+ _out << nl << "else:";
+ _out.inc();
+ for(MemberInfoList::iterator r = memberList.begin(); r != memberList.end(); ++r)
+ {
+ //
+ // The None value is not orderable in Python 3.
+ //
+ _out << nl << "if self." << r->fixedName << " != other." << r->fixedName << ':';
+ _out.inc();
+ _out << nl << "return False";
+ _out.dec();
+ }
+ _out << nl << "return True";
+ _out.dec();
+ _out.dec();
+
+ _out << sp << nl << "def __ne__(self, other):";
+ _out.inc();
+ _out << nl << "return not self.__eq__(other)";
+ _out.dec();
+ }
//
// __str__