
                  	       j   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSr	Sr
 SS	KJr  SSKr\R                  \	:  a  S
r
SSR!                  \	 V s/ s H  n \" U 5      PM     sn 5      -  rSrSrSrSrSrSrSrSrSrSrSrSrSrSr Sr!Sr"Sr#Sr$Sr%S r&S!r'S"r(S#r)S$r*S%r+S%r,S&r-S&r.\.S-  S-   r/S&r0S'r1S(r2S)r3S*r4S+r5S,r6S-r7S.r8S/r9Sr:S0r;S1r<S2 r=S3 r>S4 r?S5 r@S6 rAS7 rBS8 rCS9 rDS: rE " S; S<\F5      rG " S= S>\H5      rI " S? S@\I5      rJ " SA SB\H5      rK " SC SD\H5      rLSFSE jrMg! \ a     N\ a     Nf = fs  sn f )GzUtilities for converting between v3 and v1 datastore protocol buffers.

This module is internal and should not be used by client applications.
    )absolute_import)datastore_v4_pb)entity_v4_pb)	entity_pbN)   r   r   F)v1TzsCould not import googledatastore. This library must be installed with version >= %s to use the Cloud Datastore API..               r         	   
                                       ZLIBi#  i  d   xyemailauth_domainuser_idinternal_idfederated_identityfederated_provider__key__l @W~l   _3"c                 V   / nU R                  5        H  nUR                  5       (       a  [        UR                  5       5      nO(UR	                  5       (       a  UR                  5       nOSnUR                  UR                  5       < SU< 35        M     SSR                  U5      -  $ )a:  Generates a string representing a key's path.

The output makes no effort to qualify special characters in strings.

The key need not be valid, but if any of the key path elements have
both a name and an ID the name is ignored.

Args:
  v4_key: an entity_v4_pb.Key

Returns:
  a string representing the key's path
 : [%s], )	path_element_listhas_idstridhas_namenameappendkindjoin)v4_keypath_element_stringspath_element
id_or_names       7lib/googlecloudsdk/appengine/datastore/datastore_pbs.pyv4_key_to_stringr=   }   s     ..0l|()j				 	 $$&jjL,=,=,? LM 1 
$))01	11    c                     [        U R                  5       5      S:  d   eU R                  [        U R                  5       5      S-
  5      nUR                  5       =(       d    UR	                  5       $ )zReturns True if a key specifies an ID or name, False otherwise.

Args:
  v4_key: an entity_v4_pb.Key

Returns:
  True if the key specifies an ID or name, False otherwise.
r
   )lenr/   r:   r0   r3   )r8   last_elements     r<   is_complete_v4_keyrB      s`     
V%%'	(A	--	-$$S)A)A)C%Dq%HI,					9,"7"7"99r>   c                    / nU R                    Hg  nUR                  S5      nUS:X  a  [        UR                  5      nOUS:X  a  UR                  nOSnUR                  UR                  < SU< 35        Mi     SSR                  U5      -  $ )a=  Generates a string representing a key's path.

The output makes no effort to qualify special characters in strings.

The key need not be valid, but if any of the key path elements have
both a name and an ID the name is ignored.

Args:
  v1_key: an googledatastore.Key

Returns:
  a string representing the key's path
id_typer2   r4   r+   r,   r-   r.   )path
WhichOneofr1   r2   r4   r5   r6   r7   )v1_keyr9   r:   fieldr;   s        r<   v1_key_to_stringrI      s     kkl##I.E}|'j	&$$jjL,=,=z JK " 
$))01	11r>   c                     [        U R                  5      S:  d   eU R                  [        U R                  5      S-
     nUR                  S5      SL$ )zReturns True if a key specifies an ID or name, False otherwise.

Args:
  v1_key: an googledatastore.Key

Returns:
  True if the key specifies an ID or name, False otherwise.
r
   rD   N)r@   rE   rF   )rG   rA   s     r<   is_complete_v1_keyrK      sM     
V[[	Q		S-12,		 	 	+4	77r>   c                 B   U R                  5       R                  5       S:  d   eU R                  5       R                  5       S   nUR                  5       =(       a    UR	                  5       S:g  =(       d*    UR                  5       =(       a    UR                  5       S:g  $ )zReturns True if a key specifies an ID or name, False otherwise.

Args:
  v3_key: a datastore_pb.Reference

Returns:
  True if the key specifies an ID or name, False otherwise.
r
   r   r+   )rE   element_sizeelement_listr0   r2   r3   r4   )v3_keyrA   s     r<   is_complete_v3_keyrQ      s     
	#	#	%	**	*++-b1, ;\__%6!%; B  "@|'8'8':b'@Cr>   c                     U R                  S5      (       a  U R                  S4$ [        X R                  S5      5      nUR                  U4$ )zReturns the v1 key and entity for a v1 mutation proto, if applicable.

Args:
  v1_mutation: a googledatastore.Mutation

Returns:
  a tuple (googledatastore.Key for this mutation,
           googledatastore.Entity or None if the mutation is a deletion)
deleteN	operation)HasFieldrS   getattrrF   key)v1_mutation	v1_entitys     r<   get_v1_mutation_key_and_entityrZ      sJ     (##t##%;%;K%HII==)##r>   c                     [        U [        R                  5      (       a  g U R                  S5        g! [         a     gf = f)NTutf-8F)
isinstancesix	text_typedecodeUnicodeDecodeError)ss    r<   is_valid_utf8rc      s<    3==!!HHW	 s   4 
A Ac                 (    U (       d  [        U5      eg)zAsserts a conversion condition and raises an error if it's not met.

Args:
  condition: (boolean) condition to enforce
  message: error message

Raises:
  InvalidConversionError: if condition is not met
N)InvalidConversionError)	conditionmessages     r<   check_conversionrh      s     

 
)) 
r>   c                 <    [         U s=:*  =(       a	    [        :*  $ s  $ N)#RFC_3339_MIN_MICROSECONDS_INCLUSIVE#RFC_3339_MAX_MICROSECONDS_INCLUSIVE)microsecondss    r<   is_in_rfc_3339_boundsrn     s(    
- 1 101 2 1 2r>   c                       \ rS rSrSrSrg)re   i  zRaised when conversion fails. N)__name__
__module____qualname____firstlineno____doc____static_attributes__rp   r>   r<   re   re     s    %r>   re   c                   .    \ rS rSrSrSS jrS rS rSrg)	
IdResolveri  zGA class that can handle project id <--> application id transformations.c                 L    0 nU H  nX2U R                  U5      '   M     X l        g)zCreate a new IdResolver.

Args:
 app_ids: A list of application ids with application id shard set. i.e.
     s~my_app or e~my_app.
N)resolve_project_id_resolver_map)selfapp_idsresolver_mapapp_ids       r<   __init__IdResolver.__init__  s,     L6<4**623 %r>   c                 *    UR                  S5      S   $ )zlConverts an application id to a project id.

Args:
  app_id: The application id.
Returns:
  The project id.
~rM   )rsplitr|   r   s     r<   rz   IdResolver.resolve_project_id   s     ==b!!r>   c                 V    [        XR                  ;   SU-  5        U R                  U   $ )zConverts a project id to an application id.

Args:
  project_id: The project id.
Returns:
  The application id.
Raises:
  InvalidConversionError: if the application is unknown for the project id.
z>Cannot determine application id for provided project id: "%s".)rh   r{   r|   
project_ids     r<   resolve_app_idIdResolver.resolve_app_id*  s7     Z#5#55!"# j))r>   )r{   N)rp   )	rq   rr   rs   rt   ru   r   rz   r   rv   rp   r>   r<   rx   rx     s    O
&"*r>   rx   c                   $    \ rS rSrSrS rS rSrg)_IdentityIdResolveri;  z0An IdResolver that resolve app_id == project_id.c                     U$ rj   rp   r   s     r<   rz   &_IdentityIdResolver.resolve_project_id>  s    Mr>   c                     U$ rj   rp   r   s     r<   r   "_IdentityIdResolver.resolve_app_idA  s    r>   rp   N)rq   rr   rs   rt   ru   rz   r   rv   rp   r>   r<   r   r   ;  s    8r>   r   c                   L   \ rS rSrSrS rS rS rS rS r	S7S jr
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S  r"S7S! jr#S" r$S# r%S$ r&S% r'S& r(S' r)S( r*S) r+S* r,S+ r-S, r.S- r/S. r0S/ r1S0 r2S1 r3S2 r4S3 r5S4 r6S5r7g6)8_EntityConverteriE  z Converter for entities and keys.c                     Xl         g)zzCreates a new EntityConverter.

Args:
  id_resolver: an IdResolver object for converting
  project_id <--> application_id
N_id_resolver)r|   id_resolvers     r<   r   _EntityConverter.__init__H  s
     $r>   c                 
   UR                  5         UR                  5       (       a  UR                  5       R                  5       (       a-  UR	                  UR                  5       R                  5       5        UR                  5       R                  5       (       a-  UR                  UR                  5       R                  5       5        UR                  5        H  nUR                  5       R                  5       nUR                  UR                  5       5        UR                  5       (       a  UR                  UR!                  5       5        UR#                  5       (       d  M  UR%                  UR'                  5       5        M     g)zwConverts a v4 Key to a v3 Reference.

Args:
  v4_key: an entity_v4_pb.Key
  v3_ref: an entity_pb.Reference to populate
N)Clearhas_partition_idpartition_idhas_dataset_idset_app
dataset_idhas_namespaceset_name_space	namespacer/   mutable_pathadd_elementset_typer6   r0   set_idr2   r3   set_namer4   )r|   r8   v3_ref
v4_element
v3_elements        r<   v4_to_v3_reference#_EntityConverter.v4_to_v3_referenceQ  s    LLN  					-	-	/	/v**,779:					,	,	.	.f113==?@..0
&&(446j*//+,					*--/*					JOO-. 1r>   c                     / nU H:  n[         R                  " 5       nU R                  X45        UR                  U5        M<     U$ )zConverts a list of v4 Keys to a list of v3 References.

Args:
  v4_keys: a list of entity_v4_pb.Key objects

Returns:
  a list of entity_pb.Reference objects
)r   	Referencer   r5   )r|   v4_keysv3_refsr8   r   s        r<   v4_to_v3_references$_EntityConverter.v4_to_v3_referencesf  B     G""$f
f-nnV  Nr>   c                    UR                  5         UR                  5       (       d  gUR                  5       R                  UR                  5       5        UR	                  5       (       a-  UR                  5       R                  UR	                  5       5        UR                  5       R                  5        H  nUR                  5       nUR                  UR                  5       5        UR                  5       (       a  UR                  UR                  5       5        UR                  5       (       d  M}  UR                  UR!                  5       5        M     g)zwConverts a v3 Reference to a v4 Key.

Args:
  v3_ref: an entity_pb.Reference
  v4_key: an entity_v4_pb.Key to populate
N)r   appmutable_partition_idset_dataset_id
name_spaceset_namespacerE   rO   add_path_elementset_kindtyper0   r   r2   r3   r   r4   )r|   r   r8   r   r   s        r<   v3_to_v4_key_EntityConverter.v3_to_v4_keyv  s     LLN::<<
!00>!!#11&2C2C2EFkkm002
**,j*//+,					*--/*					JOO-. 3r>   c                     / nU H:  n[         R                  " 5       nU R                  X45        UR                  U5        M<     U$ )zConverts a list of v3 References to a list of v4 Keys.

Args:
  v3_refs: a list of entity_pb.Reference objects

Returns:
  a list of entity_v4_pb.Key objects
)r   Keyr   r5   )r|   r   r   r   r8   s        r<   v3_to_v4_keys_EntityConverter.v3_to_v4_keys  sB     G!f
'nnV  Nr>   c           	      &   UR                  5         UR                  5        Hy  nUR                  5       nUR                  5       nUR	                  5       (       a-  UR	                  5        H  nU R                  USX7U5        M     Me  U R                  USX6U5        M{     UR                  5       (       a_  UR                  5       nU R                  XR                  5       5        UR                  5       n	U R                  XR                  5       5        gg)zConverts a v4 Entity to a v3 EntityProto.

Args:
  v4_entity: an entity_v4_pb.Entity
  v3_entity: an entity_pb.EntityProto to populate
  is_projection: True if the v4_entity is from a projection query.
TFN)r   property_listr4   valuelist_value_list)_EntityConverter__add_v3_property_from_v4has_keyrW   r   mutable_keyv3_reference_to_groupmutable_entity_group)
r|   	v4_entity	v3_entityis_projectionv4_propertyproperty_namev4_valuev4_sub_valuer8   r   s
             r<   v4_to_v3_entity _EntityConverter.v4_to_v3_entity  s     OO ..0!&&(m""$h		!	!	#	#$446L

(
(T=	K 7 	&&5-9	F 1 }}f
f&;&;&=>}}f
  )G)G)IJ r>   c                    UR                  5         U R                  UR                  5       UR                  5       5        UR                  5       R	                  5       (       d  UR                  5         0 nUR                  5        H  nU R                  X#US5        M     UR                  5        H  nU R                  X#US5        M     g)zConverts a v3 EntityProto to a v4 Entity.

Args:
  v3_entity: an entity_pb.EntityProto
  v4_entity: an entity_v4_pb.Proto to populate
TFN)	r   r   rW   r   has_app	clear_keyr   +_EntityConverter__add_v4_property_to_entityraw_property_list)r|   r   r   v4_propertiesv3_propertys        r<   v3_to_v4_entity _EntityConverter.v3_to_v4_entity  s     OOimmoy'<'<'>?==?""$$
 M ..0
&&y'+- 1 !224
&&y',. 5r>   c                 x   UR                  5         UR                  5       (       a   UR                  UR                  5       5        gUR	                  5       (       a   UR                  UR                  5       5        gUR                  5       (       a   UR                  UR                  5       5        gUR                  5       (       a   UR                  UR                  5       5        gUR                  5       (       aG  [        R                  " 5       nU R                  UR!                  5       U5        U R#                  X25        gUR%                  5       (       a   UR'                  UR)                  5       5        gUR+                  5       (       a   UR'                  UR-                  5       5        gUR/                  5       (       a   UR'                  UR1                  5       5        gUR3                  5       (       a  UR5                  5       nUR7                  5       nU[8        :X  d
  U[:        :X  a!  U R=                  UUR?                  5       5        gU[@        :X  a!  U RC                  UURE                  5       5        g[        RF                  " 5       nU RI                  XF5        UR'                  URK                  5       5        gURM                  5       (       ak  UR?                  5       nURO                  URQ                  5       RS                  5       5        URU                  URQ                  5       RW                  5       5        gg)zConverts a v4 Value to a v3 PropertyValue.

Args:
  v4_value: an entity_v4_pb.Value
  v3_value: an entity_pb.PropertyValue to populate
N),r   has_boolean_valueset_booleanvalueboolean_valuehas_integer_valueset_int64valueinteger_valuehas_double_valueset_doublevaluedouble_value has_timestamp_microseconds_valuetimestamp_microseconds_valuehas_key_valuer   r   r   	key_value!v3_reference_to_v3_property_valuehas_blob_key_valueset_stringvalueblob_key_valuehas_string_valuestring_valuehas_blob_value
blob_valuehas_entity_valueentity_valuemeaningMEANING_GEORSS_POINTMEANING_PREDEFINED_ENTITY_POINT&_EntityConverter__v4_to_v3_point_valuemutable_pointvalueMEANING_PREDEFINED_ENTITY_USERv4_entity_to_v3_user_valuemutable_uservalueEntityProtor   SerializePartialToStringhas_geo_point_valueset_xgeo_point_valuelatitudeset_y	longitude)r|   r   v3_valuer   v4_entity_value
v4_meaningv3_entity_valuepoint_values           r<   v4_value_to_v3_property_value._EntityConverter.v4_value_to_v3_property_value  ss    NN!!## 6 6 89		#	#	%	%h4467		"	"	$	$x4467		2	2	4	4hCCEF				!	!""$f
h002F;
,,V>		$	$	&	&x6689		"	"	$	$x4467		 	 	"	"x2245		"	"	$	$ --/o##%j
,
,::##O$,$?$?$A	C77''(0(B(B(D	F $//1_>  !I!I!KL		%	%	'	'//1k002;;=>002<<>? r>   c                 "   UR                  5         UR                  5       nUR                  5       nSnUR                  5       (       a  UR                  5       nU R	                  U5      (       d  SnSnO:U[
        R                  R                  :X  a  SnOU R                  UU5      (       d  SnSnU(       a\  U[        :X  aQ  UR                  5       (       a;  SnU[
        R                  R                  :w  a  [
        R                  R                  nOO UR                  5       (       a!  UR                  UR                  5       5        GOUR                  5       (       ab  U[
        R                  R                   :X  a#  UR#                  UR%                  5       5        SnGOUR'                  UR%                  5       5        GOwUR)                  5       (       a!  UR+                  UR-                  5       5        GOAUR/                  5       (       aV  [
        R0                  " 5       nU R3                  UR5                  5       U5        U R7                  XR9                  5       5        GOUR                  5       (       Ga  U[
        R                  R:                  :X  aY  UR=                  5       n	[
        R>                  " 5       n
U
RA                  U	5        U RC                  XRE                  5       5        SnGOIU[
        R                  R                  :X  d  U[
        R                  RF                  :X  aH  URI                  UR=                  5       5        U(       d  U[
        R                  R                  :X  a  SnGOUR=                  5       n[K        U5      (       aF  U[
        R                  RL                  :X  a  URO                  U5        SnGOrURQ                  U5        GO_URI                  U5        U[
        R                  RR                  :w  a  SnGO,URU                  5       (       a  U[V        :X  ak  URY                  5       nUR[                  5       R]                  UR_                  5       5        UR[                  5       Ra                  URc                  5       5        OCU Re                  URY                  5       URE                  5       5        URg                  [h        5        SnO\URk                  5       (       aF  U Rm                  URo                  5       URE                  5       5        URg                  [p        5        SnO U(       a  URg                  [r        5        OU(       a  URg                  U5        X#Ru                  5       :w  a  URw                  U5        gg)zConverts a v3 Property to a v4 Value.

Args:
  v3_property: an entity_pb.Property
  indexed: whether the v3 property is indexed
  v4_value: an entity_v4_pb.Value to populate
NFT)<r   r   r   meaning_uri2_EntityConverter__is_v3_property_value_union_validr   Property
NO_MEANING4_EntityConverter__is_v3_property_value_meaning_validURI_MEANING_ZLIBhas_stringvalueBLOBhas_booleanvalueset_boolean_valuebooleanvaluehas_int64valueGD_WHEN set_timestamp_microseconds_value
int64valueset_integer_valuehas_doublevalueset_double_valuedoublevaluehas_referencevaluer   4_EntityConverter__v3_reference_value_to_v3_referencereferencevaluer   mutable_key_valueENTITY_PROTOstringvaluer   ParsePartialFromStringr   mutable_entity_value
BYTESTRINGset_blob_valuerc   BLOBKEYset_blob_key_valueset_string_valueINDEX_VALUEhas_pointvaluer   
pointvaluemutable_geo_point_valueset_latituder!   set_longituder"   '_EntityConverter__v3_to_v4_point_entityset_meaningr   has_uservaluev3_user_value_to_v4_entity	uservaluer   MEANING_ZLIBindexedset_indexed)r|   r   r:  r   v3_property_value
v3_meaningv3_uri_meaningis_zlib_valuer   serialized_entity_v3r   r   r
  s                r<   v3_property_to_v4_value(_EntityConverter.v3_property_to_v4_value   sb    NN#))+$$&JN  "..0n223DEE jn	y))44	4j667H7AC C jM	+	+,,..-9--222"++00J
 ))++  !2!?!?!AB		)	)	+	+	y))11	111((*	,
""#4#?#?#AB		*	*	,	, 1 = = ?@		-	-	/	/""$f
//

*
*
,f6
 : : <=		*	*	,	,	y))66	60<<>))+	 	(()=>Y(E(E(GH
),,111Y//::: 1 = = ?@jI$6$6$;$;;*(446&&9--555''5J%%l3 
!
!,
/9--999J 
	)	)	+	+	+	+'224((*77H((*88I$$%6%A%A%C%-%B%B%D	F<=j		(	(	*	*
%%&7&A&A&C&.&C&C&EG9:j
<(	:& ""$$7# %r>   c                 <   UR                  5       (       a   S5       eUR                  5         UR                  U5        UR                  5       (       aO  UR	                  5       [
        :X  a7  UR                  [
        5        UR                  S5        UR                  5         gUR                  U5        U R                  XER                  5       5        SnUR                  5       (       a  UR	                  5       nUR                  5       (       a+  UR                  [        R                  R                  5        GOUR                  5       (       a+  UR                  [        R                  R                  5        GO_UR!                  5       (       a  U["        :X  a  UR%                  [&        5        U[        R                  R(                  :X  a  UR+                  5       (       a   OUR+                  5       (       a*  UR                  [        R                  R(                  5        O)UR                  [        R                  R,                  5        SnOUR/                  5       (       aJ  U[0        :w  a?  U[2        :w  a3  U[4        :w  a)  UR                  [        R                  R6                  5        SnO,UR9                  5       (       a  UR                  [0        5        O Ub  UR                  U5        U(       a*  UR                  [        R                  R:                  5        gg)aJ  Converts info from a v4 Property to a v3 Property.

v4_value must not have a list_value.

Args:
  property_name: the name of the property
  is_multi: whether the property contains multiple values
  is_projection: whether the property is projected
  v4_value: an entity_v4_pb.Value
  v3_property: an entity_pb.Property to populate
z#v4 list_value not convertable to v3FN)r   r   r   has_meaningr   MEANING_EMPTY_LISTr5  set_multiplemutable_valuer  r   r   r  r  r   r+  r   r9  set_meaning_urir  r)  r:  r  r   r   r   r   r%  r   r.  )r|   r   is_multir   r   r   r  s          r<   v4_to_v3_property"_EntityConverter.v4_to_v3_propertyt  sX    ''))P+PP)'("2"2"48J"J01u%!X&&&x1J1J1LMJ##%j0022i00889		$	$	&	&i00889		 	 	"	"	|	###$45	y))44	4
 

!
!)"4"4"?"?
@

!
!)"4"4"9"9
:
		"	"	$	$	+	+99<<

!
!)"4"4"A"A
B
		%	%	'	'23 j)i00<<= r>   c                     UR                  5       (       a"  U R                  XUXER                  5       5        gU R                  XUXER                  5       5        g)a2  Adds a v3 Property to an Entity based on information from a v4 Property.

Args:
  property_name: the name of the property
  is_multi: whether the property contains multiple values
  is_projection: whether the property is a projection
  v4_value: an entity_v4_pb.Value
  v3_entity: an entity_pb.EntityProto
N)r:  rJ  add_propertyadd_raw_property)r|   r   rI  r   r   r   s         r<   __add_v3_property_from_v4*_EntityConverter.__add_v3_property_from_v4  sS     
]m%'='='?A ]m%'A'A'CEr>   c                 \    0 nUR                  5        H  nX2UR                  5       '   M     U$ rj   )r   r4   )r|   r   property_mapprops       r<   __build_name_to_v4_property_map0_EntityConverter.__build_name_to_v4_property_map  s.    L'')"&499; *r>   c                 J   UR                  5       nXR;   a  X%   nO%UR                  5       nUR                  U5        XbU'   UR                  5       (       a/  U R	                  X4UR                  5       R                  5       5        gU R	                  X4UR                  5       5        g)a  Adds a v4 Property to an entity or modifies an existing one.

property_map is used to track of properties that have already been added.
The same dict should be used for all of an entity's properties.

Args:
  v4_entity: an entity_v4_pb.Entity
  property_map: a dict of name -> v4_property
  v3_property: an entity_pb.Property to convert to v4 and add to the dict
  indexed: whether the property is indexed
N)r4   rM  r   multiplerA  rG  add_list_value)r|   r   rR  r   r:  r   r   s          r<   __add_v4_property_to_entity,_EntityConverter.__add_v4_property_to_entity  s      $$&M$ /k**,k=)$/=!
"";#.#<#<#>#M#M#OQ "";#.#<#<#>@r>   c                     [        UR                  5       R                  5       S5        UR                  5       R                  5       $ )zReturns an integer value from a v4 Property.

Args:
  v4_property: an entity_v4_pb.Property

Returns:
  an integer

Raises:
  InvalidConversionError: if the property doesn't contain an integer value
z+Property does not contain an integer value.)rh   r   r   r   r|   r   s     r<   __get_v4_integer_value'_EntityConverter.__get_v4_integer_value  s<     [&&(::<BD,,..r>   c                     [        UR                  5       R                  5       S5        UR                  5       R                  5       $ )zReturns a double value from a v4 Property.

Args:
  v4_property: an entity_v4_pb.Property

Returns:
  a double

Raises:
  InvalidConversionError: if the property doesn't contain a double value
z)Property does not contain a double value.)rh   r   r   r   r\  s     r<   __get_v4_double_value&_EntityConverter.__get_v4_double_value  <     [&&(99;@B++--r>   c                     [        UR                  5       R                  5       S5        UR                  5       R                  5       $ )zReturns an string value from a v4 Property.

Args:
  v4_property: an entity_v4_pb.Property

Returns:
  a string

Throws:
  InvalidConversionError: if the property doesn't contain a string value
z)Property does not contain a string value.)rh   r   r   r   r\  s     r<   __get_v4_string_value&_EntityConverter.__get_v4_string_value  rb  r>   c                     [         R                  " 5       nUR                  U5        UR                  5       nUR	                  U5        UR                  U5        U$ )zCreates a single-integer-valued v4 Property.

Args:
  name: the property name
  value: the integer value of the property
  indexed: whether the value should be indexed

Returns:
  an entity_v4_pb.Property
)r   r  r   rG  r;  r  r|   r4   r   r:  r   r   s         r<   __v4_integer_property&_EntityConverter.__v4_integer_property  sP     '')K((*H!u%r>   c                     [         R                  " 5       nUR                  U5        UR                  5       nUR	                  U5        UR                  U5        U$ )zCreates a single-double-valued v4 Property.

Args:
  name: the property name
  value: the double value of the property
  indexed: whether the value should be indexed

Returns:
  an entity_v4_pb.Property
)r   r  r   rG  r;  r  rg  s         r<   __v4_double_property%_EntityConverter.__v4_double_property*  P     '')K((*H!e$r>   c                     [         R                  " 5       nUR                  U5        UR                  5       nUR	                  U5        UR                  U5        U$ )zCreates a single-string-valued v4 Property.

Args:
  name: the property name
  value: the string value of the property
  indexed: whether the value should be indexed

Returns:
  an entity_v4_pb.Property
)r   r  r   rG  r;  r-  rg  s         r<   __v4_string_property%_EntityConverter.__v4_string_property<  rm  r>   c                     UR                  5         U R                  U5      nUR                  U R                  US   5      5        UR	                  U R                  US   5      5        g)zConverts a v4 point Entity to a v3 PointValue.

Args:
  v4_point_entity: an entity_v4_pb.Entity representing a point
  v3_point_value: an entity_pb.Property_PointValue to populate
r!   r"   N)r   /_EntityConverter__build_name_to_v4_property_mapr  %_EntityConverter__get_v4_double_valuer  )r|   v4_point_entityv3_point_valuename_to_v4_propertys       r<   __v4_to_v3_point_value'_EntityConverter.__v4_to_v3_point_valueN  se     >>O""#6s#;<>""#6s#;<>r>   c                 ,   UR                  5         UR                  5       R                  U R                  [        UR                  5       S5      5        UR                  5       R                  U R                  [        UR                  5       S5      5        g)zConverts a v3 UserValue to a v4 user Entity.

Args:
  v3_point_value: an entity_pb.Property_PointValue
  v4_entity: an entity_v4_pb.Entity to populate
FN)r   r   r5   $_EntityConverter__v4_double_propertyPROPERTY_NAME_Xr!   PROPERTY_NAME_Yr"   )r|   ru  r   s      r<   __v3_to_v4_point_entity(_EntityConverter.__v3_to_v4_point_entity\  st     OO$$!!/>3C3C3EuMO$$!!/>3C3C3EuMOr>   c                    UR                  5         U R                  U5      nUR                  U R                  U[           5      5        UR                  U R                  U[           5      5        [        U;   a'  UR                  U R                  U[           5      5        [        U;   a(  UR                  U R                  U[           5      5        OUR                  S5        [        U;   a'  UR                  U R                  U[           5      5        [        U;   a(  UR                  U R                  U[           5      5        gg)zConverts a v4 user Entity to a v3 UserValue.

Args:
  v4_user_entity: an entity_v4_pb.Entity representing a user
  v3_user_value: an entity_pb.Property_UserValue to populate
r   N)r   rr  	set_email%_EntityConverter__get_v4_string_valuePROPERTY_NAME_EMAILset_auth_domainPROPERTY_NAME_AUTH_DOMAINPROPERTY_NAME_USER_IDset_obfuscated_gaiaidPROPERTY_NAME_INTERNAL_ID
set_gaiaid&_EntityConverter__get_v4_integer_value PROPERTY_NAME_FEDERATED_IDENTITYset_federated_identity PROPERTY_NAME_FEDERATED_PROVIDERset_federated_provider)r|   v4_user_entityv3_user_valuerv  s       r<   r   +_EntityConverter.v4_entity_to_v3_user_valuei  s=    >>~ND66/02 3!!$"<"<56#8 9 33))

$
$!"78:; !$77t::
7
8 : ; q!'+>>**

$
$%8.&0 12 (+>>**

$
$%8.&0 12 ?r>   c                    UR                  5         UR                  5       R                  U R                  [        UR                  5       S5      5        UR                  5       R                  U R                  [        UR                  5       S5      5        UR                  5       S:w  aB  UR                  5       R                  U R                  [        UR                  5       S5      5        UR                  5       (       aB  UR                  5       R                  U R                  [        UR                  5       S5      5        UR                  5       (       aB  UR                  5       R                  U R                  [        UR!                  5       S5      5        UR#                  5       (       aC  UR                  5       R                  U R                  [$        UR'                  5       S5      5        gg)zConverts a v3 UserValue to a v4 user Entity.

Args:
  v3_user_value: an entity_pb.Property_UserValue
  v4_entity: an entity_v4_pb.Entity to populate
Fr   N)r   r   r5   $_EntityConverter__v4_string_propertyr  r#   r  r$   gaiaid%_EntityConverter__v4_integer_propertyr  has_obfuscated_gaiaidr  obfuscated_gaiaidhas_federated_identityr  r'   has_federated_providerr  r(   )r|   r  r   s      r<   r7  +_EntityConverter.v3_user_value_to_v4_entity  s    OO$$!!"5}7J7J7L"'	)* $$T%>%>!!!#U&, - "&&t'A'A
#



 
(  **,,&&t'@'@


)
)
+
(  ++--&&t'@'@
*

*
*
,
(  ++--&&t'@'@
*

*
*
,
(  .r>   c                    UR                  5         UR                  S5      (       a  UR                  R                  nU(       a,  U R                  R                  U5      nUR                  U5        UR                  R                  (       a%  UR                  UR                  R                  5        UR                   H  nUR                  5       R                  5       nUR                  UR                  R                  S5      5        UR                  S5      nUS:X  a  UR!                  UR"                  5        M  US:X  d  M  UR%                  UR&                  R                  S5      5        M     g)zzConverts a v1 Key to a v3 Reference.

Args:
  v1_key: an googledatastore.Key
  v3_ref: an entity_pb.Reference to populate
r   r\   rD   r2   r4   N)r   rU   r   r   r   r   r   namespace_idr   rE   r   r   r   r6   encoderF   r   r2   r   r4   )r|   rG   r   r   r   
v1_elementr   rD   s           r<   v1_to_v3_reference#_EntityConverter.v1_to_v3_reference  s    LLN~&&&&11j	""11*=v				)	)f11>>?kk
&&(446j*//009:%%i0g	D*--(fJOO227;< "r>   c                     / nU H:  n[         R                  " 5       nU R                  X45        UR                  U5        M<     U$ )zConverts a list of v1 Keys to a list of v3 References.

Args:
  v1_keys: a list of googledatastore.Key objects

Returns:
  a list of entity_pb.Reference objects
)r   r   r  r5   )r|   v1_keysr   rG   r   s        r<   v1_to_v3_references$_EntityConverter.v1_to_v3_references  r   r>   c                 ~   UR                  5         UR                  5       (       d  gU R                  R                  UR                  5       5      nX2R                  l        UR                  5       (       a  UR                  5       UR                  l        UR                  5       R                  5        H  nUR                  R                  5       nUR                  5       Ul        UR                  5       (       a  UR                  5       Ul        UR                  5       (       d  Ms  UR!                  5       Ul        M     g)zzConverts a v3 Reference to a v1 Key.

Args:
  v3_ref: an entity_pb.Reference
  v1_key: an googledatastore.Key to populate
N)r   r   r   rz   r   r   r   r  rE   rO   addr   r6   r0   r2   r3   r4   )r|   r   rG   r   r   r  s         r<   v3_to_v1_key_EntityConverter.v3_to_v1_key  s     LLN::<<""55fjjlCJ%/")/):):)<f&kkm002
;;??$j")jo					"
					$//+
 3r>   c                     / nU H:  n[         R                  " 5       nU R                  X45        UR                  U5        M<     U$ )zConverts a list of v3 References to a list of v1 Keys.

Args:
  v3_refs: a list of entity_pb.Reference objects

Returns:
  a list of googledatastore.Key objects
)googledatastorer   r  r5   )r|   r   r  r   rG   s        r<   v3_to_v1_keys_EntityConverter.v3_to_v1_keys  sB     G""$f
'nnV  Nr>   c                 8    U R                   R                  U5      $ )z0Converts a string project id to a string app id.)r   r   r   s     r<   project_to_app_id"_EntityConverter.project_to_app_id  s    ++J77r>   c                 8    U R                   R                  U5      $ )z0Converts a string app id to a string project id.)r   rz   r   s     r<   app_to_project_id"_EntityConverter.app_to_project_id   s    //77r>   c                 P    U(       a  UR                  5       $ UR                  5       $ rj   )rM  rN  )r|   r   
is_indexeds      r<   __new_v3_property"_EntityConverter.__new_v3_property  s#    ##%%''))r>   c           	         UR                  5         [        R                  " UR                  5       GH@  u  pEUR	                  S5      (       a  [        UR                  R                  5      S:X  ay  U R                  UUR                  (       + 5      nUR                  UR                  S5      5        UR                  S5        UR                  [        5        UR                  5         M  UR                  R                   H7  nU R                  X'R                  (       + 5      nU R!                  USX7U5        M9     GM  U R                  X%R                  (       + 5      n	U R!                  USX5U	5        GMC     UR	                  S5      (       a[  UR"                  n
U R%                  XR'                  5       5        UR#                  5       nU R)                  XR+                  5       5        gg)zConverts a v1 Entity to a v3 EntityProto.

Args:
  v1_entity: an googledatastore.Entity
  v3_entity: an entity_pb.EntityProto to populate
  is_projection: True if the v1_entity is from a projection query.
array_valuer   r\   FTrW   N)r   r^   	iteritems
propertiesrU   r@   r  values!_EntityConverter__new_v3_propertyexclude_from_indexesr   r  rF  r5  rE  rG  v1_to_v3_propertyrW   r  r   r   r   )r|   rY   r   r   r   v1_value
empty_listv1_sub_valuelist_elementvalue_propertyrG   r   s               r<   v1_to_v3_entity _EntityConverter.v1_to_v3_entity
  s    OO#&==1E1E#F			=	)	)x##**+q0--i2:2O2O.OQ*


m227;
<

!
!%
(

 
 !3
4

"
"
$&2299l11@@@BL""t],P : //888:5->	K' $G, %  }}f
f&;&;&=>}}f
  )G)G)IJ r>   c                    UR                  5         U R                  UR                  5       UR                  5        UR                  5       R                  5       (       d  UR	                  S5        UR                  5        H  nU R                  X#S5        M     UR                  5        H  nU R                  X#S5        M     g)zConverts a v3 EntityProto to a v1 Entity.

Args:
  v3_entity: an entity_pb.EntityProto
  v1_entity: an googledatastore.Proto to populate
rW   TFN)r   r  rW   r   
ClearFieldr   +_EntityConverter__add_v1_property_to_entityr   )r|   r   rY   r   s       r<   v3_to_v1_entity _EntityConverter.v3_to_v1_entity3  s     OOimmoy}}5==?""$$5!
 !..0
&&ytD 1 224
&&yuE 5r>   c                    UR                  5         UR                  S5      nUS:X  a  UR                  UR                  5        gUS:X  a  UR	                  UR
                  5        gUS:X  a  UR                  UR                  5        gUS:X  a9  UR	                  [        R                  R                  UR                  5      5        gUS:X  aC  [        R                  " 5       nU R                  UR                  U5        U R!                  XB5        gUS:X  a+  UR#                  UR$                  R'                  S5      5        gUS	:X  a  UR#                  UR(                  5        gUS
:X  a  UR*                  nUR,                  nU[.        :X  a!  U R1                  UUR3                  5       5        g[        R4                  " 5       nU R7                  XW5        UR#                  UR9                  5       5        gUS:X  a[  UR;                  5       nUR=                  UR>                  R@                  5        URC                  UR>                  RD                  5        gUS:X  a  gg)zConverts a v1 Value to a v3 PropertyValue.

Args:
  v1_value: an googledatastore.Value
  v3_value: an entity_pb.PropertyValue to populate

value_typer   r   r   timestamp_valuer   r   r\   r   r   r  
null_valueN)#r   rF   r   r   r   r   r   r   r  helpermicros_from_timestampr  r   r   r  r   r   r   r   r  r   r   r   r   v1_entity_to_v3_user_valuer   r   r  r   r   r  r  r  r  r  )	r|   r  r  rH   r   v1_entity_value
v1_meaningr	  r
  s	            r<   v1_value_to_v3_property_value._EntityConverter.v1_value_to_v3_property_valueH  s    NN-E 6 67	/	!h445	.	 x445	#	#

 
 
6
6&&() 
+	""$f
h00&9
,,V>	.	 x44;;GDE	,	x223	.	  --o##j	5	5''(0(B(B(D	F $//1_>  !I!I!KL	#	#//1k0099:00::;	,	
 r>   c                 l
   UR                  5         UR                  5       nUR                  5       nSnUR                  5       (       a  UR                  5       nU R	                  U5      (       d  SnSnO:U[
        R                  R                  :X  a  SnOU R                  UU5      (       d  SnSnU(       a\  U[        :X  aQ  UR                  5       (       a;  SnU[
        R                  R                  :w  a  [
        R                  R                  nOO UR                  5       [
        R                  R                  :X  a)  UR                  R                  R                  / 5        SnGOUR!                  5       (       a  UR#                  5       Ul        GOfUR'                  5       (       a  U[
        R                  R(                  :X  aZ  [+        UR-                  5       5      (       a<  [.        R0                  R3                  UR-                  5       UR4                  5        SnGOUR-                  5       Ul        GOUR9                  5       (       a  UR;                  5       Ul        GOUR?                  5       (       aR  [
        R@                  " 5       nU RC                  URE                  5       U5        U RG                  XRH                  5        GO/UR                  5       (       Ga<  U[
        R                  RJ                  :X  aU  URM                  5       n	[
        RN                  " 5       n
U
RQ                  U	5        U RS                  XRT                  5        SnGOU[
        R                  R                  :X  d  U[
        R                  RV                  :X  a>  URM                  5       Ul,        U(       d  U[
        R                  R                  :X  a  SnGO,URM                  5       n[[        U5      (       a  Xl.        GOXl,        U[
        R                  R^                  :w  a  SnOURa                  5       (       af  U[b        :w  a  [d        Ul        URg                  5       nURi                  5       URj                  l6        URo                  5       URj                  l8        SnObURs                  5       (       a8  U Ru                  URw                  5       URT                  5        [x        Ul        SnO[.        Rz                  Ul>        U(       a  [~        Ul        OU(       a  XSl        X#R                  :X  a  U(       + Ul@        gg)zConverts a v3 Property to a v1 Value.

Args:
  v3_property: an entity_pb.Property
  indexed: whether the v3 property is indexed
  v1_value: an googledatastore.Value to populate
NFT)Ar   r   r   r  r  r   r  r  r  r  r  r  
EMPTY_LISTr  r  extendr  r  r   r  r  rn   r  r  r  micros_to_timestampr  r   r  r   r   r!  r   r"  r#  r  r   r%  r&  r   r'  r  r   r)  r   rc   r   r.  r/  r    MEANING_POINT_WITHOUT_V3_MEANINGr0  r!   r  r  r"   r  r6  v3_user_value_to_v1_entityr8  r   
NULL_VALUEr  r9  r  )r|   r   r:  r  r<  r=  r>  r?  r   r@  r   r   r
  s                r<   v3_property_to_v1_value(_EntityConverter.v3_property_to_v1_valuew  s    NN#))+$$&JN  "..0n223DEE jn	y))44	4j667H7AC C jM	+	+,,..-9--222"++00J
 	 2 2 = ==!!((,j		+	+	-	-0==?h		)	)	+	+
	**22
2#$5$@$@$BCC22((*H,D,D	F
!2!=!=!?		*	*	,	,/;;=h		-	-	/	/""$f
//

*
*
,f6
 2 23		*	*	,	,	y))66	60<<>))+	 	(()=>Y(=(=>
),,111Y//:::/;;=jI$6$6$;$;;*(446&&".
 !-
9--999J 
	)	)	+	+	+	+;%002k*5--/h'+6==?h(j		(	(	*	*
%%&7&A&A&C&.&;&;=7hj ,66h%h	# ///*1kh# 0r>   c                    UR                  S5      nUS:X  a   S5       eUR                  5         UR                  UR                  S5      5        UR	                  U5        U R                  XER                  5       5        SnUR                  (       a  UR                  nUS:X  a+  UR                  [        R                  R                  5        GO_US:X  a  U[        :X  a  UR                  [        5        U[        R                  R                  :X  a  UR                   (       d   GOUR                   (       d*  UR                  [        R                  R                  5        O)UR                  [        R                  R"                  5        SnOUS:X  a6  U[$        :w  a)  UR                  [        R                  R&                  5        SnOeUS	:X  a"  U[(        :w  a  UR                  [*        5        SnO=US
:X  a6  U[,        :X  a+  UR                  [        R                  R                  5        SnO Ub  UR                  U5        U(       a*  UR                  [        R                  R.                  5        gg)aX  Converts info from a v1 Property to a v3 Property.

v1_value must not have an array_value.

Args:
  property_name: the name of the property, unicode
  is_multi: whether the property contains multiple values
  is_projection: whether the property is projected
  v1_value: an googledatastore.Value
  v3_property: an entity_pb.Property to populate
r  r  z$v1 array_value not convertable to v3r\   Nr  r   r   r  r   )rF   r   r   r  rF  r  rG  r   r5  r   r  r  r9  rH  r  r)  r  r  r   r%  r  r   MEANING_NON_RFC_3339_TIMESTAMPr.  )r|   r   rI  r   r  r   v1_value_typer  s           r<   r  "_EntityConverter.v1_to_v3_property  s    ''5M%:::U--g67X&&&x1J1J1LMJ##j))i00889	,	&	|	###$45	y))44	4,,
 ,,

!
!)"4"4"?"?
@

!
!)"4"4"9"9
:
	.	(	5	5	 2 2 ? ?@j	+	+	7	7 45j	/	)	5	5	 2 2 : :;
 j)i00<<= r>   c                     UR                  5       nUR                  U   nUR                  5       (       a5  U R                  X#UR                  R
                  R                  5       5        gU R                  X#U5        g)zAdds a v1 Property to an entity or modifies an existing one.

Args:
  v1_entity: an googledatastore.Entity
  v3_property: an entity_pb.Property to convert to v1 and add to the dict
  indexed: whether the property is indexed
N)r4   r  rW  r  r  r  r  )r|   rY   r   r:  r   r  s         r<   __add_v1_property_to_entity,_EntityConverter.__add_v1_property_to_entity&  sl      $$&M##M2H
"";#+#7#7#>#>#B#B#DF "";Br>   c                 P    [        UR                  S5      S5        UR                  $ )zReturns an integer value from a v1 Value.

Args:
  v1_value: a googledatastore.Value

Returns:
  an integer

Raises:
  InvalidConversionError: if the value doesn't contain an integer value
r   z(Value does not contain an integer value.)rh   rU   r   r|   r  s     r<   __get_v1_integer_value'_EntityConverter.__get_v1_integer_value6  s)     X&&7?A!!!r>   c                 P    [        UR                  S5      S5        UR                  $ )zReturns a double value from a v1 Value.

Args:
  v1_value: an googledatastore.Value

Returns:
  a double

Raises:
  InvalidConversionError: if the value doesn't contain a double value
r   z&Value does not contain a double value.)rh   rU   r   r  s     r<   __get_v1_double_value&_EntityConverter.__get_v1_double_valueF  s(     X&&~6=?   r>   c                 n    [        UR                  S5      S5        UR                  R                  S5      $ )zReturns an string value from a v1 Value.

Args:
  v1_value: an googledatastore.Value

Returns:
  a string

Throws:
  InvalidConversionError: if the value doesn't contain a string value
r   z&Value does not contain a string value.r\   )rh   rU   r   r  r  s     r<   __get_v1_string_value&_EntityConverter.__get_v1_string_valueV  s3     X&&~6=?  ''00r>   c                 F    UR                   U   nU(       + Ul        X5l        g)zPopulates a single-integer-valued v1 Property.

Args:
  entity: the entity to populate
  name: the name of the property to populate
  value: the integer value of the property
  indexed: whether the value should be indexed
N)r  r  r   r|   entityr4   r   r:  r  s         r<   __v1_integer_property&_EntityConverter.__v1_integer_propertyf  s$       &H(/KH!"r>   c                 F    UR                   U   nU(       + Ul        X5l        g)zPopulates a single-double-valued v1 Property.

Args:
  entity: the entity to populate
  name: the name of the property to populate
  value: the double value of the property
  indexed: whether the value should be indexed
N)r  r  r   r  s         r<   __v1_double_property%_EntityConverter.__v1_double_propertys  $       &H(/KH!!r>   c                 F    UR                   U   nU(       + Ul        X5l        g)zPopulates a single-string-valued v1 Property.

Args:
  entity: the entity to populate
  name: the name of the property to populate
  value: the string value of the property
  indexed: whether the value should be indexed
N)r  r  r   r  s         r<   __v1_string_property%_EntityConverter.__v1_string_property  r  r>   c                    UR                  5         UR                  nUR                  U R                  U[           5      5        UR                  U R                  U[           5      5        [        U;   a'  UR                  U R                  U[           5      5        [        U;   a(  UR                  U R                  U[           5      5        OUR                  S5        [        U;   a'  UR                  U R                  U[           5      5        [        U;   a(  UR                  U R                  U[           5      5        gg)zConverts a v1 user Entity to a v3 UserValue.

Args:
  v1_user_entity: an googledatastore.Entity representing a user
  v3_user_value: an entity_pb.Property_UserValue to populate
r   N)r   r  r  %_EntityConverter__get_v1_string_valuer  r  r  r  r  r  r  &_EntityConverter__get_v1_integer_valuer  r  r  r  )r|   v1_user_entityr  r  s       r<   r  +_EntityConverter.v1_entity_to_v3_user_value  s-    **JD66&') *!!$"<"<,-#/ 0
*))

$
$Z0E%F
GI J.t::
.
/ 1 2 q!':5**

$
$Z.&0 12 (:5**

$
$Z.&0 12 6r>   c                    UR                  5         U R                  U[        UR                  5       S5        U R                  U[        UR                  5       S5        UR                  5       S:w  a&  U R                  U[        UR                  5       S5        UR                  5       (       a&  U R                  U[        UR                  5       S5        UR                  5       (       a&  U R                  U[        UR                  5       S5        UR                  5       (       a'  U R                  U[         UR#                  5       S5        gg)zConverts a v3 UserValue to a v1 user Entity.

Args:
  v3_user_value: an entity_pb.Property_UserValue
  v1_entity: an googledatastore.Entity to populate
Fr   N)r   $_EntityConverter__v1_string_propertyr  r#   r  r$   r  %_EntityConverter__v1_integer_propertyr  r  r  r  r  r  r'   r  r  r(   )r|   r  rY   s      r<   r  +_EntityConverter.v3_user_value_to_v1_entity  s(    OOi)<+113U<i)B+7795B "
  

#



 
	
 **,,




)
)
+
	
 ++--


*

*
*
,
	
 ++--


*

*
*
,
	 .r>   c                     UR                  5       UR                  5       -   UR                  5       -   UR                  5       -   UR	                  5       -   UR                  5       -   UR                  5       -   nUS:*  $ )z6Returns True if the v3 PropertyValue's union is valid.r
   )r  r  r  r!  r  r/  r6  )r|   r<  num_sub_valuess      r<   "__is_v3_property_value_union_valid3_EntityConverter.__is_v3_property_value_union_valid  s    '88:)88:;)99;< *<<>? *99;	<
 *88:; *779:N Qr>   c           	        ^ S nU4S jnU4S jnU4S jnS n0 [         R                  R                  U_[         R                  R                  U_[         R                  R                  U_[         R                  R
                  U_[         R                  R                  U_[         R                  R                  U_[         R                  R                  U_[         R                  R                  U_[         R                  R                  U_[         R                  R                  U_[         R                  R                  U_[         R                  R                  U_[         R                  R                  U_[         R                  R                  U_[         R                  R                   U_[         R                  R"                  U_[         R                  R$                  U_[         R                  R&                  U[         R                  R(                  U[         R                  R*                  U[         R                  R,                  U0EnUn	UR/                  X)5      " 5       $ )zFReturns True if the v3 PropertyValue's type value matches its meaning.c                      g)NTrp   rp   r>   r<   
ReturnTrueI_EntityConverter.__is_v3_property_value_meaning_valid.<locals>.ReturnTrue  s    r>   c                  $   > T R                  5       $ rj   )r  r<  s   r<   HasStringValueM_EntityConverter.__is_v3_property_value_meaning_valid.<locals>.HasStringValue  s    ..00r>   c                  $   > T R                  5       $ rj   )r  r  s   r<   HasInt64ValueL_EntityConverter.__is_v3_property_value_meaning_valid.<locals>.HasInt64Value      --//r>   c                  $   > T R                  5       $ rj   )r/  r  s   r<   HasPointValueL_EntityConverter.__is_v3_property_value_meaning_valid.<locals>.HasPointValue  r  r>   c                      g)NFrp   rp   r>   r<   ReturnFalseJ_EntityConverter.__is_v3_property_value_meaning_valid.<locals>.ReturnFalse  s    r>   )r   r  r  r.  r  TEXTr)  ATOM_CATEGORY	ATOM_LINK
ATOM_TITLEATOM_CONTENTATOM_SUMMARYATOM_AUTHORGD_EMAILGD_IMGD_PHONENUMBERGD_POSTALADDRESSr+  r%  r  	GD_RATINGGEORSS_POINTr  get)
r|   r<  r=  r
  r  r  r  r  value_checkersdefaults
    `        r<   $__is_v3_property_value_meaning_valid5_EntityConverter.__is_v3_property_value_meaning_valid  s   100%%z&&
 	 		
 	%%~ 	((. 	$$n 	%%~ 	'' 	'' 	&& 	##^ 	  . 	))> 	++^  	""N!" 	''#$ 	""M$$m''%%z+N. Gj244r>   c                     UR                  5       nUR                  5       S:  d   eUR                  UR                  5       S-
  5      nUR                  5       =(       d    UR	                  5       $ )zDetermines if a v3 Reference specifies an ID or name.

Args:
  v3_ref: an entity_pb.Reference

Returns:
  boolean: True if the last path element specifies an ID or name.
r
   )rE   rN   elementr0   r3   )r|   r   rE   rA   s       r<   __v3_reference_has_id_or_name._EntityConverter.__v3_reference_has_id_or_name  s_     ;;=D!###<< 1 1 3a 78L ;L$9$9$;;r>   c                     UR                  5         UR                  5       nUR                  5       S:  d   eUR                  5       R	                  UR                  S5      5        g)a  Converts a v3 Reference to a v3 Path representing the entity group.

The entity group is represented as an entity_pb.Path containing only the
first element in the provided Reference.

Args:
  v3_ref: an entity_pb.Reference
  group: an entity_pb.Path to populate
r
   r   N)r   rE   rN   r   CopyFromr-  )r|   r   grouprE   s       r<   r   &_EntityConverter.v3_reference_to_group  sN     
KKM;;=D!###	  a1r>   c                    UR                  5         UR                  5       nUR                  5       (       a  UR                  UR	                  5       5        UR                  5       (       a  UR                  UR                  5       5        UR                  5       R                  5        H  nUR                  5       nUR                  5       (       a  UR                  UR                  5       5        UR                  5       (       a  UR                  UR!                  5       5        UR#                  5       (       d  M  UR%                  UR'                  5       5        M     g)zConverts a v3 Reference to a v3 PropertyValue.

Args:
  v3_ref: an entity_pb.Reference
  v3_property_value: an entity_pb.PropertyValue to populate
N)r   mutable_referencevaluer   r   r   has_name_spacer   r   rE   rO   add_pathelementhas_typer   r   r0   r   r2   r3   r   r4   )r|   r   r<  reference_valuev3_path_elementv3_ref_value_path_elements         r<   r   2_EntityConverter.v3_reference_to_v3_property_value!  s     '>>@O~~fjjl+$$V%6%6%89!;;=557"1"A"A"C		!	!	#	#!**?+?+?+AB				!	!!((););)=>		!	!	#	#!**?+?+?+AB 8r>   c                    UR                  5         UR                  5       (       a  UR                  UR                  5       5        UR	                  5       (       a  UR                  UR                  5       5        UR                  5        H  nUR                  5       R                  5       nUR                  5       (       a  UR                  UR                  5       5        UR                  5       (       a  UR                  UR                  5       5        UR!                  5       (       d  M  UR#                  UR%                  5       5        M     g)zConverts a v3 ReferenceValue to a v3 Reference.

Args:
  v3_ref_value: an entity_pb.PropertyValue_ReferenceValue
  v3_ref: an entity_pb.Reference to populate
N)r   r   r   r   r6  r   r   pathelement_listr   r   r8  r   r   r0   r   r2   r3   r   r4   )r|   v3_ref_valuer   r;  r:  s        r<   $__v3_reference_value_to_v3_reference5_EntityConverter.__v3_reference_value_to_v3_reference7  s     LLNnn\%%'(""$$L3356%1%B%B%D!++-99;o	"	+	+	-	-  !:!?!?!AB	"	)	)	+	+8;;=>	"	+	+	-	-  !:!?!?!AB &Er>   r   N)F)8rq   rr   rs   rt   ru   r   r   r   r   r   r   r   r  rA  rJ  r   rr  r   r  rs  r  r  rz  r  r   r4  r   r7  r  r  r  r  r  r  r  r  r  r  r  r  r  r  %_EntityConverter__get_v1_double_valuer  r  $_EntityConverter__v1_double_propertyr  r  r  r  r  -_EntityConverter__v3_reference_has_id_or_namer   r   r"  rv   rp   r>   r<   r   r   E  s   ($/* /* :.0.`r$h>>BE$@6/ . . $$$>O2B"H=0 ,, 88*'RF*-^p2d;>zC " ! 1 #""2@$L	$5L<2C,Cr>   r   c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)_QueryConverteriM  z%Base converter for v3 and v1 queries.c                     Xl         g rj   _entity_converter)r|   entity_converters     r<   r   _QueryConverter.__init__P  s    -r>   c                     U R                   $ rj   rH  )r|   s    r<   get_entity_converter$_QueryConverter.get_entity_converterS  s    !!!r>   c                    [        UR                  5       S:H  S5        [        UR                  5       S:*  SUR                  5       -  5        UR                  5         UR                  5       Ul        UR	                  S5      R                  5       UR                  l        U R                  R                  UR	                  S5      SUR                  5        g)zConverts a v3 Filter to a v1 PropertyFilter.

Args:
  v3_filter: a datastore_pb.Filter
  v1_property_filter: a googledatastore.PropertyFilter to populate

Raises:
  InvalidConversionError if the filter cannot be converted
r
   invalid filterr   unsupported filter op: %dr   TN)	rh   property_sizeopr   propertyr4   rI  r  r   )r|   	v3_filterv1_property_filters      r<    _v3_filter_to_v1_property_filter0_QueryConverter._v3_filter_to_v1_property_filterV  s     Y,,.!3%'Y\\^q(09<<>AC%LLN'0'9'9!'<'A'A'C$221t%7%=%=?r>   c                    UR                  5         UR                  UR                  5       =(       a    [        R                  R
                  =(       d    [        R                  R                  5        UR                  nUR                  [        5        UR                  5       (       a?  U R                  R                  UR                  5       UR                  R                  5        g[        R                   UR                  l        g)zConverts a v3 Query to a v1 ancestor PropertyFilter.

Args:
  v3_query: a datastore_pb.Query
  v1_property_filter: a googledatastore.PropertyFilter to populate
N)r   set_operatorshallowr  PropertyFilter
HAS_PARENTHAS_ANCESTORrT  r   PROPERTY_NAME_KEYhas_ancestorrI  r  ancestorr   r$  r  r  )r|   v3_queryrV  rS  s       r<   _v3_query_to_v1_ancestor_filter/_QueryConverter._v3_query_to_v1_ancestor_filterj  s     ## 	2&&11	4&&335 &&DMM#$
))





"
"
4
46 -<,F,F)r>   c                     UR                  5       UR                   l        UR                  5       (       a  UR                  5       Ul        gg)zConverts a v3 Query order to a v1 PropertyOrder.

Args:
  v3_order: a datastore_pb.Query.Order
  v1_order: a googledatastore.PropertyOrder to populate
N)rT  r4   has_direction	direction)r|   v3_orderv1_orders      r<   v3_order_to_v1_order$_QueryConverter.v3_order_to_v1_order  s@     &..0H#--/h  r>   c                    [        UR                  5       S:H  S5        [        UR                  5       S:*  SUR                  5       -  5        UR                  5         UR	                  UR                  5       5        UR                  5       R                  UR                  S5      R                  5       5        U R                  R                  UR                  S5      SUR                  5       5        g)zConverts a v3 Filter to a v4 PropertyFilter.

Args:
  v3_filter: a datastore_pb.Filter
  v4_property_filter: a datastore_v4_pb.PropertyFilter to populate

Raises:
  InvalidConversionError if the filter cannot be converted
r
   rP  r   rQ  r   TN)rh   rR  rS  r   rZ  mutable_propertyr   rT  r4   rI  rA  rG  )r|   rU  v4_property_filters      r<    _v3_filter_to_v4_property_filter0_QueryConverter._v3_filter_to_v4_property_filter  s     Y,,.!3%'Y\\^q(09<<>AC##ILLN3'')2293E3Ea3H3M3M3OP221t%7%E%E%GIr>   c                 L   UR                  5         UR                  [        R                  R                  5        UR                  5       nUR                  [        5        U R                  R                  UR                  5       UR                  5       R                  5       5        g)zConverts a v3 Query to a v4 ancestor PropertyFilter.

Args:
  v3_query: a datastore_pb.Query
  v4_property_filter: a datastore_v4_pb.PropertyFilter to populate
N)r   rZ  r   r\  r^  rm  r   r_  rI  r   ra  rG  r$  )r|   rb  rn  rS  s       r<   _v3_query_to_v4_ancestor_filter/_QueryConverter._v3_query_to_v4_ancestor_filter  s~     ##&&335..0DMM#$''((*<<>@r>   c                     UR                  5       R                  UR                  5       5        UR                  5       (       a   UR	                  UR                  5       5        gg)zConverts a v3 Query order to a v4 PropertyOrder.

Args:
  v3_order: a datastore_pb.Query.Order
  v4_order: a datastore_v4_pb.PropertyOrder to populate
N)rm  r   rT  rf  set_directionrg  )r|   rh  v4_orders      r<   v3_order_to_v4_order$_QueryConverter.v3_order_to_v4_order  sO     (():):)<=X//12  r>   rH  N)rq   rr   rs   rt   ru   r   rM  rW  rc  rj  ro  rr  rw  rv   rp   r>   r<   rF  rF  M  s0    -."?(G*	0I(@ 	3r>   rF  c                 >    U =(       d
    [        5       n [        U 5      $ )ztReturns a converter for v3 and v1 entities and keys.

Args:
  id_resolver: An IdResolver for project id resolution.
)r   r   )r   s    r<   rM  rM    s     424+	+	&&r>   rj   )Nru   
__future__r   "googlecloudsdk.appengine.datastorer   r   2googlecloudsdk.appengine.googlestorage.onestore.v3r   r^   _MIN_CLOUD_DATASTORE_VERSION_CLOUD_DATASTORE_ENABLEDr  r   VERSIONImportErrorAttributeErrorr7   r1   MISSING_CLOUD_DATASTORE_MESSAGEMEANING_ATOM_CATEGORYMEANING_URLMEANING_ATOM_TITLEMEANING_ATOM_CONTENTMEANING_ATOM_SUMMARYMEANING_ATOM_AUTHORr  MEANING_GD_EMAILr   MEANING_GD_IMMEANING_GD_PHONENUMBERMEANING_GD_POSTALADDRESSMEANING_PERCENTMEANING_TEXTMEANING_BYTESTRINGMEANING_BLOBKEYMEANING_INDEX_ONLYr   r   r9  r  rE  r  MAX_URL_CHARSMAX_INDEXED_STRING_CHARSMAX_INDEXED_BLOB_BYTESMAX_PARTITION_ID_LENGTHMAX_DATASET_ID_SECTION_LENGTHMAX_DATASET_ID_LENGTHMAX_KEY_PATH_LENGTHr{  r|  r  r  r  r  r  r  r_  DEFAULT_GAIA_IDrk   rl   r=   rB   rI   rK   rQ   rZ   rc   rh   rn   	Exceptionre   objectrx   r   r   rF  rM  )vs   0r<   <module>r     s!  $& ' > ; H 
(   
  <<#4HH:;:c!f:;<=        !"       !# "$ #%          #  69A=     ) ! ) #7  #7     'A #&I #24:268C$"*2Y 
'* '*T* ECv ECP(j3f j3Z'M4    <s   D D0
D-%D-,D-