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

Side by Side Diff: third_party/protobuf/python/google/protobuf/message_factory.py

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 files: The file names to extract messages from. 96 files: The file names to extract messages from.
97 97
98 Returns: 98 Returns:
99 A dictionary mapping proto names to the message classes. This will include 99 A dictionary mapping proto names to the message classes. This will include
100 any dependent messages as well as any messages defined in the same file as 100 any dependent messages as well as any messages defined in the same file as
101 a specified message. 101 a specified message.
102 """ 102 """
103 result = {} 103 result = {}
104 for file_name in files: 104 for file_name in files:
105 file_desc = self.pool.FindFileByName(file_name) 105 file_desc = self.pool.FindFileByName(file_name)
106 for name, msg in file_desc.message_types_by_name.items(): 106 for desc in file_desc.message_types_by_name.values():
107 if file_desc.package: 107 result[desc.full_name] = self.GetPrototype(desc)
108 full_name = '.'.join([file_desc.package, name])
109 else:
110 full_name = msg.name
111 result[full_name] = self.GetPrototype(
112 self.pool.FindMessageTypeByName(full_name))
113 108
114 # While the extension FieldDescriptors are created by the descriptor pool, 109 # While the extension FieldDescriptors are created by the descriptor pool,
115 # the python classes created in the factory need them to be registered 110 # the python classes created in the factory need them to be registered
116 # explicitly, which is done below. 111 # explicitly, which is done below.
117 # 112 #
118 # The call to RegisterExtension will specifically check if the 113 # The call to RegisterExtension will specifically check if the
119 # extension was already registered on the object and either 114 # extension was already registered on the object and either
120 # ignore the registration if the original was the same, or raise 115 # ignore the registration if the original was the same, or raise
121 # an error if they were different. 116 # an error if they were different.
122 117
123 for name, extension in file_desc.extensions_by_name.items(): 118 for extension in file_desc.extensions_by_name.values():
124 if extension.containing_type.full_name not in self._classes: 119 if extension.containing_type.full_name not in self._classes:
125 self.GetPrototype(extension.containing_type) 120 self.GetPrototype(extension.containing_type)
126 extended_class = self._classes[extension.containing_type.full_name] 121 extended_class = self._classes[extension.containing_type.full_name]
127 extended_class.RegisterExtension(extension) 122 extended_class.RegisterExtension(extension)
128 return result 123 return result
129 124
130 125
131 _FACTORY = MessageFactory() 126 _FACTORY = MessageFactory()
132 127
133 128
134 def GetMessages(file_protos): 129 def GetMessages(file_protos):
135 """Builds a dictionary of all the messages available in a set of files. 130 """Builds a dictionary of all the messages available in a set of files.
136 131
137 Args: 132 Args:
138 file_protos: A sequence of file protos to build messages out of. 133 file_protos: A sequence of file protos to build messages out of.
139 134
140 Returns: 135 Returns:
141 A dictionary mapping proto names to the message classes. This will include 136 A dictionary mapping proto names to the message classes. This will include
142 any dependent messages as well as any messages defined in the same file as 137 any dependent messages as well as any messages defined in the same file as
143 a specified message. 138 a specified message.
144 """ 139 """
145 for file_proto in file_protos: 140 for file_proto in file_protos:
146 _FACTORY.pool.Add(file_proto) 141 _FACTORY.pool.Add(file_proto)
147 return _FACTORY.GetMessages([file_proto.name for file_proto in file_protos]) 142 return _FACTORY.GetMessages([file_proto.name for file_proto in file_protos])
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698