3 SÉLj,ã@sDdZdZGdd„deƒZGdd„deƒZGdd„deƒZdd „Zd S) z*Provides a container for DescriptorProtos.z"matthewtoia@google.com (Matt Toia)c@s eZdZdS)ÚErrorN)Ú__name__Ú __module__Ú __qualname__©rrú)/usr/lib/python3.6/descriptor_database.pyr$src@seZdZdZdS)Ú,DescriptorDatabaseConflictingDefinitionErrorzGRaised when a proto is added with the same name & different descriptor.N)rrrÚ__doc__rrrrr(src@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚDescriptorDatabasezEA container accepting FileDescriptorProtos and maps DescriptorProtos.cCsi|_i|_dS)N)Ú_file_desc_protos_by_fileÚ_file_desc_protos_by_symbol)ÚselfrrrÚ__init__/szDescriptorDatabase.__init__csâˆj}||jkrˆ|j|<n|j|ˆkr6td|ƒ‚ˆj}x.ˆjD]$}|jj‡fdd„t||ƒDƒƒqDWx$ˆjD]}ˆ|jdj ||jfƒ<qtWx$ˆj D]}ˆ|jdj ||jfƒ<qšWx$ˆj D]}ˆ|jdj ||jfƒ<qÀWdS)aMAdds the FileDescriptorProto and its types to this database. Args: file_desc_proto: The FileDescriptorProto to add. Raises: DescriptorDatabaseConflictingDefinitionError: if an attempt is made to add a proto with the same name but different definition than an exisiting proto in the database. z0%s already added, but with different descriptor.c3s|]}|ˆfVqdS)Nr)Ú.0Úname)Úfile_desc_protorrú Hsz)DescriptorDatabase.Add..Ú.N) rr rÚpackageZ message_typer ÚupdateÚ_ExtractSymbolsÚ enum_typeÚjoinÚ extensionÚservice)r rZ proto_namerÚmessageÚenumrrr)rrÚAdd3s        zDescriptorDatabase.AddcCs |j|S)a¸Finds the file descriptor proto by file name. Typically the file name is a relative path ending to a .proto file. The proto with the given name will have to have been added to this database using the Add method or else an error will be raised. Args: name: The file name to find. Returns: The file descriptor proto matching the name. Raises: KeyError if no file by the given name was added. )r )r rrrrÚFindFileByNameSsz!DescriptorDatabase.FindFileByNamec Cs:y |j|Stk r4|jdƒ\}}}|j|SXdS)a¢Finds the file descriptor proto containing the specified symbol. The symbol should be a fully qualified name including the file descriptor's package and any containing messages. Some examples: 'some.package.name.Message' 'some.package.name.Message.NestedEnum' 'some.package.name.Message.some_field' The file descriptor proto containing the specified symbol must be added to this database using the Add method or else an error will be raised. Args: symbol: The fully qualified symbol name. Returns: The file descriptor proto containing the symbol. Raises: KeyError if no file contains the specified symbol. rN)r ÚKeyErrorÚ rpartition)r ÚsymbolZ top_levelÚ_rrrÚFindFileContainingSymbolfs  z+DescriptorDatabase.FindFileContainingSymbolN)rrrrr rrr"rrrrr ,s  r ccsn|r|d|jn|j}|Vx(|jD]}xt||ƒD] }|Vq6Wq&Wx |jD]}dj||jfƒVqPWdS)zëPulls out all the symbols from a descriptor proto. Args: desc_proto: The proto to extract symbols from. package: The package containing the descriptor type. Yields: The fully qualified name found in the descriptor. rN)rÚ nested_typerrr)Z desc_protorZ message_namer#r rrrrrˆs   rN)rÚ __author__Ú ExceptionrrÚobjectr rrrrrÚs \