
    L                        S r SSKrSSKrSSKrSSKJr  SSKJr  / SQr\R                  \R                  \R                  \R                  \R                  S \R                  S \R                  S \R                  S	 0r\R                  \\R                  \\R                  S
 \R                  S \R                  S \R                  \0r " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      rS rS rS rS rS rS rS r \RB                  " S 5      \"4S! j5       r# " S" S#\$5      r%g)$ah
  Services descriptor definitions.

Contains message definitions and functions for converting
service classes into transmittable message format.

Describing an Enum instance, Enum class, Field class or Message class will
generate an appropriate descriptor object that describes that class.
This message can itself be used to transmit information to clients wishing
to know the description of an enum value, enum, field or message without
needing to download the source code.  This format is also compatible with
other, non-Python languages.

The descriptors are modeled to be binary compatible with
  https://github.com/google/protobuf

NOTE: The names of types and fields are not always the same between these
descriptors and the ones defined in descriptor.proto.  This was done in order
to make source code files that use these descriptors easier to read.  For
example, it is not necessary to prefix TYPE to all the values in
FieldDescriptor.Variant as is done in descriptor.proto
FieldDescriptorProto.Type.

Example:

  class Pixel(messages.Message):

    x = messages.IntegerField(1, required=True)
    y = messages.IntegerField(2, required=True)

    color = messages.BytesField(3)

  # Describe Pixel class using message descriptor.
  fields = []

  field = FieldDescriptor()
  field.name = 'x'
  field.number = 1
  field.label = FieldDescriptor.Label.REQUIRED
  field.variant = FieldDescriptor.Variant.INT64
  fields.append(field)

  field = FieldDescriptor()
  field.name = 'y'
  field.number = 2
  field.label = FieldDescriptor.Label.REQUIRED
  field.variant = FieldDescriptor.Variant.INT64
  fields.append(field)

  field = FieldDescriptor()
  field.name = 'color'
  field.number = 3
  field.label = FieldDescriptor.Label.OPTIONAL
  field.variant = FieldDescriptor.Variant.BYTES
  fields.append(field)

  message = MessageDescriptor()
  message.name = 'Pixel'
  message.fields = fields

  # Describing is the equivalent of building the above message.
  message == describe_message(Pixel)

Public Classes:
  EnumValueDescriptor: Describes Enum values.
  EnumDescriptor: Describes Enum classes.
  FieldDescriptor: Describes field instances.
  FileDescriptor: Describes a single 'file' unit.
  FileSet: Describes a collection of file descriptors.
  MessageDescriptor: Describes Message classes.

Public Functions:
  describe_enum_value: Describe an individual enum-value.
  describe_enum: Describe an Enum class.
  describe_field: Describe a Field definition.
  describe_file: Describe a 'file' unit from a Python module or object.
  describe_file_set: Describe a file set from a list of modules or objects.
  describe_message: Describe a Message definition.
    N)messages)util)EnumDescriptorEnumValueDescriptorFieldDescriptorMessageDescriptorFileDescriptorFileSetDescriptorLibrarydescribe_enumdescribe_enum_valuedescribe_fielddescribe_messagedescribe_filedescribe_file_setdescribeimport_descriptor_loaderc                 *    U =(       a    S=(       d    S$ )Ntruefalse values    8lib/third_party/apitools/base/protorpclite/descriptor.py<lambda>r      s    ):7)Fh)F    c                 4    [         R                  " U 5      S   $ Nr   )codecsescape_encoder   s    r   r   r          v';';E'B1'Er   c                     U $ Nr   r   s    r   r   r          r   c                 B    [         R                  " U R                  5      $ r#   )six	text_typenumberr   s    r   r   r      s    cmmELL&Ar   c                     U S:H  $ )Nr   r   r   s    r   r   r      s	    ')9r   c                 4    [         R                  " U 5      S   $ r   )r   escape_decoder   s    r   r   r      r!   r   c                     U $ r#   r   r   s    r   r   r      r$   r   c                       \ rS rSrSr\R                  " SSS9r\R                  " SS\R                  R                  S9rSrg	)
r      zjEnum value descriptor.

Fields:
  name: Name of enumeration value.
  number: Number of enumeration value.
   Trequired   r1   variantr   N)__name__
__module____qualname____firstlineno____doc__r   StringFieldnameIntegerFieldVariantINT32r(   __static_attributes__r   r   r   r   r      s@     D1D""1,0+3+;+;+A+ACFr   r   c                   `    \ rS rSrSr\R                  " S5      r\R                  " \	SSS9r
Srg)	r      zxEnum class descriptor.

Fields:
  name: Name of Enum without any qualification.
  values: Values defined by Enum class.
r/   r2   Trepeatedr   N)r5   r6   r7   r8   r9   r   r:   r;   MessageFieldr   valuesr?   r   r   r   r   r      s.     "D""#6DIFr   r   c                   n   \ rS rSrSr\R                  r " S S\R                  5      r\R                  " SSS9r
\R                  " SS\R                  R                  S	9r\R                  " \S
\R                  S9r\R                  " \S5      r\R                  " S5      r\R                  " S5      rSrg)r      aW  Field definition descriptor.

Enums:
  Variant: Wire format hint sub-types for field.
  Label: Values for optional, required and repeated fields.

Fields:
  name: Name of field.
  number: Number of field.
  variant: Variant of field.
  type_name: Type name for message and enum fields.
  default_value: String representation of default value.
c                   $    \ rS rSrSrSrSrSrSrg)FieldDescriptor.Label   zField label.r/   r2      r   N)	r5   r6   r7   r8   r9   OPTIONALREQUIREDREPEATEDr?   r   r   r   LabelrI      s    r   rO   r/   Tr0   rK   r3      )default         r   N)r5   r6   r7   r8   r9   r   r=   EnumrO   r:   r;   r<   r>   r(   	EnumFieldrL   labelr4   	type_namedefault_valuer?   r   r   r   r   r      s     G  D1D""1,0+3+;+;+A+ACF ua@E  !,G$$Q'I ((+Mr   r   c                       \ rS rSrSr\R                  " S5      r\R                  " \	SSS9r
\R                  " SSSS9r\R                  " \S	SS9rS
rg)r      zMessage definition descriptor.

Fields:
  name: Name of Message without any qualification.
  fields: Fields defined for message.
  message_types: Nested Message classes defined on message.
  enum_types: Nested Enum classes defined on message.
r/   r2   TrB   z7apitools.base.protorpclite.descriptor.MessageDescriptorrK   rP   r   N)r5   r6   r7   r8   r9   r   r:   r;   rD   r   fieldsmessage_typesr   
enum_typesr?   r   r   r   r   r      s[     "D""?AEF))A1M &&~q4HJr   r   c                       \ rS rSrSr\R                  " S5      r\R                  " \	SSS9r
\R                  " \SSS9rSrg	)
r	      zDescription of file containing protobuf definitions.

Fields:
  package: Fully qualified name of package that definitions belong to.
  message_types: Message definitions contained in file.
  enum_types: Enum definitions contained in file.
r2   rP   TrB   rR   r   N)r5   r6   r7   r8   r9   r   r:   packagerD   r   r]   r   r^   r?   r   r   r   r	   r	      sD     ""1%G ))*;QNM&&~q4HJr   r	   c                   <    \ rS rSrSr\R                  " \SSS9rSr	g)r
   i  zFA collection of FileDescriptors.

Fields:
  files: Files in file-set.
r/   TrB   r   N)
r5   r6   r7   r8   r9   r   rD   r	   filesr?   r   r   r   r
   r
     s     !!.!dCEr   r
   c                     [        5       n[        R                  " U R                  5      Ul        U R                  Ul        U$ )zBuild descriptor for Enum instance.

Args:
  enum_value: Enum value to provide descriptor for.

Returns:
  Initialized EnumValueDescriptor instance describing the Enum instance.
)r   r&   r'   r;   r(   )
enum_valueenum_value_descriptors     r   r   r     s8     01!$z!?#-#4#4   r   c                    [        5       nU R                  5       R                  S5      S   Ul        / n[	        U R                  5       5       H.  nU R                  U5      nUR                  [        U5      5        M0     U(       a  X!l	        U$ )zBuild descriptor for Enum class.

Args:
  enum_definition: Enum class to provide descriptor for.

Returns:
  Initialized EnumDescriptor instance describing the Enum class.
.)
r   definition_namesplitr;   sortednumberslookup_by_numberappendr   rE   )enum_definitionenum_descriptorrE   r(   r   s        r   r   r     s}     %&O*::<BB3GKOF0023008)%01 4 !'r   c                    [        5       nU R                  Ul        U R                  Ul        U R                  Ul        [	        U [
        R                  5      (       a  U R                  R                  5       Ul	        [	        U [
        R                  5      (       a  U R                  R                  5       Ul	        U R                  b'  [        [        U 5         " U R                  5      Ul        U R                  (       a!  [         R                   R"                  Ul        U$ U R&                  (       a!  [         R                   R(                  Ul        U$ [         R                   R*                  Ul        U$ )zBuild descriptor for Field instance.

Args:
  field_definition: Field instance to provide descriptor for.

Returns:
  Initialized FieldDescriptor instance describing the Field instance.
)r   r;   r(   r4   
isinstancer   rV   typerj   rX   rD   message_typerQ   _DEFAULT_TO_STRING_MAPrY   rC   rO   rN   rW   r1   rM   rL   )field_definitionfield_descriptors     r   r   r   1  s4    '(,11.55/77"H$6$677%5%:%:%J%J%L""H$9$9::))99; 	" +)?!"*$$4$<$<*>&   !0!6!6!?!?  
	"	"!0!6!6!?!?  "1!6!6!?!?r   c                 B   [        5       nU R                  5       R                  S5      S   Ul        [	        U R                  5       S S9nU(       a!  U Vs/ s H  n[        U5      PM     snUl         U R                  n/ nU H(  n[        X5      nUR                  [        U5      5        M*     XQl         U R                  n/ n	U H(  n[        X5      nU	R                  [        U5      5        M*     Xl        U$ s  snf ! [         a     NVf = f! [         a     U$ f = f)zBuild descriptor for Message class.

Args:
  message_definition: Message class to provide descriptor for.

Returns:
  Initialized MessageDescriptor instance describing the Message class.
rh   ri   c                     U R                   $ r#   )r(   )vs    r   r   "describe_message.<locals>.<lambda>c  s    !((r   )key)r   rj   rk   r;   rl   
all_fieldsr   r\   __messages__getattrro   r   r]   AttributeError	__enums__r   r^   )
message_definitionmessage_descriptorr\   fieldnested_messagesmessage_descriptorsr;   r   nested_enumsenum_descriptorss
             r   r   r   U  s<    +,0@@BHH &113*,FHN$Ou^E%:$O!
?,99 !#D.5E&&'7'>? $ ,?(
9)33  D.5E##M%$89 ! )9%5 %P     s*   C;4D  7D  
DD
DDc                 "   [        5       n[        R                  " U 5      Ul        UR                  (       d  SUl        / n/ n[	        [        U 5      5       H  n[        X5      n[        U[        5      (       d  M%  [        U[        R                  5      (       a  UR                  [        U5      5        M`  [        U[        R                  5      (       d  M  UR                  [        U5      5        M     U(       a  X!l        U(       a  X1l        U$ )zBuild a file from a specified Python module.

Args:
  module: Python module to describe.

Returns:
  Initialized FileDescriptor instance describing the module.
N)r	   r   get_package_for_modulera   rl   dirr   rs   rt   
issubclassr   Messagero   r   rU   r   r]   r^   )module
descriptorr   r   r;   r   s         r   r   r     s      !J44V<J!
 s6{#%eT""%!1!122#**+;E+BCE8==11 ''e(<= $ #6  0r   c                 ~    [        5       n/ nU  H  nUR                  [        U5      5        M     U(       a  X!l        U$ )zBuild a file set from a specified Python modules.

Args:
  modules: Iterable of Python module to describe.

Returns:
  Initialized FileSet instance describing the modules.
)r
   ro   r   rc   )modulesr   file_descriptorsr   s       r   r   r     s?     Jf 56  +r   c                    [        U [        R                  5      (       a  [        U 5      $ [        U [        R
                  5      (       a  [        U 5      $ [        U [        R                  5      (       a  [        U 5      $ [        U [        5      (       aT  [        U [        R                  5      (       a  [        U 5      $ [        U [        R                  5      (       a  [        U 5      $ g)a  Describe any value as a descriptor.

Helper function for describing any object with an appropriate descriptor
object.

Args:
  value: Value to describe as a descriptor.

Returns:
  Descriptor message class if object is describable as a descriptor, else
  None.
N)rs   types
ModuleTyper   r   Fieldr   rU   r   rt   r   r   r   r   r   s    r   r   r     s     %))**U##	E8>>	*	*e$$	E8==	)	)"5))	E4	 	 eX--..#E**x}}-- ''r   r/   c                    U R                  S5      (       a  U SS n U R                  S5      (       d3  U R                  S5      S   nU (       a   U" U SSU/5      n[        U5      $  [        [        R
                  " U [        S95      $ ! [         a     N/f = f! [        R                   a  nU R                  SS5      n[        U5      S:  a  Uu  pg [        XaS9n[        U[        5      (       a  UR                  =(       d    / n	O-[        U[        5      (       a  UR                  =(       d    / n	O/ n	U	 H  n
U
R                   U:X  d  M  U
s  s SnA$    Ue! [        R                   a     Uef = fUeSnAff = f)a   Find objects by importing modules as needed.

A definition loader is a function that resolves a definition name to a
descriptor.

The import finder resolves definitions to their names by importing modules
when necessary.

Args:
  definition_name: Name of definition to find.
  importer: Import function used for importing new modules.

Returns:
  Appropriate descriptor for any describable type located by name.

Raises:
  DefinitionNotFoundError when a name does not refer to either a definition
  or a module.
rh   r/   Nri    )importer)
startswithrk   r   ImportErrorr   find_definition
__import__DefinitionNotFoundErrorrsplitlenr   rs   r   rE   r   r\   r;   )rj   r   leafr   err
split_nameparentchildparent_definitionsearch_list
definitions              r   r   r     s   , !!#&&)!"-%%c**$$S)"-(!/2rD6B  ''00:DF G 	G   ++  %++C3
z?Q&MF*$<%/! /@@"3":":"@bK 13DEE"3":":"@bK"$K"-J!%/)) #.
 	# 33  	#" 	7sa   B &!B 
BBE9,%E4	EA+E4
E4E9E4E/+E4.E//E44E9c                   \    \ rS rSrSr\R                  " S5      S\4S j5       rS r	S r
Srg)	r   i  a~  A descriptor library is an object that contains known definitions.

A descriptor library contains a cache of descriptor objects mapped by
definition name.  It contains all types of descriptors except for
file sets.

When a definition name is requested that the library does not know about
it can be provided with a descriptor loader which attempt to resolve the
missing descriptor.
r/   Nc                 0    X l         U=(       d    0 U l        g)af  Constructor.

Args:
  descriptors: A dictionary or dictionary-like object that can be used
    to store and cache descriptors by definition name.
  definition_loader: A function used for resolving missing descriptors.
    The function takes a definition name as its parameter and returns
    an appropriate descriptor.  It may raise DefinitionNotFoundError.
N)%_DescriptorLibrary__descriptor_loader_DescriptorLibrary__descriptors)selfdescriptorsdescriptor_loaders      r   __init__DescriptorLibrary.__init__(  s     $5 (.Br   c                      U R                   U   $ ! [         a     Of = fU R                  (       a!  U R                  U5      nX R                   U'   U$ [        R                  " SU-  5      e)aP  Lookup descriptor by name.

Get descriptor from library by name.  If descriptor is not found will
attempt to find via descriptor loader if provided.

Args:
  definition_name: Definition name to find.

Returns:
  Descriptor that describes definition name.

Raises:
  DefinitionNotFoundError if not descriptor exists for definition name.
z Could not find definition for %s)r   KeyErrorr   r   r   )r   rj   r   s      r   lookup_descriptor#DescriptorLibrary.lookup_descriptor8  sv    	%%o66 		 ##11/BJ2</222_DF Fs    
c                      U R                  U5      n[        U[        5      (       a  UR                  $ UR	                  S5      nUS:  a  gUSU nMQ  )a  Determines the package name for any definition.

Determine the package that any definition name belongs to. May
check parent for package name and will resolve missing
descriptors if provided descriptor loader.

Args:
  definition_name: Definition name to find package for.

rh   r   N)r   rs   r	   ra   rfind)r   rj   r   indexs       r   lookup_package DescriptorLibrary.lookup_packageT  s[     //@J*n55!)))'--c219"1&5"9 r   )__descriptor_loader__descriptors)r5   r6   r7   r8   r9   r   
positionalr   r   r   r   r?   r   r   r   r   r     s5    	 
__Q!#;/ /F8:r   r   )&r9   r   r   r&   apitools.base.protorpcliter   r   __all__r<   r'   
FloatFieldBooleanField
BytesFieldr:   rV   rv   intfloat_DEFAULT_FROM_STRING_MAPr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   objectr   r   r   r   <module>r      s  $M\   
 / +8 3==FE-A  39E- C(** C 	JX%% 	J',h&& ',TI(( I&IX%% I"Dh D!.!H*Z$N(6 7A @ @FK: K:r   