summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Geyer <jensg@apache.org>2015-09-21 22:43:28 +0200
committerJens Geyer <jensg@apache.org>2015-09-21 22:43:28 +0200
commit61444d7be5d5a0949b87d28d6fc3cd87152716cb (patch)
treeb5f1671c2030d7c57f51969c2b2732688ce519de
parentb9257395509bc6fbcc2f77e0f9237e39f7ec1a7d (diff)
downloadthrift-61444d7be5d5a0949b87d28d6fc3cd87152716cb.tar.gz
THRIFT-557 charset problem with file Autogenerated by Thrift
Client: Python Patch: zhenghuabin <zhenghuabin@bytedance.com> This closes #601
-rw-r--r--compiler/cpp/src/generate/t_py_generator.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index 2002c1e28..10b1680ed 100644
--- a/compiler/cpp/src/generate/t_py_generator.cc
+++ b/compiler/cpp/src/generate/t_py_generator.cc
@@ -99,6 +99,11 @@ public:
iter = parsed_options.find("utf8strings");
gen_utf8strings_ = (iter != parsed_options.end());
+ iter = parsed_options.find("coding");
+ if (iter != parsed_options.end()) {
+ coding_ = iter->second;
+ }
+
copy_options_ = option_string;
if (gen_twisted_) {
@@ -276,6 +281,12 @@ private:
bool gen_utf8strings_;
/**
+ * specify generated file encoding
+ * eg. # -*- coding: utf-8 -*-
+ */
+ string coding_;
+
+ /**
* File streams
*/
@@ -382,7 +393,11 @@ string t_py_generator::render_fastbinary_includes() {
* Autogen'd comment
*/
string t_py_generator::py_autogen_comment() {
- return std::string("#\n") + "# Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n"
+ string coding;
+ if (!coding_.empty()) {
+ coding = "# -*- coding: " + coding_ + " -*-\n";
+ }
+ return coding + std::string("#\n") + "# Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n"
+ "#\n" + "# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" + "#\n"
+ "# options string: " + copy_options_ + "\n" + "#\n";
}
@@ -2429,6 +2444,7 @@ THRIFT_REGISTER_GENERATOR(
" twisted: Generate Twisted-friendly RPC services.\n"
" tornado: Generate code for use with Tornado.\n"
" utf8strings: Encode/decode strings using utf8 in the generated code.\n"
+ " coding=CODING: Add file encoding declare in generated file.\n"
" slots: Generate code using slots for instance members.\n"
" dynamic: Generate dynamic code, less code generated but slower.\n"
" dynbase=CLS Derive generated classes from class CLS instead of TBase.\n"