summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/PythonUtil.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2009-09-22 16:22:53 -0700
committerMark Spruiell <mes@zeroc.com>2009-09-22 16:22:53 -0700
commit50fb9c16c2f97abe5b3c986fd257cd6abd1e458a (patch)
tree5448d845b289ebab5b434c191ed596239f5646b8 /cpp/src/Slice/PythonUtil.cpp
parent2214 - AMD missed files (diff)
downloadice-50fb9c16c2f97abe5b3c986fd257cd6abd1e458a.tar.bz2
ice-50fb9c16c2f97abe5b3c986fd257cd6abd1e458a.tar.xz
ice-50fb9c16c2f97abe5b3c986fd257cd6abd1e458a.zip
bug 4217 - improve __cmp__ method in Python generated code
Diffstat (limited to 'cpp/src/Slice/PythonUtil.cpp')
-rw-r--r--cpp/src/Slice/PythonUtil.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/cpp/src/Slice/PythonUtil.cpp b/cpp/src/Slice/PythonUtil.cpp
index 3d626d9b72a..1f1be440704 100644
--- a/cpp/src/Slice/PythonUtil.cpp
+++ b/cpp/src/Slice/PythonUtil.cpp
@@ -1171,10 +1171,8 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p)
_out << sp << nl << "def __cmp__(self, other):";
_out.inc();
- _out << nl << "if other == None:";
+ _out << nl << "if isinstance(other, _M_" << abs << "):";
_out.inc();
- _out << nl << "return 1";
- _out.dec();
for(r = memberList.begin(); r != memberList.end(); ++r)
{
_out << nl << "if self." << r->fixedName << " < other." << r->fixedName << ':';
@@ -1188,6 +1186,12 @@ Slice::Python::CodeVisitor::visitStructStart(const StructPtr& p)
}
_out << nl << "return 0";
_out.dec();
+ _out << nl << "elif other == None:";
+ _out.inc();
+ _out << nl << "return 1";
+ _out.dec();
+ _out << nl << "return NotImplemented";
+ _out.dec();
//
// __str__
@@ -1356,6 +1360,8 @@ Slice::Python::CodeVisitor::visitEnum(const EnumPtr& p)
_out.dec();
_out << sp << nl << "def __str__(self):";
_out.inc();
+ _out << nl << "return _names(self.value)";
+#if 0
for(q = enums.begin(), i = 0; q != enums.end(); ++q, ++i)
{
_out << nl;
@@ -1375,6 +1381,7 @@ Slice::Python::CodeVisitor::visitEnum(const EnumPtr& p)
_out.dec();
}
_out << nl << "return None";
+#endif
_out.dec();
_out << sp << nl << "__repr__ = __str__";
_out << sp << nl << "def __hash__(self):";
@@ -1385,6 +1392,21 @@ Slice::Python::CodeVisitor::visitEnum(const EnumPtr& p)
_out.inc();
_out << nl << "return cmp(self.value, other.value)";
_out.dec();
+
+ _out << sp << nl << "_names = (";
+ for(q = enums.begin(), i = 0; q != enums.end(); ++q, ++i)
+ {
+ if(q != enums.begin())
+ {
+ _out << ", ";
+ }
+ _out << "'" << (*q)->name() << "'";
+ }
+ if(enums.size() == 1)
+ {
+ _out << ',';
+ }
+ _out << ')';
_out.dec();
_out << sp;