|  | @@ -74,16 +74,18 @@ PythonGrpcGenerator::PythonGrpcGenerator(const GeneratorConfiguration& config)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  PythonGrpcGenerator::~PythonGrpcGenerator() {}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -bool PythonGrpcGenerator::Generate(
 | 
	
		
			
				|  |  | -    const FileDescriptor* file, const grpc::string& parameter,
 | 
	
		
			
				|  |  | -    GeneratorContext* context, grpc::string* error) const {
 | 
	
		
			
				|  |  | +bool PythonGrpcGenerator::Generate(const FileDescriptor* file,
 | 
	
		
			
				|  |  | +                                   const grpc::string& parameter,
 | 
	
		
			
				|  |  | +                                   GeneratorContext* context,
 | 
	
		
			
				|  |  | +                                   grpc::string* error) const {
 | 
	
		
			
				|  |  |    // Get output file name.
 | 
	
		
			
				|  |  |    grpc::string file_name;
 | 
	
		
			
				|  |  |    static const int proto_suffix_length = strlen(".proto");
 | 
	
		
			
				|  |  |    if (file->name().size() > static_cast<size_t>(proto_suffix_length) &&
 | 
	
		
			
				|  |  |        file->name().find_last_of(".proto") == file->name().size() - 1) {
 | 
	
		
			
				|  |  | -    file_name = file->name().substr(
 | 
	
		
			
				|  |  | -        0, file->name().size() - proto_suffix_length) + "_pb2.py";
 | 
	
		
			
				|  |  | +    file_name =
 | 
	
		
			
				|  |  | +        file->name().substr(0, file->name().size() - proto_suffix_length) +
 | 
	
		
			
				|  |  | +        "_pb2.py";
 | 
	
		
			
				|  |  |    } else {
 | 
	
		
			
				|  |  |      *error = "Invalid proto file name. Proto file must end with .proto";
 | 
	
		
			
				|  |  |      return false;
 | 
	
	
		
			
				|  | @@ -115,7 +117,7 @@ map<grpc::string, grpc::string> ListToDict(
 | 
	
		
			
				|  |  |    assert(values.size() % 2 == 0);
 | 
	
		
			
				|  |  |    map<grpc::string, grpc::string> value_map;
 | 
	
		
			
				|  |  |    auto value_iter = values.begin();
 | 
	
		
			
				|  |  | -  for (unsigned i = 0; i < values.size()/2; ++i) {
 | 
	
		
			
				|  |  | +  for (unsigned i = 0; i < values.size() / 2; ++i) {
 | 
	
		
			
				|  |  |      grpc::string key = *value_iter;
 | 
	
		
			
				|  |  |      ++value_iter;
 | 
	
		
			
				|  |  |      grpc::string value = *value_iter;
 | 
	
	
		
			
				|  | @@ -138,9 +140,7 @@ class IndentScope {
 | 
	
		
			
				|  |  |      printer_->Indent();
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  ~IndentScope() {
 | 
	
		
			
				|  |  | -    printer_->Outdent();
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | +  ~IndentScope() { printer_->Outdent(); }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |   private:
 | 
	
		
			
				|  |  |    Printer* printer_;
 | 
	
	
		
			
				|  | @@ -173,7 +173,6 @@ grpc::string ModuleAlias(const grpc::string& filename) {
 | 
	
		
			
				|  |  |    return module_name;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  bool GetModuleAndMessagePath(const Descriptor* type,
 | 
	
		
			
				|  |  |                               const ServiceDescriptor* service,
 | 
	
		
			
				|  |  |                               grpc::string* out) {
 | 
	
	
		
			
				|  | @@ -182,7 +181,7 @@ bool GetModuleAndMessagePath(const Descriptor* type,
 | 
	
		
			
				|  |  |    do {
 | 
	
		
			
				|  |  |      message_path.push_back(path_elem_type);
 | 
	
		
			
				|  |  |      path_elem_type = path_elem_type->containing_type();
 | 
	
		
			
				|  |  | -  } while (path_elem_type); // implicit nullptr comparison; don't be explicit
 | 
	
		
			
				|  |  | +  } while (path_elem_type);  // implicit nullptr comparison; don't be explicit
 | 
	
		
			
				|  |  |    grpc::string file_name = type->file()->name();
 | 
	
		
			
				|  |  |    static const int proto_suffix_length = strlen(".proto");
 | 
	
		
			
				|  |  |    if (!(file_name.size() > static_cast<size_t>(proto_suffix_length) &&
 | 
	
	
		
			
				|  | @@ -190,11 +189,11 @@ bool GetModuleAndMessagePath(const Descriptor* type,
 | 
	
		
			
				|  |  |      return false;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    grpc::string service_file_name = service->file()->name();
 | 
	
		
			
				|  |  | -  grpc::string module = service_file_name == file_name ?
 | 
	
		
			
				|  |  | -          "" : ModuleAlias(file_name) + ".";
 | 
	
		
			
				|  |  | +  grpc::string module =
 | 
	
		
			
				|  |  | +      service_file_name == file_name ? "" : ModuleAlias(file_name) + ".";
 | 
	
		
			
				|  |  |    grpc::string message_type;
 | 
	
		
			
				|  |  | -  for (auto path_iter = message_path.rbegin();
 | 
	
		
			
				|  |  | -       path_iter != message_path.rend(); ++path_iter) {
 | 
	
		
			
				|  |  | +  for (auto path_iter = message_path.rbegin(); path_iter != message_path.rend();
 | 
	
		
			
				|  |  | +       ++path_iter) {
 | 
	
		
			
				|  |  |      message_type += (*path_iter)->name() + ".";
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    // no pop_back prior to C++11
 | 
	
	
		
			
				|  | @@ -229,8 +228,7 @@ static void PrintAllComments(const DescriptorType* desc, Printer* printer) {
 | 
	
		
			
				|  |  |    printer->Print("\"\"\"\n");
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -bool PrintBetaServicer(const ServiceDescriptor* service,
 | 
	
		
			
				|  |  | -                       Printer* out) {
 | 
	
		
			
				|  |  | +bool PrintBetaServicer(const ServiceDescriptor* service, Printer* out) {
 | 
	
		
			
				|  |  |    out->Print("\n\n");
 | 
	
		
			
				|  |  |    out->Print("class Beta$Service$Servicer(object):\n", "Service",
 | 
	
		
			
				|  |  |               service->name());
 | 
	
	
		
			
				|  | @@ -239,10 +237,10 @@ bool PrintBetaServicer(const ServiceDescriptor* service,
 | 
	
		
			
				|  |  |      PrintAllComments(service, out);
 | 
	
		
			
				|  |  |      for (int i = 0; i < service->method_count(); ++i) {
 | 
	
		
			
				|  |  |        auto meth = service->method(i);
 | 
	
		
			
				|  |  | -      grpc::string arg_name = meth->client_streaming() ?
 | 
	
		
			
				|  |  | -          "request_iterator" : "request";
 | 
	
		
			
				|  |  | -      out->Print("def $Method$(self, $ArgName$, context):\n",
 | 
	
		
			
				|  |  | -                 "Method", meth->name(), "ArgName", arg_name);
 | 
	
		
			
				|  |  | +      grpc::string arg_name =
 | 
	
		
			
				|  |  | +          meth->client_streaming() ? "request_iterator" : "request";
 | 
	
		
			
				|  |  | +      out->Print("def $Method$(self, $ArgName$, context):\n", "Method",
 | 
	
		
			
				|  |  | +                 meth->name(), "ArgName", arg_name);
 | 
	
		
			
				|  |  |        {
 | 
	
		
			
				|  |  |          IndentScope raii_method_indent(out);
 | 
	
		
			
				|  |  |          PrintAllComments(meth, out);
 | 
	
	
		
			
				|  | @@ -253,8 +251,7 @@ bool PrintBetaServicer(const ServiceDescriptor* service,
 | 
	
		
			
				|  |  |    return true;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -bool PrintBetaStub(const ServiceDescriptor* service,
 | 
	
		
			
				|  |  | -                   Printer* out) {
 | 
	
		
			
				|  |  | +bool PrintBetaStub(const ServiceDescriptor* service, Printer* out) {
 | 
	
		
			
				|  |  |    out->Print("\n\n");
 | 
	
		
			
				|  |  |    out->Print("class Beta$Service$Stub(object):\n", "Service", service->name());
 | 
	
		
			
				|  |  |    {
 | 
	
	
		
			
				|  | @@ -262,10 +259,12 @@ bool PrintBetaStub(const ServiceDescriptor* service,
 | 
	
		
			
				|  |  |      PrintAllComments(service, out);
 | 
	
		
			
				|  |  |      for (int i = 0; i < service->method_count(); ++i) {
 | 
	
		
			
				|  |  |        const MethodDescriptor* meth = service->method(i);
 | 
	
		
			
				|  |  | -      grpc::string arg_name = meth->client_streaming() ?
 | 
	
		
			
				|  |  | -          "request_iterator" : "request";
 | 
	
		
			
				|  |  | +      grpc::string arg_name =
 | 
	
		
			
				|  |  | +          meth->client_streaming() ? "request_iterator" : "request";
 | 
	
		
			
				|  |  |        auto methdict = ListToDict({"Method", meth->name(), "ArgName", arg_name});
 | 
	
		
			
				|  |  | -      out->Print(methdict, "def $Method$(self, $ArgName$, timeout, metadata=None, with_call=False, protocol_options=None):\n");
 | 
	
		
			
				|  |  | +      out->Print(methdict,
 | 
	
		
			
				|  |  | +                 "def $Method$(self, $ArgName$, timeout, metadata=None, "
 | 
	
		
			
				|  |  | +                 "with_call=False, protocol_options=None):\n");
 | 
	
		
			
				|  |  |        {
 | 
	
		
			
				|  |  |          IndentScope raii_method_indent(out);
 | 
	
		
			
				|  |  |          PrintAllComments(meth, out);
 | 
	
	
		
			
				|  | @@ -282,9 +281,10 @@ bool PrintBetaStub(const ServiceDescriptor* service,
 | 
	
		
			
				|  |  |  bool PrintBetaServerFactory(const grpc::string& package_qualified_service_name,
 | 
	
		
			
				|  |  |                              const ServiceDescriptor* service, Printer* out) {
 | 
	
		
			
				|  |  |    out->Print("\n\n");
 | 
	
		
			
				|  |  | -  out->Print("def beta_create_$Service$_server(servicer, pool=None, "
 | 
	
		
			
				|  |  | -             "pool_size=None, default_timeout=None, maximum_timeout=None):\n",
 | 
	
		
			
				|  |  | -             "Service", service->name());
 | 
	
		
			
				|  |  | +  out->Print(
 | 
	
		
			
				|  |  | +      "def beta_create_$Service$_server(servicer, pool=None, "
 | 
	
		
			
				|  |  | +      "pool_size=None, default_timeout=None, maximum_timeout=None):\n",
 | 
	
		
			
				|  |  | +      "Service", service->name());
 | 
	
		
			
				|  |  |    {
 | 
	
		
			
				|  |  |      IndentScope raii_create_server_indent(out);
 | 
	
		
			
				|  |  |      map<grpc::string, grpc::string> method_implementation_constructors;
 | 
	
	
		
			
				|  | @@ -315,58 +315,62 @@ bool PrintBetaServerFactory(const grpc::string& package_qualified_service_name,
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      out->Print("request_deserializers = {\n");
 | 
	
		
			
				|  |  |      for (auto name_and_input_module_class_pair =
 | 
	
		
			
				|  |  | -           input_message_modules_and_classes.begin();
 | 
	
		
			
				|  |  | +             input_message_modules_and_classes.begin();
 | 
	
		
			
				|  |  |           name_and_input_module_class_pair !=
 | 
	
		
			
				|  |  | -           input_message_modules_and_classes.end();
 | 
	
		
			
				|  |  | +         input_message_modules_and_classes.end();
 | 
	
		
			
				|  |  |           name_and_input_module_class_pair++) {
 | 
	
		
			
				|  |  |        IndentScope raii_indent(out);
 | 
	
		
			
				|  |  | -      out->Print("(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
 | 
	
		
			
				|  |  | -                 "$InputTypeModuleAndClass$.FromString,\n",
 | 
	
		
			
				|  |  | -                 "PackageQualifiedServiceName", package_qualified_service_name,
 | 
	
		
			
				|  |  | -                 "MethodName", name_and_input_module_class_pair->first,
 | 
	
		
			
				|  |  | -                 "InputTypeModuleAndClass",
 | 
	
		
			
				|  |  | -                 name_and_input_module_class_pair->second);
 | 
	
		
			
				|  |  | +      out->Print(
 | 
	
		
			
				|  |  | +          "(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
 | 
	
		
			
				|  |  | +          "$InputTypeModuleAndClass$.FromString,\n",
 | 
	
		
			
				|  |  | +          "PackageQualifiedServiceName", package_qualified_service_name,
 | 
	
		
			
				|  |  | +          "MethodName", name_and_input_module_class_pair->first,
 | 
	
		
			
				|  |  | +          "InputTypeModuleAndClass", name_and_input_module_class_pair->second);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      out->Print("}\n");
 | 
	
		
			
				|  |  |      out->Print("response_serializers = {\n");
 | 
	
		
			
				|  |  |      for (auto name_and_output_module_class_pair =
 | 
	
		
			
				|  |  | -           output_message_modules_and_classes.begin();
 | 
	
		
			
				|  |  | +             output_message_modules_and_classes.begin();
 | 
	
		
			
				|  |  |           name_and_output_module_class_pair !=
 | 
	
		
			
				|  |  | -           output_message_modules_and_classes.end();
 | 
	
		
			
				|  |  | +         output_message_modules_and_classes.end();
 | 
	
		
			
				|  |  |           name_and_output_module_class_pair++) {
 | 
	
		
			
				|  |  |        IndentScope raii_indent(out);
 | 
	
		
			
				|  |  | -      out->Print("(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
 | 
	
		
			
				|  |  | -                 "$OutputTypeModuleAndClass$.SerializeToString,\n",
 | 
	
		
			
				|  |  | -                 "PackageQualifiedServiceName", package_qualified_service_name,
 | 
	
		
			
				|  |  | -                 "MethodName", name_and_output_module_class_pair->first,
 | 
	
		
			
				|  |  | -                 "OutputTypeModuleAndClass",
 | 
	
		
			
				|  |  | -                 name_and_output_module_class_pair->second);
 | 
	
		
			
				|  |  | +      out->Print(
 | 
	
		
			
				|  |  | +          "(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
 | 
	
		
			
				|  |  | +          "$OutputTypeModuleAndClass$.SerializeToString,\n",
 | 
	
		
			
				|  |  | +          "PackageQualifiedServiceName", package_qualified_service_name,
 | 
	
		
			
				|  |  | +          "MethodName", name_and_output_module_class_pair->first,
 | 
	
		
			
				|  |  | +          "OutputTypeModuleAndClass",
 | 
	
		
			
				|  |  | +          name_and_output_module_class_pair->second);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      out->Print("}\n");
 | 
	
		
			
				|  |  |      out->Print("method_implementations = {\n");
 | 
	
		
			
				|  |  |      for (auto name_and_implementation_constructor =
 | 
	
		
			
				|  |  | -           method_implementation_constructors.begin();
 | 
	
		
			
				|  |  | -	 name_and_implementation_constructor !=
 | 
	
		
			
				|  |  | -	   method_implementation_constructors.end();
 | 
	
		
			
				|  |  | -	 name_and_implementation_constructor++) {
 | 
	
		
			
				|  |  | +             method_implementation_constructors.begin();
 | 
	
		
			
				|  |  | +         name_and_implementation_constructor !=
 | 
	
		
			
				|  |  | +         method_implementation_constructors.end();
 | 
	
		
			
				|  |  | +         name_and_implementation_constructor++) {
 | 
	
		
			
				|  |  |        IndentScope raii_descriptions_indent(out);
 | 
	
		
			
				|  |  |        const grpc::string method_name =
 | 
	
		
			
				|  |  |            name_and_implementation_constructor->first;
 | 
	
		
			
				|  |  | -      out->Print("(\'$PackageQualifiedServiceName$\', \'$Method$\'): "
 | 
	
		
			
				|  |  | -                 "face_utilities.$Constructor$(servicer.$Method$),\n",
 | 
	
		
			
				|  |  | -                 "PackageQualifiedServiceName", package_qualified_service_name,
 | 
	
		
			
				|  |  | -                 "Method", name_and_implementation_constructor->first,
 | 
	
		
			
				|  |  | -                 "Constructor", name_and_implementation_constructor->second);
 | 
	
		
			
				|  |  | +      out->Print(
 | 
	
		
			
				|  |  | +          "(\'$PackageQualifiedServiceName$\', \'$Method$\'): "
 | 
	
		
			
				|  |  | +          "face_utilities.$Constructor$(servicer.$Method$),\n",
 | 
	
		
			
				|  |  | +          "PackageQualifiedServiceName", package_qualified_service_name,
 | 
	
		
			
				|  |  | +          "Method", name_and_implementation_constructor->first, "Constructor",
 | 
	
		
			
				|  |  | +          name_and_implementation_constructor->second);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      out->Print("}\n");
 | 
	
		
			
				|  |  | -    out->Print("server_options = beta_implementations.server_options("
 | 
	
		
			
				|  |  | -               "request_deserializers=request_deserializers, "
 | 
	
		
			
				|  |  | -               "response_serializers=response_serializers, "
 | 
	
		
			
				|  |  | -               "thread_pool=pool, thread_pool_size=pool_size, "
 | 
	
		
			
				|  |  | -               "default_timeout=default_timeout, "
 | 
	
		
			
				|  |  | -               "maximum_timeout=maximum_timeout)\n");
 | 
	
		
			
				|  |  | -    out->Print("return beta_implementations.server(method_implementations, "
 | 
	
		
			
				|  |  | -               "options=server_options)\n");
 | 
	
		
			
				|  |  | +    out->Print(
 | 
	
		
			
				|  |  | +        "server_options = beta_implementations.server_options("
 | 
	
		
			
				|  |  | +        "request_deserializers=request_deserializers, "
 | 
	
		
			
				|  |  | +        "response_serializers=response_serializers, "
 | 
	
		
			
				|  |  | +        "thread_pool=pool, thread_pool_size=pool_size, "
 | 
	
		
			
				|  |  | +        "default_timeout=default_timeout, "
 | 
	
		
			
				|  |  | +        "maximum_timeout=maximum_timeout)\n");
 | 
	
		
			
				|  |  | +    out->Print(
 | 
	
		
			
				|  |  | +        "return beta_implementations.server(method_implementations, "
 | 
	
		
			
				|  |  | +        "options=server_options)\n");
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    return true;
 | 
	
		
			
				|  |  |  }
 | 
	
	
		
			
				|  | @@ -374,10 +378,11 @@ bool PrintBetaServerFactory(const grpc::string& package_qualified_service_name,
 | 
	
		
			
				|  |  |  bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name,
 | 
	
		
			
				|  |  |                            const ServiceDescriptor* service, Printer* out) {
 | 
	
		
			
				|  |  |    map<grpc::string, grpc::string> dict = ListToDict({
 | 
	
		
			
				|  |  | -        "Service", service->name(),
 | 
	
		
			
				|  |  | -      });
 | 
	
		
			
				|  |  | +      "Service", service->name(),
 | 
	
		
			
				|  |  | +  });
 | 
	
		
			
				|  |  |    out->Print("\n\n");
 | 
	
		
			
				|  |  | -  out->Print(dict, "def beta_create_$Service$_stub(channel, host=None,"
 | 
	
		
			
				|  |  | +  out->Print(dict,
 | 
	
		
			
				|  |  | +             "def beta_create_$Service$_stub(channel, host=None,"
 | 
	
		
			
				|  |  |               " metadata_transformer=None, pool=None, pool_size=None):\n");
 | 
	
		
			
				|  |  |    {
 | 
	
		
			
				|  |  |      IndentScope raii_create_server_indent(out);
 | 
	
	
		
			
				|  | @@ -387,8 +392,7 @@ bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name,
 | 
	
		
			
				|  |  |      for (int i = 0; i < service->method_count(); ++i) {
 | 
	
		
			
				|  |  |        const MethodDescriptor* method = service->method(i);
 | 
	
		
			
				|  |  |        const grpc::string method_cardinality =
 | 
	
		
			
				|  |  | -          grpc::string(method->client_streaming() ? "STREAM" : "UNARY") +
 | 
	
		
			
				|  |  | -          "_" +
 | 
	
		
			
				|  |  | +          grpc::string(method->client_streaming() ? "STREAM" : "UNARY") + "_" +
 | 
	
		
			
				|  |  |            grpc::string(method->server_streaming() ? "STREAM" : "UNARY");
 | 
	
		
			
				|  |  |        grpc::string input_message_module_and_class;
 | 
	
		
			
				|  |  |        if (!GetModuleAndMessagePath(method->input_type(), service,
 | 
	
	
		
			
				|  | @@ -409,32 +413,33 @@ bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name,
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      out->Print("request_serializers = {\n");
 | 
	
		
			
				|  |  |      for (auto name_and_input_module_class_pair =
 | 
	
		
			
				|  |  | -           input_message_modules_and_classes.begin();
 | 
	
		
			
				|  |  | +             input_message_modules_and_classes.begin();
 | 
	
		
			
				|  |  |           name_and_input_module_class_pair !=
 | 
	
		
			
				|  |  | -           input_message_modules_and_classes.end();
 | 
	
		
			
				|  |  | +         input_message_modules_and_classes.end();
 | 
	
		
			
				|  |  |           name_and_input_module_class_pair++) {
 | 
	
		
			
				|  |  |        IndentScope raii_indent(out);
 | 
	
		
			
				|  |  | -      out->Print("(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
 | 
	
		
			
				|  |  | -                 "$InputTypeModuleAndClass$.SerializeToString,\n",
 | 
	
		
			
				|  |  | -                 "PackageQualifiedServiceName", package_qualified_service_name,
 | 
	
		
			
				|  |  | -                 "MethodName", name_and_input_module_class_pair->first,
 | 
	
		
			
				|  |  | -                 "InputTypeModuleAndClass",
 | 
	
		
			
				|  |  | -                 name_and_input_module_class_pair->second);
 | 
	
		
			
				|  |  | +      out->Print(
 | 
	
		
			
				|  |  | +          "(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
 | 
	
		
			
				|  |  | +          "$InputTypeModuleAndClass$.SerializeToString,\n",
 | 
	
		
			
				|  |  | +          "PackageQualifiedServiceName", package_qualified_service_name,
 | 
	
		
			
				|  |  | +          "MethodName", name_and_input_module_class_pair->first,
 | 
	
		
			
				|  |  | +          "InputTypeModuleAndClass", name_and_input_module_class_pair->second);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      out->Print("}\n");
 | 
	
		
			
				|  |  |      out->Print("response_deserializers = {\n");
 | 
	
		
			
				|  |  |      for (auto name_and_output_module_class_pair =
 | 
	
		
			
				|  |  | -           output_message_modules_and_classes.begin();
 | 
	
		
			
				|  |  | +             output_message_modules_and_classes.begin();
 | 
	
		
			
				|  |  |           name_and_output_module_class_pair !=
 | 
	
		
			
				|  |  | -           output_message_modules_and_classes.end();
 | 
	
		
			
				|  |  | +         output_message_modules_and_classes.end();
 | 
	
		
			
				|  |  |           name_and_output_module_class_pair++) {
 | 
	
		
			
				|  |  |        IndentScope raii_indent(out);
 | 
	
		
			
				|  |  | -      out->Print("(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
 | 
	
		
			
				|  |  | -                 "$OutputTypeModuleAndClass$.FromString,\n",
 | 
	
		
			
				|  |  | -                 "PackageQualifiedServiceName", package_qualified_service_name,
 | 
	
		
			
				|  |  | -                 "MethodName", name_and_output_module_class_pair->first,
 | 
	
		
			
				|  |  | -                 "OutputTypeModuleAndClass",
 | 
	
		
			
				|  |  | -                 name_and_output_module_class_pair->second);
 | 
	
		
			
				|  |  | +      out->Print(
 | 
	
		
			
				|  |  | +          "(\'$PackageQualifiedServiceName$\', \'$MethodName$\'): "
 | 
	
		
			
				|  |  | +          "$OutputTypeModuleAndClass$.FromString,\n",
 | 
	
		
			
				|  |  | +          "PackageQualifiedServiceName", package_qualified_service_name,
 | 
	
		
			
				|  |  | +          "MethodName", name_and_output_module_class_pair->first,
 | 
	
		
			
				|  |  | +          "OutputTypeModuleAndClass",
 | 
	
		
			
				|  |  | +          name_and_output_module_class_pair->second);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      out->Print("}\n");
 | 
	
		
			
				|  |  |      out->Print("cardinalities = {\n");
 | 
	
	
		
			
				|  | @@ -443,17 +448,19 @@ bool PrintBetaStubFactory(const grpc::string& package_qualified_service_name,
 | 
	
		
			
				|  |  |           name_and_cardinality++) {
 | 
	
		
			
				|  |  |        IndentScope raii_descriptions_indent(out);
 | 
	
		
			
				|  |  |        out->Print("\'$Method$\': cardinality.Cardinality.$Cardinality$,\n",
 | 
	
		
			
				|  |  | -                 "Method", name_and_cardinality->first,
 | 
	
		
			
				|  |  | -                 "Cardinality", name_and_cardinality->second);
 | 
	
		
			
				|  |  | +                 "Method", name_and_cardinality->first, "Cardinality",
 | 
	
		
			
				|  |  | +                 name_and_cardinality->second);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      out->Print("}\n");
 | 
	
		
			
				|  |  | -    out->Print("stub_options = beta_implementations.stub_options("
 | 
	
		
			
				|  |  | -               "host=host, metadata_transformer=metadata_transformer, "
 | 
	
		
			
				|  |  | -               "request_serializers=request_serializers, "
 | 
	
		
			
				|  |  | -               "response_deserializers=response_deserializers, "
 | 
	
		
			
				|  |  | -               "thread_pool=pool, thread_pool_size=pool_size)\n");
 | 
	
		
			
				|  |  |      out->Print(
 | 
	
		
			
				|  |  | -        "return beta_implementations.dynamic_stub(channel, \'$PackageQualifiedServiceName$\', "
 | 
	
		
			
				|  |  | +        "stub_options = beta_implementations.stub_options("
 | 
	
		
			
				|  |  | +        "host=host, metadata_transformer=metadata_transformer, "
 | 
	
		
			
				|  |  | +        "request_serializers=request_serializers, "
 | 
	
		
			
				|  |  | +        "response_deserializers=response_deserializers, "
 | 
	
		
			
				|  |  | +        "thread_pool=pool, thread_pool_size=pool_size)\n");
 | 
	
		
			
				|  |  | +    out->Print(
 | 
	
		
			
				|  |  | +        "return beta_implementations.dynamic_stub(channel, "
 | 
	
		
			
				|  |  | +        "\'$PackageQualifiedServiceName$\', "
 | 
	
		
			
				|  |  |          "cardinalities, options=stub_options)\n",
 | 
	
		
			
				|  |  |          "PackageQualifiedServiceName", package_qualified_service_name);
 | 
	
		
			
				|  |  |    }
 | 
	
	
		
			
				|  | @@ -476,43 +483,41 @@ bool PrintStub(const grpc::string& package_qualified_service_name,
 | 
	
		
			
				|  |  |        out->Print("Args:\n");
 | 
	
		
			
				|  |  |        {
 | 
	
		
			
				|  |  |          IndentScope raii_args_indent(out);
 | 
	
		
			
				|  |  | -	out->Print("channel: A grpc.Channel.\n");
 | 
	
		
			
				|  |  | +        out->Print("channel: A grpc.Channel.\n");
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |        out->Print("\"\"\"\n");
 | 
	
		
			
				|  |  |        for (int i = 0; i < service->method_count(); ++i) {
 | 
	
		
			
				|  |  |          auto method = service->method(i);
 | 
	
		
			
				|  |  | -	auto multi_callable_constructor =
 | 
	
		
			
				|  |  | -	    grpc::string(method->client_streaming() ? "stream" : "unary") +
 | 
	
		
			
				|  |  | -	    "_" +
 | 
	
		
			
				|  |  | -	    grpc::string(method->server_streaming() ? "stream" : "unary");
 | 
	
		
			
				|  |  | -	grpc::string request_module_and_class;
 | 
	
		
			
				|  |  | -	if (!GetModuleAndMessagePath(method->input_type(), service,
 | 
	
		
			
				|  |  | -				     &request_module_and_class)) {
 | 
	
		
			
				|  |  | -	  return false;
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	grpc::string response_module_and_class;
 | 
	
		
			
				|  |  | -	if (!GetModuleAndMessagePath(method->output_type(), service,
 | 
	
		
			
				|  |  | -				     &response_module_and_class)) {
 | 
	
		
			
				|  |  | +        auto multi_callable_constructor =
 | 
	
		
			
				|  |  | +            grpc::string(method->client_streaming() ? "stream" : "unary") +
 | 
	
		
			
				|  |  | +            "_" + grpc::string(method->server_streaming() ? "stream" : "unary");
 | 
	
		
			
				|  |  | +        grpc::string request_module_and_class;
 | 
	
		
			
				|  |  | +        if (!GetModuleAndMessagePath(method->input_type(), service,
 | 
	
		
			
				|  |  | +                                     &request_module_and_class)) {
 | 
	
		
			
				|  |  | +          return false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        grpc::string response_module_and_class;
 | 
	
		
			
				|  |  | +        if (!GetModuleAndMessagePath(method->output_type(), service,
 | 
	
		
			
				|  |  | +                                     &response_module_and_class)) {
 | 
	
		
			
				|  |  |            return false;
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	out->Print("self.$Method$ = channel.$MultiCallableConstructor$(\n",
 | 
	
		
			
				|  |  | -		   "Method", method->name(),
 | 
	
		
			
				|  |  | -		   "MultiCallableConstructor", multi_callable_constructor);
 | 
	
		
			
				|  |  | -	{
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        out->Print("self.$Method$ = channel.$MultiCallableConstructor$(\n",
 | 
	
		
			
				|  |  | +                   "Method", method->name(), "MultiCallableConstructor",
 | 
	
		
			
				|  |  | +                   multi_callable_constructor);
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  |            IndentScope raii_first_attribute_indent(out);
 | 
	
		
			
				|  |  |            IndentScope raii_second_attribute_indent(out);
 | 
	
		
			
				|  |  | -	  out->Print(
 | 
	
		
			
				|  |  | -	      "'/$PackageQualifiedService$/$Method$',\n",
 | 
	
		
			
				|  |  | -	      "PackageQualifiedService", package_qualified_service_name,
 | 
	
		
			
				|  |  | -	      "Method", method->name());
 | 
	
		
			
				|  |  | -	  out->Print(
 | 
	
		
			
				|  |  | -	      "request_serializer=$RequestModuleAndClass$.SerializeToString,\n",
 | 
	
		
			
				|  |  | -	      "RequestModuleAndClass", request_module_and_class);
 | 
	
		
			
				|  |  | -	  out->Print(
 | 
	
		
			
				|  |  | +          out->Print("'/$PackageQualifiedService$/$Method$',\n",
 | 
	
		
			
				|  |  | +                     "PackageQualifiedService", package_qualified_service_name,
 | 
	
		
			
				|  |  | +                     "Method", method->name());
 | 
	
		
			
				|  |  | +          out->Print(
 | 
	
		
			
				|  |  | +              "request_serializer=$RequestModuleAndClass$.SerializeToString,\n",
 | 
	
		
			
				|  |  | +              "RequestModuleAndClass", request_module_and_class);
 | 
	
		
			
				|  |  | +          out->Print(
 | 
	
		
			
				|  |  |                "response_deserializer=$ResponseModuleAndClass$.FromString,\n",
 | 
	
		
			
				|  |  | -	      "ResponseModuleAndClass", response_module_and_class);
 | 
	
		
			
				|  |  | -	  out->Print(")\n");
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | +              "ResponseModuleAndClass", response_module_and_class);
 | 
	
		
			
				|  |  | +          out->Print(")\n");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
	
		
			
				|  | @@ -527,11 +532,11 @@ bool PrintServicer(const ServiceDescriptor* service, Printer* out) {
 | 
	
		
			
				|  |  |      PrintAllComments(service, out);
 | 
	
		
			
				|  |  |      for (int i = 0; i < service->method_count(); ++i) {
 | 
	
		
			
				|  |  |        auto method = service->method(i);
 | 
	
		
			
				|  |  | -      grpc::string arg_name = method->client_streaming() ?
 | 
	
		
			
				|  |  | -	  "request_iterator" : "request";
 | 
	
		
			
				|  |  | +      grpc::string arg_name =
 | 
	
		
			
				|  |  | +          method->client_streaming() ? "request_iterator" : "request";
 | 
	
		
			
				|  |  |        out->Print("\n");
 | 
	
		
			
				|  |  | -      out->Print("def $Method$(self, $ArgName$, context):\n",
 | 
	
		
			
				|  |  | -                 "Method", method->name(), "ArgName", arg_name);
 | 
	
		
			
				|  |  | +      out->Print("def $Method$(self, $ArgName$, context):\n", "Method",
 | 
	
		
			
				|  |  | +                 method->name(), "ArgName", arg_name);
 | 
	
		
			
				|  |  |        {
 | 
	
		
			
				|  |  |          IndentScope raii_method_indent(out);
 | 
	
		
			
				|  |  |          PrintAllComments(method, out);
 | 
	
	
		
			
				|  | @@ -544,11 +549,12 @@ bool PrintServicer(const ServiceDescriptor* service, Printer* out) {
 | 
	
		
			
				|  |  |    return true;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -bool PrintAddServicerToServer(const grpc::string& package_qualified_service_name,
 | 
	
		
			
				|  |  | -			      const ServiceDescriptor* service, Printer* out) {
 | 
	
		
			
				|  |  | +bool PrintAddServicerToServer(
 | 
	
		
			
				|  |  | +    const grpc::string& package_qualified_service_name,
 | 
	
		
			
				|  |  | +    const ServiceDescriptor* service, Printer* out) {
 | 
	
		
			
				|  |  |    out->Print("\n\n");
 | 
	
		
			
				|  |  |    out->Print("def add_$Service$Servicer_to_server(servicer, server):\n",
 | 
	
		
			
				|  |  | -	     "Service", service->name());
 | 
	
		
			
				|  |  | +             "Service", service->name());
 | 
	
		
			
				|  |  |    {
 | 
	
		
			
				|  |  |      IndentScope raii_class_indent(out);
 | 
	
		
			
				|  |  |      out->Print("rpc_method_handlers = {\n");
 | 
	
	
		
			
				|  | @@ -557,34 +563,37 @@ bool PrintAddServicerToServer(const grpc::string& package_qualified_service_name
 | 
	
		
			
				|  |  |        IndentScope raii_dict_second_indent(out);
 | 
	
		
			
				|  |  |        for (int i = 0; i < service->method_count(); ++i) {
 | 
	
		
			
				|  |  |          auto method = service->method(i);
 | 
	
		
			
				|  |  | -	auto method_handler_constructor =
 | 
	
		
			
				|  |  | +        auto method_handler_constructor =
 | 
	
		
			
				|  |  |              grpc::string(method->client_streaming() ? "stream" : "unary") +
 | 
	
		
			
				|  |  | -	    "_" +
 | 
	
		
			
				|  |  | +            "_" +
 | 
	
		
			
				|  |  |              grpc::string(method->server_streaming() ? "stream" : "unary") +
 | 
	
		
			
				|  |  |              "_rpc_method_handler";
 | 
	
		
			
				|  |  | -	grpc::string request_module_and_class;
 | 
	
		
			
				|  |  | -	if (!GetModuleAndMessagePath(method->input_type(), service,
 | 
	
		
			
				|  |  | -				     &request_module_and_class)) {
 | 
	
		
			
				|  |  | -	  return false;
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	grpc::string response_module_and_class;
 | 
	
		
			
				|  |  | -	if (!GetModuleAndMessagePath(method->output_type(), service,
 | 
	
		
			
				|  |  | -				     &response_module_and_class)) {
 | 
	
		
			
				|  |  | +        grpc::string request_module_and_class;
 | 
	
		
			
				|  |  | +        if (!GetModuleAndMessagePath(method->input_type(), service,
 | 
	
		
			
				|  |  | +                                     &request_module_and_class)) {
 | 
	
		
			
				|  |  |            return false;
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -        out->Print("'$Method$': grpc.$MethodHandlerConstructor$(\n",
 | 
	
		
			
				|  |  | -		   "Method", method->name(),
 | 
	
		
			
				|  |  | -		   "MethodHandlerConstructor", method_handler_constructor);
 | 
	
		
			
				|  |  | -	{
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        grpc::string response_module_and_class;
 | 
	
		
			
				|  |  | +        if (!GetModuleAndMessagePath(method->output_type(), service,
 | 
	
		
			
				|  |  | +                                     &response_module_and_class)) {
 | 
	
		
			
				|  |  | +          return false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        out->Print("'$Method$': grpc.$MethodHandlerConstructor$(\n", "Method",
 | 
	
		
			
				|  |  | +                   method->name(), "MethodHandlerConstructor",
 | 
	
		
			
				|  |  | +                   method_handler_constructor);
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  |            IndentScope raii_call_first_indent(out);
 | 
	
		
			
				|  |  | -	  IndentScope raii_call_second_indent(out);
 | 
	
		
			
				|  |  | -	  out->Print("servicer.$Method$,\n", "Method", method->name());
 | 
	
		
			
				|  |  | -	  out->Print("request_deserializer=$RequestModuleAndClass$.FromString,\n",
 | 
	
		
			
				|  |  | -		     "RequestModuleAndClass", request_module_and_class);
 | 
	
		
			
				|  |  | -	  out->Print("response_serializer=$ResponseModuleAndClass$.SerializeToString,\n",
 | 
	
		
			
				|  |  | -		     "ResponseModuleAndClass", response_module_and_class);
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	out->Print("),\n");
 | 
	
		
			
				|  |  | +          IndentScope raii_call_second_indent(out);
 | 
	
		
			
				|  |  | +          out->Print("servicer.$Method$,\n", "Method", method->name());
 | 
	
		
			
				|  |  | +          out->Print(
 | 
	
		
			
				|  |  | +              "request_deserializer=$RequestModuleAndClass$.FromString,\n",
 | 
	
		
			
				|  |  | +              "RequestModuleAndClass", request_module_and_class);
 | 
	
		
			
				|  |  | +          out->Print(
 | 
	
		
			
				|  |  | +              "response_serializer=$ResponseModuleAndClass$.SerializeToString,"
 | 
	
		
			
				|  |  | +              "\n",
 | 
	
		
			
				|  |  | +              "ResponseModuleAndClass", response_module_and_class);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        out->Print("),\n");
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      out->Print("}\n");
 | 
	
	
		
			
				|  | @@ -593,7 +602,7 @@ bool PrintAddServicerToServer(const grpc::string& package_qualified_service_name
 | 
	
		
			
				|  |  |        IndentScope raii_call_first_indent(out);
 | 
	
		
			
				|  |  |        IndentScope raii_call_second_indent(out);
 | 
	
		
			
				|  |  |        out->Print("'$PackageQualifiedServiceName$', rpc_method_handlers)\n",
 | 
	
		
			
				|  |  | -		 "PackageQualifiedServiceName", package_qualified_service_name);
 | 
	
		
			
				|  |  | +                 "PackageQualifiedServiceName", package_qualified_service_name);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      out->Print("server.add_generic_rpc_handlers((generic_handler,))\n");
 | 
	
		
			
				|  |  |    }
 | 
	
	
		
			
				|  | @@ -605,10 +614,12 @@ bool PrintPreamble(const FileDescriptor* file,
 | 
	
		
			
				|  |  |    out->Print("import $Package$\n", "Package", config.grpc_package_root);
 | 
	
		
			
				|  |  |    out->Print("from $Package$ import implementations as beta_implementations\n",
 | 
	
		
			
				|  |  |               "Package", config.beta_package_root);
 | 
	
		
			
				|  |  | -  out->Print("from $Package$ import interfaces as beta_interfaces\n",
 | 
	
		
			
				|  |  | -             "Package", config.beta_package_root);
 | 
	
		
			
				|  |  | +  out->Print("from $Package$ import interfaces as beta_interfaces\n", "Package",
 | 
	
		
			
				|  |  | +             config.beta_package_root);
 | 
	
		
			
				|  |  |    out->Print("from grpc.framework.common import cardinality\n");
 | 
	
		
			
				|  |  | -  out->Print("from grpc.framework.interfaces.face import utilities as face_utilities\n");
 | 
	
		
			
				|  |  | +  out->Print(
 | 
	
		
			
				|  |  | +      "from grpc.framework.interfaces.face import utilities as "
 | 
	
		
			
				|  |  | +      "face_utilities\n");
 | 
	
		
			
				|  |  |    return true;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -632,12 +643,14 @@ pair<bool, grpc::string> GetServices(const FileDescriptor* file,
 | 
	
		
			
				|  |  |        auto service = file->service(i);
 | 
	
		
			
				|  |  |        auto package_qualified_service_name = package + service->name();
 | 
	
		
			
				|  |  |        if (!(PrintStub(package_qualified_service_name, service, &out) &&
 | 
	
		
			
				|  |  | -	    PrintServicer(service, &out) &&
 | 
	
		
			
				|  |  | -	    PrintAddServicerToServer(package_qualified_service_name, service, &out) &&
 | 
	
		
			
				|  |  | -	    PrintBetaServicer(service, &out) &&
 | 
	
		
			
				|  |  | -            PrintBetaStub(service, &out) &&
 | 
	
		
			
				|  |  | -            PrintBetaServerFactory(package_qualified_service_name, service, &out) &&
 | 
	
		
			
				|  |  | -            PrintBetaStubFactory(package_qualified_service_name, service, &out))) {
 | 
	
		
			
				|  |  | +            PrintServicer(service, &out) &&
 | 
	
		
			
				|  |  | +            PrintAddServicerToServer(package_qualified_service_name, service,
 | 
	
		
			
				|  |  | +                                     &out) &&
 | 
	
		
			
				|  |  | +            PrintBetaServicer(service, &out) && PrintBetaStub(service, &out) &&
 | 
	
		
			
				|  |  | +            PrintBetaServerFactory(package_qualified_service_name, service,
 | 
	
		
			
				|  |  | +                                   &out) &&
 | 
	
		
			
				|  |  | +            PrintBetaStubFactory(package_qualified_service_name, service,
 | 
	
		
			
				|  |  | +                                 &out))) {
 | 
	
		
			
				|  |  |          return make_pair(false, "");
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 |