ó SÉLjc@s¶dZdZddlZddlmZddlmZddlmZejZd„Zd„Z d „Z d e fd „ƒYZ d „Z er ejjZn e ƒZd „ZdS(sJProvides DescriptorPool to use as a container for proto2 descriptors. The DescriptorPool is used in conjection with a DescriptorDatabase to maintain a collection of protocol buffer descriptors for use when dynamically creating message types at runtime. For most applications protocol buffers should be used via modules generated by the protocol buffer compiler tool. This should only be used when the type of protocol buffers used in an application or library cannot be predetermined. Below is a straightforward example on how to use this class: pool = DescriptorPool() file_descriptor_protos = [ ... ] for file_descriptor_proto in file_descriptor_protos: pool.Add(file_descriptor_proto) my_message_descriptor = pool.FindMessageTypeByName('some.package.MessageType') The message descriptor can be used in conjunction with the message_factory module in order to create a protocol buffer class that can be encoded and decoded. If you want to get a Python class for the specified proto, use the helper functions inside google.protobuf.message_factory directly instead of this class. s"matthewtoia@google.com (Matt Toia)iÿÿÿÿN(t descriptor(tdescriptor_database(t text_encodingcCs |jdƒS(sLRemove leading period from fully-qualified type name. Due to b/13860351 in descriptor_database.py, types in the root namespace are generated with a leading period. This function removes that prefix. Args: name: A str, the fully-qualified symbol name. Returns: A str, the normalized fully-qualified symbol name. t.(tlstrip(tname((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyt_NormalizeFullyQualifiedNameFs cCs|jdƒr|jSdSdS(sCReturns the value of the field `options`, or None if it is not set.toptionsN(tHasFieldRtNone(tdescriptor_proto((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyt_OptionsOrNoneUscCsO|joN|jjoN|jjƒjoN|jtjjkoN|j tjj kS(N( t is_extensiontcontaining_typet has_optionst GetOptionstmessage_set_wire_formatttypeRtFieldDescriptort TYPE_MESSAGEtlabeltLABEL_OPTIONAL(tfield((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyt_IsMessageSetExtension]s   tDescriptorPoolcBsaeZdZer!d"d„Znd"d„Zd„Zd„Zd„Z d„Z d„Z d„Z d „Z d „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd"d"d"d"d„Zd"d"d"d"d„Zed„Zd„Zd„Z d„Z!d„Z"d„Z#d„Z$d „Z%d!„Z&RS(#sGA collection of protobufs dynamically constructed by descriptor protos.cCstjj|ƒS(N(Rt_messageR(tclst descriptor_db((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyt__new__jscCsmtjƒ|_||_i|_i|_i|_i|_i|_t j t ƒ|_ t j t ƒ|_ dS(sîInitializes a Pool of proto buffs. The descriptor_db argument to the constructor is provided to allow specialized file descriptor proto lookup code to be triggered on demand. An example would be an implementation which will read and compile a file specified in a call to FindFileByName() and not require the call to Add() at all. Results from this database will be cached internally here as well. Args: descriptor_db: A secondary source of file descriptors. N(RtDescriptorDatabaset _internal_dbt_descriptor_dbt _descriptorst_enum_descriptorst_service_descriptorst_file_descriptorst_toplevel_extensionst collectionst defaultdicttdictt_extensions_by_namet_extensions_by_number(tselfR((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyt__init__ns       cCs|jj|ƒdS(sAdds the FileDescriptorProto and its types to this pool. Args: file_desc_proto: The FileDescriptorProto to add. N(RtAdd(R*tfile_desc_proto((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyR,ˆscCs3ddlm}|jj|ƒ}|j|ƒdS(s³Adds the FileDescriptorProto and its types to this pool. Args: serialized_file_desc_proto: A bytes string, serialization of the FileDescriptorProto to add. iÿÿÿÿ(tdescriptor_pb2N(tgoogle.protobufR.tFileDescriptorProtot FromStringR,(R*tserialized_file_desc_protoR.R-((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pytAddSerializedFile‘s   cCsEt|tjƒs!tdƒ‚n||j|j<|j|jƒdS(sAdds a Descriptor to the pool, non-recursively. If the Descriptor contains nested messages or enums, the caller must explicitly register them. This method also registers the FileDescriptor associated with the message. Args: desc: A Descriptor. s+Expected instance of descriptor.Descriptor.N(t isinstanceRt Descriptort TypeErrorR t full_namet_AddFileDescriptortfile(R*tdesc((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyt AddDescriptorŸs cCsEt|tjƒs!tdƒ‚n||j|j<|j|jƒdS(s¤Adds an EnumDescriptor to the pool. This method also registers the FileDescriptor associated with the enum. Args: enum_desc: An EnumDescriptor. s/Expected instance of descriptor.EnumDescriptor.N(R4RtEnumDescriptorR6R!R7R8R9(R*t enum_desc((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pytAddEnumDescriptor¯s cCs5t|tjƒs!tdƒ‚n||j|jt|ƒ}|jdƒ\}}}|j|ƒ}|j|S(sLoads the named field descriptor from the pool. Args: full_name: The full name of the field descriptor to load. Returns: The field descriptor for the named field. Raises: KeyError: if the field cannot be found in the pool. R(RRSRTtfields_by_name(R*R7RWRXt field_nametmessage_descriptor((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pytFindFieldByNames cCs>t|ƒ}|jdƒ\}}}|j|ƒ}|j|S(sLoads the named oneof descriptor from the pool. Args: full_name: The full name of the oneof descriptor to load. Returns: The oneof descriptor for the named oneof. Raises: KeyError: if the oneof cannot be found in the pool. R(RRSRTtoneofs_by_name(R*R7RWRXt oneof_nameR_((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pytFindOneofByName�s cCsˆt|ƒ}y|j|SWntk r.nX|jdƒ\}}}y|j|ƒ}Wn tk r||j|ƒ}nX|j|S(sLoads the named extension descriptor from the pool. Args: full_name: The full name of the extension descriptor to load. Returns: A FieldDescriptor, describing the named extension. Raises: KeyError: if the extension cannot be found in the pool. R(RR$RDRSRTRRRU(R*R7RWRXRYtscope((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pytFindExtensionByName¡s   cCs|j||S(sÕGets the extension of the specified message with the specified number. Extensions have to be registered to this pool by calling AddExtensionDescriptor. Args: message_descriptor: descriptor of the extended message. number: integer, number of the extension field. Returns: A FieldDescriptor describing the extension. Raises: KeyError: when no extension with the given number is known for the specified message. (R)(R*R_RC((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pytFindExtensionByNumber¿scCst|j|jƒƒS(s!Gets all the known extension of a given message. Extensions have to be registered to this pool by calling AddExtensionDescriptor. Args: message_descriptor: descriptor of the extended message. Returns: A list of FieldDescriptor describing the extensions. (tlistR)tvalues(R*R_((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pytFindAllExtensionsÒs cCs6t|ƒ}||jkr+|j|ƒn|j|S(sLoads the named service descriptor from the pool. Args: full_name: The full name of the service descriptor to load. Returns: The service descriptor for the named service. Raises: KeyError: if the service cannot be found in the pool. (RR"RR(R*R7((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pytFindServiceByNameàs cCsvy|jj|ƒ}Wn7tk rO}|jrF|jj|ƒ}qP|‚nX|sitd|ƒ‚n|j|ƒS(s"Finds the file in descriptor DB containing the specified symbol. Args: symbol: The name of the symbol to search for. Returns: A FileDescriptor that contains the specified symbol. Raises: KeyError: if the file cannot be found in the descriptor database. s Cannot find a file containing %s(RR[RDRRN(R*RVRPRQ((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyRRñs   cCs|j|jkrt|j|jƒƒ}g|jD]}|j|ƒ^q4}g|jD]}||^qY}tjd|d|jd|j d|j dt |ƒd|j ƒd|d|ƒ}i}xM|D]E} |j |j| jjƒƒƒ|j d „| jjƒDƒƒqÍWxB|jD]7} |j| |j |||j ƒ} | |j| j,sR tN(&RR#Rgt_GetDepst dependencyRMtpublic_dependencyRRLRlRmR tSerializeToStringtupdatet_ExtractSymbolstmessage_types_by_nameRhtenum_types_by_nameRFt_ConvertMessageDescriptort enum_typet_ConvertEnumDescriptorR t enumerateRGt_MakeFieldDescriptortTruet_GetTypeFromScopetextendeeR t _SetFieldTypeRUt_SetAllFieldTypesRqtservicet_MakeServiceDescriptortservices_by_nameR,(R*RPt built_depstnt direct_depstit public_depstfile_descriptorRdRvRFt message_descR~tindextextension_prototextension_desct desc_prototdesc_proto_prefixR:t service_proto((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyRNsf %                 c!Cs|r!dj||jfƒ}n |j}|dkr?d}n |j}|dkr]i}ng|jD]!}|j|||||ƒ^qg}g|jD]!} |j| ||d|ƒ^q˜} gt|jƒD]$\} } |j | || |ƒ^qÏ} gt|j ƒD]*\} }|j ||| |dt ƒ^q }gt|j ƒD]B\} }t j|jdj||jfƒ| dg|jƒ^qI}g|jD]}|j|jf^q›}|rÈt }nt}t jd|jd|d|ddd| d|d |d | d |d t|ƒd |d|d|ddddd|ƒ}x|jD]}||_qMWx|jD]} || _qjWxat|jƒD]P\}}|jdƒr�|j}||jj| |ƒ||| |_q�q�W||t|ƒ<||j|<|S(s¹Adds the proto to the pool in the specified package. Args: desc_proto: The descriptor_pb2.DescriptorProto protobuf message. package: The package the proto should be located in. file_desc: The file containing this message. scope: Dict mapping short and full symbols to message and enum types. syntax: string indicating syntax of the file ("proto2" or "proto3") Returns: The added descriptor. RR RR7tfilenameR tfieldstoneofst nested_typest enum_typest extensionsRt is_extendabletextension_rangesR9tserialized_starttserialized_endRmt oneof_indexN( tjoinRR t nested_typeR}R~RR€RR�RGR‚t oneof_declRtOneofDescriptorRtextension_rangetstarttendtFalseR5R RšR R›RR¡R˜tappendtcontaining_oneofRqR (R*R”RlRJRdRmt desc_nameROtnestedRstenumsR‘RR˜RGRœR:R™trRžR�t field_indext field_descR¡((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyR}]sf      ..7=U(         c CsÚ|r!dj||jfƒ}n |j}|d kr?d }n |j}gt|jƒD]\}} |j| |ƒ^qX} tjd|jd|d|d|d| d|dt|ƒƒ} | |d |<| |j |<| S( s±Make a protobuf EnumDescriptor given an EnumDescriptorProto protobuf. Args: enum_proto: The descriptor_pb2.EnumDescriptorProto protobuf message. package: Optional package name for the new message EnumDescriptor. file_desc: The file containing the enum descriptor. containing_type: The type containing this enum. scope: Scope containing available types. Returns: The added descriptor RRR7R—R9RhR Rs.%sN( R¢RR R€tvaluet_MakeEnumValueDescriptorRR<R R!( R*t enum_protoRlRJR Rdt enum_nameROR‘R²RhR:((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyR®s$    1 c!Cs¦|r!dj||jfƒ}n |j}tjd|jd|d|d|jd|jddddd dd dd |jd td dd|dddt |ƒd|ƒS(s£Creates a field descriptor from a FieldDescriptorProto. For message and enum type fields, this method will do a look up in the pool for the appropriate descriptor for that type. If it is unavailable, it will fall back to the _source function to create it. If this type is still unavailable, construction will fail. Args: field_proto: The proto describing the field. message_name: The name of the containing message. index: Index of the field file_desc: The file containing the field descriptor. is_extension: Indication that this field is for an extension. Returns: An initialized FieldDescriptor object RRR7R‘RCRtcpp_typeRFR~R Rthas_default_valuet default_valueR RBRR9N( R¢RRRRCRR RR©R (R*t field_protoRWR‘RJR R7((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyR�Ôs(       c Cst|ƒ}|j||j|ƒ}|dkrBt|jƒ}ndj||jgƒ}x9t|j|jƒD]"\}}|j||||ƒqpWxTt|j|j ƒD]=\}} |j||j |ƒ| _ |j|| ||ƒq¬Wx$|j D]} |j || |ƒq÷WdS(sSets all the descriptor's fields's types. This method also sets the containing types on any extensions. Args: package: The current package of desc_proto. desc_proto: The message descriptor to update. scope: Enclosing scope of available types. RN(RqRƒRR¢tzipRR˜R…RGRœR„R R£R†( R*RlR”Rdt main_desctnested_packageR¹R±R’R“R£((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyR†s  "cCs|jr$|j||j|ƒ}nd}|jdƒsot|tjƒr]tjj|_ qotjj |_ ntjj |j ƒ|_ |j tjjks±|j tjj kr½||_n|j tjj krÞ||_n|jtjjkrt|_g|_n÷|jdƒr&t|_|j tjjksJ|j tjjkr_t|jƒ|_qÿ|j tjjkrƒ|j|_qÿ|j tjjkr³|jjƒdk|_qÿ|j tjj krä|jj|jj|_qÿ|j tjjkrtj |jƒ|_qÿt!|jƒ|_nÙt|_|j tjjksY|j tjjkred|_nš|j tjjkr†d|_ny|j tjjkr§t|_nX|j tjj krÕ|jj"dj|_n*|j tjjkröd|_n d|_|j |_ dS( sSets the field's type, cpp_type, message_type and enum_type. Args: field_proto: Data about the field in proto format. field_desc: The descriptor to modiy. package: The package the field's container is in. scope: Enclosing scope of available types. RR¸ttrueguiRtN(#t type_nameRƒR RR4RR5RRRt TYPE_ENUMtProtoTypeToCppProtoTypeR¶t TYPE_GROUPRFR~RtLABEL_REPEATEDR©R·R¸R‚t TYPE_DOUBLEt TYPE_FLOATtfloatt TYPE_STRINGt TYPE_BOOLtlowertvalues_by_nameRCt TYPE_BYTESRt CUnescapetintRh(R*R¹R±RlRdR:((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyR… s^              c Cs4tjd|jd|d|jdt|ƒddƒS(sðCreates a enum value descriptor object from a enum value proto. Args: value_proto: The proto describing the enum value. index: The index of the enum value. Returns: An initialized EnumValueDescriptor object. RR‘RCRRN(RtEnumValueDescriptorRRCR R (R*t value_protoR‘((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyR³fs    c Cs±|r!dj||jfƒ}n |j}gt|jƒD]'\}}|j|||||ƒ^q:} tjd|jd|d|d| dt|ƒd|ƒ} | |j|<| S(sÙMake a protobuf ServiceDescriptor given a ServiceDescriptorProto. Args: service_proto: The descriptor_pb2.ServiceDescriptorProto protobuf message. service_index: The index of the service in the File. scope: Dict mapping short and full symbols to message and enum types. package: Optional package name for the new message EnumDescriptor. file_desc: The file containing the service descriptor. Returns: The added descriptor. RRR7R‘tmethodsRR9( R¢RR€tmethodt_MakeMethodDescriptorRR?R R"( R*R–t service_indexRdRlRJt service_nameR‘t method_protoRÏR:((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyRˆxs :   c Cs…dj||jfƒ}|j||j|ƒ}|j||j|ƒ}tjd|jd|d|dd d|d|dt|ƒƒS( s�Creates a method descriptor from a MethodDescriptorProto. Args: method_proto: The proto describing the method. service_name: The name of the containing service. package: Optional package name to look up for types. scope: Scope containing available types. index: Index of the method in the service. Returns: An initialized MethodDescriptor object. RRR7R‘tcontaining_servicet input_typet output_typeRN( R¢RRƒRÖR×RtMethodDescriptorR R ( R*RÔRÓRlRdR‘R7RÖR×((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyRјsccssxl|D]d}t|jƒ|fVx|j|jƒD] }|Vq4Wx%|jD]}t|jƒ|fVqMWqWdS(sÌPulls out all the symbols from descriptor protos. Args: descriptors: The messages to extract descriptors from. Yields: A two element tuple of the type name and descriptor object. N(RqR7RzRšR›(R*t descriptorsR:RVRs((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyRz³s  ccsBx;|D]3}|j|ƒ}|Vx|jD] }|Vq+WqWdS(sµRecursively finds dependencies for file protos. Args: dependencies: The names of the files being depended on. Yields: Each direct and indirect dependency. N(RMRo(R*RoRvtdep_desct parent_dep((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyRuÃs cCsr||krjt|ƒjdƒ}xF|rfdj||gƒ}||krV|}Pq$|jdƒq$Wn||S(s?Finds a given type name in the current scope. Args: package: The package the proto should be located in. type_name: The name of the type to be found in the scope. scope: Dict mapping short and full symbols to message and enum types. Returns: The descriptor for the requested type. Riÿÿÿÿ(RqtsplitR¢tpop(R*RlR¾Rdt componentstpossible_match((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyRƒÓs   N('t__name__t __module__t__doc__t_USE_C_DESCRIPTORSR RR+R,R3R;R>RARIRKR8RMR[RTR\R`RcReRfRiRjRRRNR}RR©R�R†R…R³RˆRÑRzRuRƒ(((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyResJ     *   0          UP& + F    cCs|jdƒr|Sd|S(NRs.%s(t startswith(R((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyRqêscCstS(N(t_DEFAULT(((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pytDefault÷s(Rât __author__R%R/RRRRãRR RtobjectRRqRt default_poolRåRæ(((sC/usr/lib/python2.7/site-packages/google/protobuf/descriptor_pool.pyt8s$     ÿÿÿˆ