aboutsummaryrefslogtreecommitdiff
path: root/src/google
diff options
context:
space:
mode:
authorJie Luo <anandolee@gmail.com>2017-02-09 16:32:08 -0800
committerGitHub <noreply@github.com>2017-02-09 16:32:08 -0800
commitc6e0d0e7f3dca63c006edae515dfca2a89b9c1e4 (patch)
tree05b13c1c646b3c69bae99664fedec64557538566 /src/google
parente844510f442119cc0c9b3d3ebbf06a542d7d18eb (diff)
parent42e1e2abef8c49efffaa55c645b04bb7e4184cc8 (diff)
downloadprotobuf-c6e0d0e7f3dca63c006edae515dfca2a89b9c1e4.tar.gz
protobuf-c6e0d0e7f3dca63c006edae515dfca2a89b9c1e4.tar.bz2
protobuf-c6e0d0e7f3dca63c006edae515dfca2a89b9c1e4.zip
Merge pull request #2647 from anandolee/master
Fix python compatibility test
Diffstat (limited to 'src/google')
-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));
}