diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index fca94a31fc..b30d1972fa 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -581,17 +581,14 @@ void Generator::PrintServiceDescriptor( } -void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor) const { - printer_->Indent(); +void Generator::PrintDescriptorKeyAndModuleName(const ServiceDescriptor& descriptor) const { printer_->Print( "$descriptor_key$ = $descriptor_name$,\n", "descriptor_key", kDescriptorKey, "descriptor_name", ModuleLevelServiceDescriptorName(descriptor)); printer_->Print( "__module__ = '$module_name$'\n", - "module_name", ModuleName(file_->name())); - printer_->Print("))\n\n"); - printer_->Outdent(); + "module_name", ModuleName(file_->name())); } void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const { @@ -599,7 +596,10 @@ void Generator::PrintServiceClass(const ServiceDescriptor& descriptor) const { printer_->Print("$class_name$ = service_reflection.GeneratedServiceType(" "'$class_name$', (_service.Service,), dict(\n", "class_name", descriptor.name()); + printer_->Indent(); Generator::PrintDescriptorKeyAndModuleName(descriptor); + printer_->Print("))\n\n"); + printer_->Outdent(); } void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const { @@ -608,7 +608,10 @@ void Generator::PrintServiceStub(const ServiceDescriptor& descriptor) const { "service_reflection.GeneratedServiceStubType(" "'$class_name$_Stub', ($class_name$,), dict(\n", "class_name", descriptor.name()); + printer_->Indent(); Generator::PrintDescriptorKeyAndModuleName(descriptor); + printer_->Print("))\n\n"); + printer_->Outdent(); } // Prints statement assigning ModuleLevelDescriptorName(message_descriptor)