You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2015/09/21 22:45:09 UTC
thrift git commit: THRIFT-557 charset problem with file Autogenerated
by Thrift Client: Python Patch: zhenghuabin
Repository: thrift
Updated Branches:
refs/heads/master b92573955 -> 61444d7be
THRIFT-557 charset problem with file Autogenerated by Thrift
Client: Python
Patch: zhenghuabin <zh...@bytedance.com>
This closes #601
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/61444d7b
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/61444d7b
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/61444d7b
Branch: refs/heads/master
Commit: 61444d7be5d5a0949b87d28d6fc3cd87152716cb
Parents: b925739
Author: Jens Geyer <je...@apache.org>
Authored: Mon Sep 21 22:43:28 2015 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Mon Sep 21 22:43:28 2015 +0200
----------------------------------------------------------------------
compiler/cpp/src/generate/t_py_generator.cc | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/61444d7b/compiler/cpp/src/generate/t_py_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_py_generator.cc b/compiler/cpp/src/generate/t_py_generator.cc
index 2002c1e..10b1680 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"