From 1316ed9d1644234106035d76f48d6362c41bf914 Mon Sep 17 00:00:00 2001 From: Bryan Duxbury Date: Thu, 2 Sep 2010 14:20:01 +0000 Subject: [PATCH] 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 --- compiler/cpp/src/generate/t_generator.cc | 6 +++++- compiler/cpp/src/generate/t_py_generator.cc | 13 +++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/compiler/cpp/src/generate/t_generator.cc b/compiler/cpp/src/generate/t_generator.cc index 3a2c002c..c91929c7 100644 --- a/compiler/cpp/src/generate/t_generator.cc +++ b/compiler/cpp/src/generate/t_generator.cc @@ -102,7 +102,11 @@ void t_generator::generate_docstring_comment(ofstream& out, 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 891ba305..92471aca 100644 --- a/compiler/cpp/src/generate/t_py_generator.cc +++ b/compiler/cpp/src/generate/t_py_generator.cc @@ -423,7 +423,7 @@ void t_py_generator::generate_const(t_const* tconst) { 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 @@ void t_py_generator::generate_py_struct_definition(ofstream& out, const vector& sorted_members = tstruct->get_sorted_members(); vector::const_iterator m_iter; - out << + out << std::endl << "class " << tstruct->get_name(); if (is_exception) { out << "(Exception)"; @@ -711,8 +711,6 @@ void t_py_generator::generate_py_struct_definition(ofstream& out, out << indent() << "return not (self == other)" << endl; indent_down(); - out << endl; - indent_down(); } @@ -901,7 +899,6 @@ void t_py_generator::generate_service(t_service* tservice) { generate_service_remote(tservice); // Close service file - f_service_ << endl; f_service_.close(); } @@ -915,7 +912,7 @@ void t_py_generator::generate_service_helpers(t_service* tservice) { vector::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 @@ void t_py_generator::generate_service_remote(t_service* tservice) { "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 << -- 2.17.1