1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
U
£ý°dóã@szdZdZddlmZddlmZddlmZe ¡dkrFddlm    Z
n ddlm Z
e
j Z Gd    d
„d
eƒZeƒZd d „Zd S)aoProvides a factory class for generating dynamic messages.
 
The easiest way to use this class is if you have access to the FileDescriptor
protos containing the messages you want to create you can just do the following:
 
message_classes = message_factory.GetMessages(iterable_of_file_descriptors)
my_proto_instance = message_classes['some.proto.package.MessageName']()
z"matthewtoia@google.com (Matt Toia)é)Úapi_implementation)Údescriptor_pool)ÚmessageÚcpp)Ú cpp_message)Úpython_messagec@s2eZdZdZd dd„Zdd„Zdd„Zd    d
„ZdS) ÚMessageFactoryz@Factory for creating Proto2 messages from descriptors in a pool.NcCs|p
t ¡|_i|_dS)zInitializes a new factory.N)rZDescriptorPoolÚpoolÚ_classes)Úselfr    ©r úVd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\google/protobuf/message_factory.pyÚ__init__;szMessageFactory.__init__cCs,||jkr"| |¡}||j|<|S|j|S)aEObtains a proto2 message class based on the passed in descriptor.
 
    Passing a descriptor with a fully qualified name matching a previous
    invocation will cause the same class to be returned.
 
    Args:
      descriptor: The descriptor to build from.
 
    Returns:
      A class describing the passed in descriptor.
    )r
ÚCreatePrototype)r Ú
descriptorÚ result_classr r r Ú GetPrototypeBs
 
 
 
zMessageFactory.GetPrototypecCsŠ|j}t|tjf|ddœƒ}||_||j|<|jD]}|jr2| |j¡q2|j    j
D]2}|j |jkrn| |j ¡|j|j }|  |¡qR|S)a¢Builds a proto2 message class based on the passed in descriptor.
 
    Don't call this function directly, it always creates a new class. Call
    GetPrototype() instead. This method is meant to be overridden in subblasses
    to perform additional operations on the newly constructed class.
 
    Args:
      descriptor: The descriptor to build from.
 
    Returns:
      A class describing the passed in descriptor.
    N)Ú
DESCRIPTORÚ
__module__) ÚnameÚ _GENERATED_PROTOCOL_MESSAGE_TYPErÚMessageÚ_FACTORYr
ÚfieldsZ message_typerrÚ
extensionsÚcontaining_typeÚRegisterExtension)r rZdescriptor_namerÚfieldÚ    extensionÚextended_classr r r rWs& ýý
 
     zMessageFactory.CreatePrototypecCs|i}|D]n}|j |¡}|j ¡D]}| |¡||j<q"|j ¡D]2}|j|jkr^| |j¡|j|j}|     |¡qBq|S)a£Gets all the messages from a specified file.
 
    This will find and resolve dependencies, failing if the descriptor
    pool cannot satisfy them.
 
    Args:
      files: The file names to extract messages from.
 
    Returns:
      A dictionary mapping proto names to the message classes. This will include
      any dependent messages as well as any messages defined in the same file as
      a specified message.
    )
r    ZFindFileByNameZmessage_types_by_nameÚvaluesrZ    full_nameZextensions_by_namerr
r)r ÚfilesÚresultÚ    file_nameZ    file_descÚdescrrr r r Ú GetMessages{s     zMessageFactory.GetMessages)N)Ú__name__rÚ __qualname__Ú__doc__rrrr%r r r r r8s
 
$rcsFdd„|Dƒ‰‡‡fdd„‰ˆr2ˆˆ ¡dƒqt dd„|Dƒ¡S)a^Builds a dictionary of all the messages available in a set of files.
 
  Args:
    file_protos: Iterable of FileDescriptorProto to build messages out of.
 
  Returns:
    A dictionary mapping proto names to the message classes. This will include
    any dependent messages as well as any messages defined in the same file as
    a specified message.
  cSsi|] }|j|“qSr ©r©Ú.0Ú
file_protor r r Ú
<dictcomp>°szGetMessages.<locals>.<dictcomp>cs2|jD]}|ˆkrˆˆ |¡ƒqtj |¡dS)N)Ú
dependencyÚpoprr    ZAdd)r,r.©Ú_AddFileZ file_by_namer r r1±s
zGetMessages.<locals>._AddFileécSsg|]
}|j‘qSr r)r*r r r Ú
<listcomp>¹szGetMessages.<locals>.<listcomp>)Úpopitemrr%)Z file_protosr r0r r%£s
r%N)r(Ú
__author__Zgoogle.protobuf.internalrZgoogle.protobufrrÚTypeZgoogle.protobuf.pyextrZ message_implrZGeneratedProtocolMessageTyperÚobjectrrr%r r r r Ú<module>s         h