aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/python
diff options
context:
space:
mode:
authorGravatar Jie Luo <jieluo@google.com>2017-01-30 15:23:35 -0800
committerGravatar Jie Luo <jieluo@google.com>2017-02-09 11:08:10 -0800
commit42e1e2abef8c49efffaa55c645b04bb7e4184cc8 (patch)
tree5d86f24ec8118f36867ef65850a30984a2db1374 /src/google/protobuf/compiler/python
parentccb76fff445862ac11bf7980818d587030f1c7d9 (diff)
Fix python compatibility test when a new generated code imports an old version(2.6.1 or older) generated code.
Diffstat (limited to 'src/google/protobuf/compiler/python')
-rw-r--r--src/google/protobuf/compiler/python/python_generator.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc
index f5769128..f83f155a 100644
--- a/src/google/protobuf/compiler/python/python_generator.cc
+++ b/src/google/protobuf/compiler/python/python_generator.cc
@@ -1380,8 +1380,17 @@ void Generator::FixOptionsForMessage(const Descriptor& descriptor) const {
void Generator::CopyPublicDependenciesAliases(
const string& copy_from, const FileDescriptor* file) const {
for (int i = 0; i < file->public_dependency_count(); ++i) {
+ string module_name = ModuleName(file->public_dependency(i)->name());
string module_alias = ModuleAlias(file->public_dependency(i)->name());
- printer_->Print("$alias$ = $copy_from$.$alias$\n", "alias", module_alias,
+ // There's no module alias in the dependent file if it was generated by
+ // an old protoc (less than 3.0.0-alpha-1). Use module name in this
+ // situation.
+ printer_->Print("try:\n"
+ " $alias$ = $copy_from$.$alias$\n"
+ "except AttributeError:\n"
+ " $alias$ = $copy_from$.$module$\n",
+ "alias", module_alias,
+ "module", module_name,
"copy_from", copy_from);
CopyPublicDependenciesAliases(copy_from, file->public_dependency(i));
}