Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: recipe_engine/third_party/google/protobuf/descriptor.py

Issue 2236673002: Bump vendoring, move to proto3 release. (Closed) Base URL: https://github.com/luci/recipes-py@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Protocol Buffers - Google's data interchange format 1 # Protocol Buffers - Google's data interchange format
2 # Copyright 2008 Google Inc. All rights reserved. 2 # Copyright 2008 Google Inc. All rights reserved.
3 # https://developers.google.com/protocol-buffers/ 3 # https://developers.google.com/protocol-buffers/
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are 6 # modification, are permitted provided that the following conditions are
7 # met: 7 # met:
8 # 8 #
9 # * Redistributions of source code must retain the above copyright 9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer. 10 # notice, this list of conditions and the following disclaimer.
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 251
252 file: (FileDescriptor) Reference to file descriptor. 252 file: (FileDescriptor) Reference to file descriptor.
253 """ 253 """
254 254
255 if _USE_C_DESCRIPTORS: 255 if _USE_C_DESCRIPTORS:
256 _C_DESCRIPTOR_CLASS = _message.Descriptor 256 _C_DESCRIPTOR_CLASS = _message.Descriptor
257 257
258 def __new__(cls, name, full_name, filename, containing_type, fields, 258 def __new__(cls, name, full_name, filename, containing_type, fields,
259 nested_types, enum_types, extensions, options=None, 259 nested_types, enum_types, extensions, options=None,
260 is_extendable=True, extension_ranges=None, oneofs=None, 260 is_extendable=True, extension_ranges=None, oneofs=None,
261 file=None, serialized_start=None, serialized_end=None, 261 file=None, serialized_start=None, serialized_end=None, # pylint : disable=redefined-builtin
262 syntax=None): 262 syntax=None):
263 _message.Message._CheckCalledFromGeneratedFile() 263 _message.Message._CheckCalledFromGeneratedFile()
264 return _message.default_pool.FindMessageTypeByName(full_name) 264 return _message.default_pool.FindMessageTypeByName(full_name)
265 265
266 # NOTE(tmarek): The file argument redefining a builtin is nothing we can 266 # NOTE(tmarek): The file argument redefining a builtin is nothing we can
267 # fix right now since we don't know how many clients already rely on the 267 # fix right now since we don't know how many clients already rely on the
268 # name of the argument. 268 # name of the argument.
269 def __init__(self, name, full_name, filename, containing_type, fields, 269 def __init__(self, name, full_name, filename, containing_type, fields,
270 nested_types, enum_types, extensions, options=None, 270 nested_types, enum_types, extensions, options=None,
271 is_extendable=True, extension_ranges=None, oneofs=None, 271 is_extendable=True, extension_ranges=None, oneofs=None,
272 file=None, serialized_start=None, serialized_end=None, 272 file=None, serialized_start=None, serialized_end=None, # pylint: disable=redefined-builtin
273 syntax=None): # pylint:disable=redefined-builtin 273 syntax=None):
274 """Arguments to __init__() are as described in the description 274 """Arguments to __init__() are as described in the description
275 of Descriptor fields above. 275 of Descriptor fields above.
276 276
277 Note that filename is an obsolete argument, that is not used anymore. 277 Note that filename is an obsolete argument, that is not used anymore.
278 Please use file.name to access this as an attribute. 278 Please use file.name to access this as an attribute.
279 """ 279 """
280 super(Descriptor, self).__init__( 280 super(Descriptor, self).__init__(
281 options, 'MessageOptions', name, full_name, file, 281 options, 'MessageOptions', name, full_name, file,
282 containing_type, serialized_start=serialized_start, 282 containing_type, serialized_start=serialized_start,
283 serialized_end=serialized_end) 283 serialized_end=serialized_end)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 value for the enum. 342 value for the enum.
343 """ 343 """
344 return self.enum_types_by_name[enum].values_by_number[value].name 344 return self.enum_types_by_name[enum].values_by_number[value].name
345 345
346 def CopyToProto(self, proto): 346 def CopyToProto(self, proto):
347 """Copies this to a descriptor_pb2.DescriptorProto. 347 """Copies this to a descriptor_pb2.DescriptorProto.
348 348
349 Args: 349 Args:
350 proto: An empty descriptor_pb2.DescriptorProto. 350 proto: An empty descriptor_pb2.DescriptorProto.
351 """ 351 """
352 # This function is overriden to give a better doc comment. 352 # This function is overridden to give a better doc comment.
353 super(Descriptor, self).CopyToProto(proto) 353 super(Descriptor, self).CopyToProto(proto)
354 354
355 355
356 # TODO(robinson): We should have aggressive checking here, 356 # TODO(robinson): We should have aggressive checking here,
357 # for example: 357 # for example:
358 # * If you specify a repeated field, you should not be allowed 358 # * If you specify a repeated field, you should not be allowed
359 # to specify a default value. 359 # to specify a default value.
360 # * [Other examples here as needed]. 360 # * [Other examples here as needed].
361 # 361 #
362 # TODO(robinson): for this and other *Descriptor classes, we 362 # TODO(robinson): for this and other *Descriptor classes, we
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 value.type = self 619 value.type = self
620 self.values_by_name = dict((v.name, v) for v in values) 620 self.values_by_name = dict((v.name, v) for v in values)
621 self.values_by_number = dict((v.number, v) for v in values) 621 self.values_by_number = dict((v.number, v) for v in values)
622 622
623 def CopyToProto(self, proto): 623 def CopyToProto(self, proto):
624 """Copies this to a descriptor_pb2.EnumDescriptorProto. 624 """Copies this to a descriptor_pb2.EnumDescriptorProto.
625 625
626 Args: 626 Args:
627 proto: An empty descriptor_pb2.EnumDescriptorProto. 627 proto: An empty descriptor_pb2.EnumDescriptorProto.
628 """ 628 """
629 # This function is overriden to give a better doc comment. 629 # This function is overridden to give a better doc comment.
630 super(EnumDescriptor, self).CopyToProto(proto) 630 super(EnumDescriptor, self).CopyToProto(proto)
631 631
632 632
633 class EnumValueDescriptor(DescriptorBase): 633 class EnumValueDescriptor(DescriptorBase):
634 634
635 """Descriptor for a single value within an enum. 635 """Descriptor for a single value within an enum.
636 636
637 name: (str) Name of this value. 637 name: (str) Name of this value.
638 index: (int) Dense, 0-indexed index giving the order that this 638 index: (int) Dense, 0-indexed index giving the order that this
639 value appears textually within its enum in the .proto file. 639 value appears textually within its enum in the .proto file.
(...skipping 18 matching lines...) Expand all
658 658
659 def __init__(self, name, index, number, type=None, options=None): 659 def __init__(self, name, index, number, type=None, options=None):
660 """Arguments are as described in the attribute description above.""" 660 """Arguments are as described in the attribute description above."""
661 super(EnumValueDescriptor, self).__init__(options, 'EnumValueOptions') 661 super(EnumValueDescriptor, self).__init__(options, 'EnumValueOptions')
662 self.name = name 662 self.name = name
663 self.index = index 663 self.index = index
664 self.number = number 664 self.number = number
665 self.type = type 665 self.type = type
666 666
667 667
668 class OneofDescriptor(object): 668 class OneofDescriptor(DescriptorBase):
669 """Descriptor for a oneof field. 669 """Descriptor for a oneof field.
670 670
671 name: (str) Name of the oneof field. 671 name: (str) Name of the oneof field.
672 full_name: (str) Full name of the oneof field, including package name. 672 full_name: (str) Full name of the oneof field, including package name.
673 index: (int) 0-based index giving the order of the oneof field inside 673 index: (int) 0-based index giving the order of the oneof field inside
674 its containing type. 674 its containing type.
675 containing_type: (Descriptor) Descriptor of the protocol message 675 containing_type: (Descriptor) Descriptor of the protocol message
676 type that contains this field. Set by the Descriptor constructor 676 type that contains this field. Set by the Descriptor constructor
677 if we're passed into one. 677 if we're passed into one.
678 fields: (list of FieldDescriptor) The list of field descriptors this 678 fields: (list of FieldDescriptor) The list of field descriptors this
679 oneof can contain. 679 oneof can contain.
680 """ 680 """
681 681
682 if _USE_C_DESCRIPTORS: 682 if _USE_C_DESCRIPTORS:
683 _C_DESCRIPTOR_CLASS = _message.OneofDescriptor 683 _C_DESCRIPTOR_CLASS = _message.OneofDescriptor
684 684
685 def __new__(cls, name, full_name, index, containing_type, fields): 685 def __new__(
686 cls, name, full_name, index, containing_type, fields, options=None):
686 _message.Message._CheckCalledFromGeneratedFile() 687 _message.Message._CheckCalledFromGeneratedFile()
687 return _message.default_pool.FindOneofByName(full_name) 688 return _message.default_pool.FindOneofByName(full_name)
688 689
689 def __init__(self, name, full_name, index, containing_type, fields): 690 def __init__(
691 self, name, full_name, index, containing_type, fields, options=None):
690 """Arguments are as described in the attribute description above.""" 692 """Arguments are as described in the attribute description above."""
693 super(OneofDescriptor, self).__init__(options, 'OneofOptions')
691 self.name = name 694 self.name = name
692 self.full_name = full_name 695 self.full_name = full_name
693 self.index = index 696 self.index = index
694 self.containing_type = containing_type 697 self.containing_type = containing_type
695 self.fields = fields 698 self.fields = fields
696 699
697 700
698 class ServiceDescriptor(_NestedDescriptorBase): 701 class ServiceDescriptor(_NestedDescriptorBase):
699 702
700 """Descriptor for a service. 703 """Descriptor for a service.
701 704
702 name: (str) Name of the service. 705 name: (str) Name of the service.
703 full_name: (str) Full name of the service, including package name. 706 full_name: (str) Full name of the service, including package name.
704 index: (int) 0-indexed index giving the order that this services 707 index: (int) 0-indexed index giving the order that this services
705 definition appears withing the .proto file. 708 definition appears withing the .proto file.
706 methods: (list of MethodDescriptor) List of methods provided by this 709 methods: (list of MethodDescriptor) List of methods provided by this
707 service. 710 service.
711 methods_by_name: (dict str -> MethodDescriptor) Same MethodDescriptor
712 objects as in |methods_by_name|, but indexed by "name" attribute in each
713 MethodDescriptor.
708 options: (descriptor_pb2.ServiceOptions) Service options message or 714 options: (descriptor_pb2.ServiceOptions) Service options message or
709 None to use default service options. 715 None to use default service options.
710 file: (FileDescriptor) Reference to file info. 716 file: (FileDescriptor) Reference to file info.
711 """ 717 """
712 718
719 if _USE_C_DESCRIPTORS:
720 _C_DESCRIPTOR_CLASS = _message.ServiceDescriptor
721
722 def __new__(cls, name, full_name, index, methods, options=None, file=None, # pylint: disable=redefined-builtin
723 serialized_start=None, serialized_end=None):
724 _message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protec ted-access
725 return _message.default_pool.FindServiceByName(full_name)
726
713 def __init__(self, name, full_name, index, methods, options=None, file=None, 727 def __init__(self, name, full_name, index, methods, options=None, file=None,
714 serialized_start=None, serialized_end=None): 728 serialized_start=None, serialized_end=None):
715 super(ServiceDescriptor, self).__init__( 729 super(ServiceDescriptor, self).__init__(
716 options, 'ServiceOptions', name, full_name, file, 730 options, 'ServiceOptions', name, full_name, file,
717 None, serialized_start=serialized_start, 731 None, serialized_start=serialized_start,
718 serialized_end=serialized_end) 732 serialized_end=serialized_end)
719 self.index = index 733 self.index = index
720 self.methods = methods 734 self.methods = methods
735 self.methods_by_name = dict((m.name, m) for m in methods)
721 # Set the containing service for each method in this service. 736 # Set the containing service for each method in this service.
722 for method in self.methods: 737 for method in self.methods:
723 method.containing_service = self 738 method.containing_service = self
724 739
725 def FindMethodByName(self, name): 740 def FindMethodByName(self, name):
726 """Searches for the specified method, and returns its descriptor.""" 741 """Searches for the specified method, and returns its descriptor."""
727 for method in self.methods: 742 return self.methods_by_name.get(name, None)
728 if name == method.name:
729 return method
730 return None
731 743
732 def CopyToProto(self, proto): 744 def CopyToProto(self, proto):
733 """Copies this to a descriptor_pb2.ServiceDescriptorProto. 745 """Copies this to a descriptor_pb2.ServiceDescriptorProto.
734 746
735 Args: 747 Args:
736 proto: An empty descriptor_pb2.ServiceDescriptorProto. 748 proto: An empty descriptor_pb2.ServiceDescriptorProto.
737 """ 749 """
738 # This function is overriden to give a better doc comment. 750 # This function is overridden to give a better doc comment.
739 super(ServiceDescriptor, self).CopyToProto(proto) 751 super(ServiceDescriptor, self).CopyToProto(proto)
740 752
741 753
742 class MethodDescriptor(DescriptorBase): 754 class MethodDescriptor(DescriptorBase):
743 755
744 """Descriptor for a method in a service. 756 """Descriptor for a method in a service.
745 757
746 name: (str) Name of the method within the service. 758 name: (str) Name of the method within the service.
747 full_name: (str) Full name of method. 759 full_name: (str) Full name of method.
748 index: (int) 0-indexed index of the method inside the service. 760 index: (int) 0-indexed index of the method inside the service.
749 containing_service: (ServiceDescriptor) The service that contains this 761 containing_service: (ServiceDescriptor) The service that contains this
750 method. 762 method.
751 input_type: The descriptor of the message that this method accepts. 763 input_type: The descriptor of the message that this method accepts.
752 output_type: The descriptor of the message that this method returns. 764 output_type: The descriptor of the message that this method returns.
753 options: (descriptor_pb2.MethodOptions) Method options message or 765 options: (descriptor_pb2.MethodOptions) Method options message or
754 None to use default method options. 766 None to use default method options.
755 """ 767 """
756 768
769 if _USE_C_DESCRIPTORS:
770 _C_DESCRIPTOR_CLASS = _message.MethodDescriptor
771
772 def __new__(cls, name, full_name, index, containing_service,
773 input_type, output_type, options=None):
774 _message.Message._CheckCalledFromGeneratedFile() # pylint: disable=protec ted-access
775 return _message.default_pool.FindMethodByName(full_name)
776
757 def __init__(self, name, full_name, index, containing_service, 777 def __init__(self, name, full_name, index, containing_service,
758 input_type, output_type, options=None): 778 input_type, output_type, options=None):
759 """The arguments are as described in the description of MethodDescriptor 779 """The arguments are as described in the description of MethodDescriptor
760 attributes above. 780 attributes above.
761 781
762 Note that containing_service may be None, and may be set later if necessary. 782 Note that containing_service may be None, and may be set later if necessary.
763 """ 783 """
764 super(MethodDescriptor, self).__init__(options, 'MethodOptions') 784 super(MethodDescriptor, self).__init__(options, 'MethodOptions')
765 self.name = name 785 self.name = name
766 self.full_name = full_name 786 self.full_name = full_name
(...skipping 14 matching lines...) Expand all
781 package: name of the package 801 package: name of the package
782 syntax: string indicating syntax of the file (can be "proto2" or "proto3") 802 syntax: string indicating syntax of the file (can be "proto2" or "proto3")
783 serialized_pb: (str) Byte string of serialized 803 serialized_pb: (str) Byte string of serialized
784 descriptor_pb2.FileDescriptorProto. 804 descriptor_pb2.FileDescriptorProto.
785 dependencies: List of other FileDescriptors this FileDescriptor depends on. 805 dependencies: List of other FileDescriptors this FileDescriptor depends on.
786 public_dependencies: A list of FileDescriptors, subset of the dependencies 806 public_dependencies: A list of FileDescriptors, subset of the dependencies
787 above, which were declared as "public". 807 above, which were declared as "public".
788 message_types_by_name: Dict of message names of their descriptors. 808 message_types_by_name: Dict of message names of their descriptors.
789 enum_types_by_name: Dict of enum names and their descriptors. 809 enum_types_by_name: Dict of enum names and their descriptors.
790 extensions_by_name: Dict of extension names and their descriptors. 810 extensions_by_name: Dict of extension names and their descriptors.
811 services_by_name: Dict of services names and their descriptors.
791 pool: the DescriptorPool this descriptor belongs to. When not passed to the 812 pool: the DescriptorPool this descriptor belongs to. When not passed to the
792 constructor, the global default pool is used. 813 constructor, the global default pool is used.
793 """ 814 """
794 815
795 if _USE_C_DESCRIPTORS: 816 if _USE_C_DESCRIPTORS:
796 _C_DESCRIPTOR_CLASS = _message.FileDescriptor 817 _C_DESCRIPTOR_CLASS = _message.FileDescriptor
797 818
798 def __new__(cls, name, package, options=None, serialized_pb=None, 819 def __new__(cls, name, package, options=None, serialized_pb=None,
799 dependencies=None, public_dependencies=None, 820 dependencies=None, public_dependencies=None,
800 syntax=None, pool=None): 821 syntax=None, pool=None):
(...skipping 17 matching lines...) Expand all
818 pool = descriptor_pool.Default() 839 pool = descriptor_pool.Default()
819 self.pool = pool 840 self.pool = pool
820 self.message_types_by_name = {} 841 self.message_types_by_name = {}
821 self.name = name 842 self.name = name
822 self.package = package 843 self.package = package
823 self.syntax = syntax or "proto2" 844 self.syntax = syntax or "proto2"
824 self.serialized_pb = serialized_pb 845 self.serialized_pb = serialized_pb
825 846
826 self.enum_types_by_name = {} 847 self.enum_types_by_name = {}
827 self.extensions_by_name = {} 848 self.extensions_by_name = {}
849 self.services_by_name = {}
828 self.dependencies = (dependencies or []) 850 self.dependencies = (dependencies or [])
829 self.public_dependencies = (public_dependencies or []) 851 self.public_dependencies = (public_dependencies or [])
830 852
831 if (api_implementation.Type() == 'cpp' and 853 if (api_implementation.Type() == 'cpp' and
832 self.serialized_pb is not None): 854 self.serialized_pb is not None):
833 _message.default_pool.AddSerializedFile(self.serialized_pb) 855 _message.default_pool.AddSerializedFile(self.serialized_pb)
834 856
835 def CopyToProto(self, proto): 857 def CopyToProto(self, proto):
836 """Copies this to a descriptor_pb2.FileDescriptorProto. 858 """Copies this to a descriptor_pb2.FileDescriptorProto.
837 859
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 field_proto.number, field_proto.type, 984 field_proto.number, field_proto.type,
963 FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type), 985 FieldDescriptor.ProtoTypeToCppProtoType(field_proto.type),
964 field_proto.label, None, nested_desc, enum_desc, None, False, None, 986 field_proto.label, None, nested_desc, enum_desc, None, False, None,
965 options=field_proto.options, has_default_value=False) 987 options=field_proto.options, has_default_value=False)
966 fields.append(field) 988 fields.append(field)
967 989
968 desc_name = '.'.join(full_message_name) 990 desc_name = '.'.join(full_message_name)
969 return Descriptor(desc_proto.name, desc_name, None, None, fields, 991 return Descriptor(desc_proto.name, desc_name, None, None, fields,
970 list(nested_types.values()), list(enum_types.values()), [], 992 list(nested_types.values()), list(enum_types.values()), [],
971 options=desc_proto.options) 993 options=desc_proto.options)
OLDNEW
« no previous file with comments | « recipe_engine/third_party/google/protobuf/any_test_pb2.py ('k') | recipe_engine/third_party/google/protobuf/descriptor_pb2.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698