THRIFT-673. py: Generated Python code has whitespace issues

This patch trims several forms of trailing whitespace.

Patch: Ian Eure

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@991945 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_generator.cc b/compiler/cpp/src/generate/t_generator.cc
index 3a2c002..c91929c 100644
--- a/compiler/cpp/src/generate/t_generator.cc
+++ b/compiler/cpp/src/generate/t_generator.cc
@@ -102,7 +102,11 @@
   while (!docs.eof()) {
     char line[1024];
     docs.getline(line, 1024);
-    if (strlen(line) > 0 || !docs.eof()) {  // skip the empty last line
+
+    // Just prnt a newline when the line & prefix are empty.
+    if (strlen(line) == 0 && line_prefix == "" && !docs.eof()) {
+        out << std::endl;
+    } else if (strlen(line) > 0 || !docs.eof()) {  // skip the empty last line
       indent(out) << line_prefix << line << std::endl;
     }
   }
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index 891ba30..92471ac 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -423,7 +423,7 @@
   t_const_value* value = tconst->get_value();
 
   indent(f_consts_) << name << " = " << render_const_value(type, value);
-  f_consts_ << endl << endl;
+  f_consts_ << endl;
 }
 
 /**
@@ -573,7 +573,7 @@
   const vector<t_field*>& sorted_members = tstruct->get_sorted_members();
   vector<t_field*>::const_iterator m_iter;
 
-  out <<
+  out << std::endl <<
     "class " << tstruct->get_name();
   if (is_exception) {
     out << "(Exception)";
@@ -711,8 +711,6 @@
   out <<
     indent() << "return not (self == other)" << endl;
   indent_down();
-  out << endl;
-
   indent_down();
 }
 
@@ -901,7 +899,6 @@
   generate_service_remote(tservice);
 
   // Close service file
-  f_service_ << endl;
   f_service_.close();
 }
 
@@ -915,7 +912,7 @@
   vector<t_function*>::iterator f_iter;
 
   f_service_ <<
-    "# HELPER FUNCTIONS AND STRUCTURES" << endl << endl;
+    "# HELPER FUNCTIONS AND STRUCTURES" << endl;
 
   for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
     t_struct* ts = (*f_iter)->get_arglist();
@@ -1338,14 +1335,14 @@
     "argi = 1" << endl <<
     endl <<
     "if sys.argv[argi] == '-h':" << endl <<
-    "  parts = sys.argv[argi+1].split(':') " << endl <<
+    "  parts = sys.argv[argi+1].split(':')" << endl <<
     "  host = parts[0]" << endl <<
     "  port = int(parts[1])" << endl <<
     "  argi += 2" << endl <<
     endl <<
     "if sys.argv[argi] == '-u':" << endl <<
     "  url = urlparse(sys.argv[argi+1])" << endl <<
-    "  parts = url[1].split(':') " << endl <<
+    "  parts = url[1].split(':')" << endl <<
     "  host = parts[0]" << endl <<
     "  if len(parts) > 1:" << endl <<
     "    port = int(parts[1])" << endl <<