本文整理汇总了Python中google.protobuf.descriptor_pb2.ServiceDescriptorProto方法的典型用法代码示例。如果您正苦于以下问题:Python descriptor_pb2.ServiceDescriptorProto方法的具体用法?Python descriptor_pb2.ServiceDescriptorProto怎么用?Python descriptor_pb2.ServiceDescriptorProto使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.protobuf.descriptor_pb2
的用法示例。
在下文中一共展示了descriptor_pb2.ServiceDescriptorProto方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCopyToProto_ServiceDescriptor
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def testCopyToProto_ServiceDescriptor(self):
TEST_SERVICE_ASCII = """
name: 'TestService'
method: <
name: 'Foo'
input_type: '.protobuf_unittest.FooRequest'
output_type: '.protobuf_unittest.FooResponse'
>
method: <
name: 'Bar'
input_type: '.protobuf_unittest.BarRequest'
output_type: '.protobuf_unittest.BarResponse'
>
"""
self._InternalTestCopyToProto(
unittest_pb2.TestService.DESCRIPTOR,
descriptor_pb2.ServiceDescriptorProto,
TEST_SERVICE_ASCII)
示例2: testCopyToProto_ServiceDescriptor
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def testCopyToProto_ServiceDescriptor(self):
TEST_SERVICE_ASCII = """
name: 'TestService'
method: <
name: 'Foo'
input_type: '.protobuf_unittest.FooRequest'
output_type: '.protobuf_unittest.FooResponse'
>
method: <
name: 'Bar'
input_type: '.protobuf_unittest.BarRequest'
output_type: '.protobuf_unittest.BarResponse'
>
"""
# TODO(rocking): enable this test after the proto descriptor change is
# checked in.
#self._InternalTestCopyToProto(
# unittest_pb2.TestService.DESCRIPTOR,
# descriptor_pb2.ServiceDescriptorProto,
# TEST_SERVICE_ASCII)
示例3: write_services
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def write_services(self, services):
# type: (Iterable[d.ServiceDescriptorProto]) -> None
l = self._write_line
for service in [s for s in services if s.name not in PYTHON_RESERVED]:
# The service definition interface
l(
"class {}({}, metaclass={}):",
service.name,
self._import("google.protobuf.service", "Service"),
self._import("abc", "ABCMeta"),
)
with self._indent():
self.write_methods(service, is_abstract=True)
# The stub client
l("class {}({}):", service.name + "_Stub", service.name)
with self._indent():
l(
"def __init__(self, rpc_channel: {}) -> None: ...",
self._import("google.protobuf.service", "RpcChannel"),
)
self.write_methods(service, is_abstract=False)
示例4: testCopyToProto_ServiceDescriptor
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def testCopyToProto_ServiceDescriptor(self):
TEST_SERVICE_ASCII = """
name: 'TestService'
method: <
name: 'Foo'
input_type: '.protobuf_unittest.FooRequest'
output_type: '.protobuf_unittest.FooResponse'
>
method: <
name: 'Bar'
input_type: '.protobuf_unittest.BarRequest'
output_type: '.protobuf_unittest.BarResponse'
>
"""
self._InternalTestCopyToProto(
unittest_pb2.TestService.DESCRIPTOR,
descriptor_pb2.ServiceDescriptorProto,
TEST_SERVICE_ASCII)
示例5: make_service
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def make_service(name: str = 'Placeholder', host: str = '',
methods: typing.Tuple[wrappers.Method] = (),
scopes: typing.Tuple[str] = ()) -> wrappers.Service:
# Define a service descriptor, and set a host and oauth scopes if
# appropriate.
service_pb = desc.ServiceDescriptorProto(name=name)
if host:
service_pb.options.Extensions[client_pb2.default_host] = host
service_pb.options.Extensions[client_pb2.oauth_scopes] = ','.join(scopes)
# Return a service object to test.
return wrappers.Service(
service_pb=service_pb,
methods={m.name: m for m in methods},
)
# FIXME (lukesneeringer): This test method is convoluted and it makes these
# tests difficult to understand and maintain.
示例6: _load_service
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def _load_service(self,
service: descriptor_pb2.ServiceDescriptorProto,
address: metadata.Address,
path: Tuple[int],
) -> wrappers.Service:
"""Load comments for a service and its methods."""
address = address.child(service.name, path)
# Put together a dictionary of the service's methods.
methods = self._get_methods(
service.method,
service_address=address,
path=path + (2,),
)
# Load the comments for the service itself.
self.proto_services[address.proto] = wrappers.Service(
meta=metadata.Metadata(
address=address,
documentation=self.docs.get(path, self.EMPTY),
),
methods=methods,
service_pb=service,
)
return self.proto_services[address.proto]
示例7: test_get_filename_with_service
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def test_get_filename_with_service():
g = make_generator()
template_name = "%name/%service/foo.py.j2"
assert (
g._get_filename(
template_name,
api_schema=make_api(
naming=make_naming(namespace=(), name="Spam", version="v2"),
),
context={
"service": wrappers.Service(
methods=[],
service_pb=descriptor_pb2.ServiceDescriptorProto(
name="Eggs"),
),
},
)
== "spam/eggs/foo.py"
)
示例8: _MakeServiceDescriptor
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def _MakeServiceDescriptor(self, service_proto, service_index, scope,
package, file_desc):
"""Make a protobuf ServiceDescriptor given a ServiceDescriptorProto.
Args:
service_proto: The descriptor_pb2.ServiceDescriptorProto protobuf message.
service_index: The index of the service in the File.
scope: Dict mapping short and full symbols to message and enum types.
package: Optional package name for the new message EnumDescriptor.
file_desc: The file containing the service descriptor.
Returns:
The added descriptor.
"""
if package:
service_name = '.'.join((package, service_proto.name))
else:
service_name = service_proto.name
methods = [self._MakeMethodDescriptor(method_proto, service_name, package,
scope, index)
for index, method_proto in enumerate(service_proto.method)]
desc = descriptor.ServiceDescriptor(name=service_proto.name,
full_name=service_name,
index=service_index,
methods=methods,
options=_OptionsOrNone(service_proto),
file=file_desc)
self._CheckConflictRegister(desc)
self._service_descriptors[service_name] = desc
return desc
示例9: _MakeServiceDescriptor
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def _MakeServiceDescriptor(self, service_proto, service_index, scope,
package, file_desc):
"""Make a protobuf ServiceDescriptor given a ServiceDescriptorProto.
Args:
service_proto: The descriptor_pb2.ServiceDescriptorProto protobuf message.
service_index: The index of the service in the File.
scope: Dict mapping short and full symbols to message and enum types.
package: Optional package name for the new message EnumDescriptor.
file_desc: The file containing the service descriptor.
Returns:
The added descriptor.
"""
if package:
service_name = '.'.join((package, service_proto.name))
else:
service_name = service_proto.name
methods = [self._MakeMethodDescriptor(method_proto, service_name, package,
scope, index)
for index, method_proto in enumerate(service_proto.method)]
desc = descriptor.ServiceDescriptor(name=service_proto.name,
full_name=service_name,
index=service_index,
methods=methods,
options=_OptionsOrNone(service_proto),
file=file_desc)
return desc
示例10: convert_protodef_to_editable
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def convert_protodef_to_editable(proto):
"""
Protobuf objects can't have arbitrary fields addedd and we need to later on
add comments to them, so we instead make "Editable" objects that can do so
"""
class Editable(object):
def __init__(self, prot):
self.kind = type(prot)
self.name = prot.name
self.comment = ""
self.options = dict([(key.name, value) for (key, value) in prot.options.ListFields()])
if isinstance(prot, EnumDescriptorProto):
self.value = [convert_protodef_to_editable(x) for x in prot.value]
elif isinstance(prot, DescriptorProto):
self.field = [convert_protodef_to_editable(x) for x in prot.field]
self.enum_type = [convert_protodef_to_editable(x) for x in prot.enum_type]
self.nested_type = prot.nested_type
self.oneof_decl = prot.oneof_decl
elif isinstance(prot, EnumValueDescriptorProto):
self.number = prot.number
elif isinstance(prot, FieldDescriptorProto):
if prot.type in [11, 14]:
self.ref_type = prot.type_name[1:]
self.type = prot.type
self.label = prot.label
elif isinstance(prot, ServiceDescriptorProto):
self.method = [convert_protodef_to_editable(x) for x in prot.method]
elif isinstance(prot, MethodDescriptorProto):
self.input_type = prot.input_type
self.output_type = prot.output_type
else:
raise Exception, type(prot)
return Editable(proto)
示例11: write_methods
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def write_methods(self, service, is_abstract):
# type: (d.ServiceDescriptorProto, bool) -> None
l = self._write_line
methods = [m for m in service.method if m.name not in PYTHON_RESERVED]
if not methods:
l("pass")
for method in methods:
if is_abstract:
l("@{}", self._import("abc", "abstractmethod"))
l("def {}(self,", method.name)
with self._indent():
l(
"rpc_controller: {},",
self._import("google.protobuf.service", "RpcController"),
)
l("request: {},", self._import_message(method.input_type))
l(
"done: {}[{}[[{}], None]],",
self._import("typing", "Optional"),
self._import("typing", "Callable"),
self._import_message(method.output_type),
)
l(
") -> {}[{}]: ...",
self._import("concurrent.futures", "Future"),
self._import_message(method.output_type),
)
示例12: _MakeServiceDescriptor
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def _MakeServiceDescriptor(self, service_proto, service_index, scope,
package, file_desc):
"""Make a protobuf ServiceDescriptor given a ServiceDescriptorProto.
Args:
service_proto: The descriptor_pb2.ServiceDescriptorProto protobuf message.
service_index: The index of the service in the File.
scope: Dict mapping short and full symbols to message and enum types.
package: Optional package name for the new message EnumDescriptor.
file_desc: The file containing the service descriptor.
Returns:
The added descriptor.
"""
if package:
service_name = '.'.join((package, service_proto.name))
else:
service_name = service_proto.name
methods = [self._MakeMethodDescriptor(method_proto, service_name, package,
scope, index)
for index, method_proto in enumerate(service_proto.method)]
desc = descriptor.ServiceDescriptor(name=service_proto.name,
full_name=service_name,
index=service_index,
methods=methods,
options=_OptionsOrNone(service_proto),
file=file_desc)
self._service_descriptors[service_name] = desc
return desc
示例13: CopyToProto
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def CopyToProto(self, proto):
"""Copies this to a descriptor_pb2.ServiceDescriptorProto.
Args:
proto (descriptor_pb2.ServiceDescriptorProto): An empty descriptor proto.
"""
# This function is overridden to give a better doc comment.
super(ServiceDescriptor, self).CopyToProto(proto)
示例14: _MakeServiceDescriptor
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def _MakeServiceDescriptor(self, service_proto, service_index, scope,
package, file_desc):
"""Make a protobuf ServiceDescriptor given a ServiceDescriptorProto.
Args:
service_proto: The descriptor_pb2.ServiceDescriptorProto protobuf message.
service_index: The index of the service in the File.
scope: Dict mapping short and full symbols to message and enum types.
package: Optional package name for the new message EnumDescriptor.
file_desc: The file containing the service descriptor.
Returns:
The added descriptor.
"""
if package:
service_name = '.'.join((package, service_proto.name))
else:
service_name = service_proto.name
methods = [self._MakeMethodDescriptor(method_proto, service_name, package,
scope, index)
for index, method_proto in enumerate(service_proto.method)]
desc = descriptor.ServiceDescriptor(
name=service_proto.name,
full_name=service_name,
index=service_index,
methods=methods,
options=_OptionsOrNone(service_proto),
file=file_desc,
# pylint: disable=protected-access
create_key=descriptor._internal_create_key)
self._CheckConflictRegister(desc, desc.full_name, desc.file.name)
self._service_descriptors[service_name] = desc
return desc
示例15: make_service_with_method_options
# 需要导入模块: from google.protobuf import descriptor_pb2 [as 别名]
# 或者: from google.protobuf.descriptor_pb2 import ServiceDescriptorProto [as 别名]
def make_service_with_method_options(
*,
http_rule: http_pb2.HttpRule = None,
method_signature: str = '',
in_fields: typing.Tuple[desc.FieldDescriptorProto] = ()
) -> wrappers.Service:
# Declare a method with options enabled for long-running operations and
# field headers.
method = get_method(
'DoBigThing',
'foo.bar.ThingRequest',
'google.longrunning.operations_pb2.Operation',
lro_response_type='foo.baz.ThingResponse',
lro_metadata_type='foo.qux.ThingMetadata',
in_fields=in_fields,
http_rule=http_rule,
method_signature=method_signature,
)
# Define a service descriptor.
service_pb = desc.ServiceDescriptorProto(name='ThingDoer')
# Return a service object to test.
return wrappers.Service(
service_pb=service_pb,
methods={method.name: method},
)