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

Side by Side Diff: third_party/protobuf26/message_factory.py

Issue 1162993005: Renamed google.protobuf to protobuf26 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Addressed comments Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « third_party/protobuf26/message.py ('k') | third_party/protobuf26/reflection.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 # http://code.google.com/p/protobuf/ 3 # http://code.google.com/p/protobuf/
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 26 matching lines...) Expand all
37 The easiest way to use this class is if you have access to the FileDescriptor 37 The easiest way to use this class is if you have access to the FileDescriptor
38 protos containing the messages you want to create you can just do the following: 38 protos containing the messages you want to create you can just do the following:
39 39
40 message_classes = message_factory.GetMessages(iterable_of_file_descriptors) 40 message_classes = message_factory.GetMessages(iterable_of_file_descriptors)
41 my_proto_instance = message_classes['some.proto.package.MessageName']() 41 my_proto_instance = message_classes['some.proto.package.MessageName']()
42 """ 42 """
43 43
44 __author__ = 'matthewtoia@google.com (Matt Toia)' 44 __author__ = 'matthewtoia@google.com (Matt Toia)'
45 45
46 import sys ##PY25 46 import sys ##PY25
47 from google.protobuf import descriptor_database 47 from protobuf26 import descriptor_database
48 from google.protobuf import descriptor_pool 48 from protobuf26 import descriptor_pool
49 from google.protobuf import message 49 from protobuf26 import message
50 from google.protobuf import reflection 50 from protobuf26 import reflection
51 51
52 52
53 class MessageFactory(object): 53 class MessageFactory(object):
54 """Factory for creating Proto2 messages from descriptors in a pool.""" 54 """Factory for creating Proto2 messages from descriptors in a pool."""
55 55
56 def __init__(self, pool=None): 56 def __init__(self, pool=None):
57 """Initializes a new factory.""" 57 """Initializes a new factory."""
58 self.pool = (pool or descriptor_pool.DescriptorPool( 58 self.pool = (pool or descriptor_pool.DescriptorPool(
59 descriptor_database.DescriptorDatabase())) 59 descriptor_database.DescriptorDatabase()))
60 60
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 file_protos: A sequence of file protos to build messages out of. 146 file_protos: A sequence of file protos to build messages out of.
147 147
148 Returns: 148 Returns:
149 A dictionary mapping proto names to the message classes. This will include 149 A dictionary mapping proto names to the message classes. This will include
150 any dependent messages as well as any messages defined in the same file as 150 any dependent messages as well as any messages defined in the same file as
151 a specified message. 151 a specified message.
152 """ 152 """
153 for file_proto in file_protos: 153 for file_proto in file_protos:
154 _FACTORY.pool.Add(file_proto) 154 _FACTORY.pool.Add(file_proto)
155 return _FACTORY.GetMessages([file_proto.name for file_proto in file_protos]) 155 return _FACTORY.GetMessages([file_proto.name for file_proto in file_protos])
OLDNEW
« no previous file with comments | « third_party/protobuf26/message.py ('k') | third_party/protobuf26/reflection.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698