THRIFT-471. python: Generated exceptions should implement __str__

This makes Python stack dumps properly show the exception content.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@770002 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index cd7f760..343c982 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -637,6 +637,16 @@
   generate_py_struct_reader(out, tstruct);
   generate_py_struct_writer(out, tstruct);
 
+  // For exceptions only, generate a __str__ method. This is
+  // because when raised exceptions are printed to the console, __repr__
+  // isn't used. See python bug #5882
+  if (is_exception) {
+    out <<
+      indent() << "def __str__(self):" << endl <<
+      indent() << "  return repr(self)" << endl <<
+      endl;
+  }
+
   // Printing utilities so that on the command line thrift
   // structs look pretty like dictionaries
   out <<