<s> """<STR_LIT>""" <EOL> from google . appengine . datastore import entity_pb <EOL> from google . appengine . datastore import datastore_v4_pb <EOL> from google . appengine . datastore import entity_v4_pb <EOL> _MIN_CLOUD_DATASTORE_VERSION = ( <NUM_LIT:4> , <NUM_LIT:0> , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> _CLOUD_DATASTORE_ENABLED = False <EOL> try : <EOL> import googledatastore <EOL> if googledatastore . VERSION >= _MIN_CLOUD_DATASTORE_VERSION : <EOL> _CLOUD_DATASTORE_ENABLED = True <EOL> except ImportError : <EOL> pass <EOL> except AttributeError : <EOL> pass <EOL> MISSING_CLOUD_DATASTORE_MESSAGE = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> '<STR_LIT:.>' . join ( [ str ( v ) for v in _MIN_CLOUD_DATASTORE_VERSION ] ) ) <EOL> MEANING_ATOM_CATEGORY = <NUM_LIT:1> <EOL> MEANING_URL = <NUM_LIT:2> <EOL> MEANING_ATOM_TITLE = <NUM_LIT:3> <EOL> MEANING_ATOM_CONTENT = <NUM_LIT:4> <EOL> MEANING_ATOM_SUMMARY = <NUM_LIT:5> <EOL> MEANING_ATOM_AUTHOR = <NUM_LIT:6> <EOL> MEANING_NON_RFC_3339_TIMESTAMP = <NUM_LIT:7> <EOL> MEANING_GD_EMAIL = <NUM_LIT:8> <EOL> MEANING_GEORSS_POINT = <NUM_LIT:9> <EOL> MEANING_GD_IM = <NUM_LIT:10> <EOL> MEANING_GD_PHONENUMBER = <NUM_LIT:11> <EOL> MEANING_GD_POSTALADDRESS = <NUM_LIT:12> <EOL> MEANING_PERCENT = <NUM_LIT> <EOL> MEANING_TEXT = <NUM_LIT:15> <EOL> MEANING_BYTESTRING = <NUM_LIT:16> <EOL> MEANING_BLOBKEY = <NUM_LIT> <EOL> MEANING_INDEX_ONLY = <NUM_LIT> <EOL> MEANING_PREDEFINED_ENTITY_USER = <NUM_LIT:20> <EOL> MEANING_PREDEFINED_ENTITY_POINT = <NUM_LIT> <EOL> MEANING_ZLIB = <NUM_LIT> <EOL> MEANING_POINT_WITHOUT_V3_MEANING = <NUM_LIT> <EOL> MEANING_EMPTY_LIST = <NUM_LIT> <EOL> URI_MEANING_ZLIB = '<STR_LIT>' <EOL> MAX_URL_CHARS = <NUM_LIT> <EOL> MAX_INDEXED_STRING_CHARS = <NUM_LIT> <EOL> MAX_INDEXED_BLOB_BYTES = <NUM_LIT> <EOL> MAX_PARTITION_ID_LENGTH = <NUM_LIT:100> <EOL> MAX_DATASET_ID_SECTION_LENGTH = <NUM_LIT:100> <EOL> MAX_DATASET_ID_LENGTH = MAX_DATASET_ID_SECTION_LENGTH * <NUM_LIT:3> + <NUM_LIT:2> <EOL> MAX_KEY_PATH_LENGTH = <NUM_LIT:100> <EOL> PROPERTY_NAME_X = '<STR_LIT:x>' <EOL> PROPERTY_NAME_Y = '<STR_LIT:y>' <EOL> PROPERTY_NAME_EMAIL = '<STR_LIT:email>' <EOL> PROPERTY_NAME_AUTH_DOMAIN = '<STR_LIT>' <EOL> PROPERTY_NAME_USER_ID = '<STR_LIT>' <EOL> PROPERTY_NAME_INTERNAL_ID = '<STR_LIT>' <EOL> PROPERTY_NAME_FEDERATED_IDENTITY = '<STR_LIT>' <EOL> PROPERTY_NAME_FEDERATED_PROVIDER = '<STR_LIT>' <EOL> PROPERTY_NAME_KEY = '<STR_LIT>' <EOL> DEFAULT_GAIA_ID = <NUM_LIT:0> <EOL> RFC_3339_MIN_MICROSECONDS_INCLUSIVE = - <NUM_LIT> * <NUM_LIT:1000> * <NUM_LIT:1000> <EOL> RFC_3339_MAX_MICROSECONDS_INCLUSIVE = <NUM_LIT> * <NUM_LIT:1000> * <NUM_LIT:1000> + <NUM_LIT> <EOL> def v4_key_to_string ( v4_key ) : <EOL> """<STR_LIT>""" <EOL> path_element_strings = [ ] <EOL> for path_element in v4_key . path_element_list ( ) : <EOL> if path_element . has_id ( ) : <EOL> id_or_name = str ( path_element . id ( ) ) <EOL> elif path_element . has_name ( ) : <EOL> id_or_name = path_element . name ( ) <EOL> else : <EOL> id_or_name = '<STR_LIT>' <EOL> path_element_strings . append ( '<STR_LIT>' % ( path_element . kind ( ) , id_or_name ) ) <EOL> return '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( path_element_strings ) <EOL> def is_complete_v4_key ( v4_key ) : <EOL> """<STR_LIT>""" <EOL> assert len ( v4_key . path_element_list ( ) ) >= <NUM_LIT:1> <EOL> last_element = v4_key . path_element ( len ( v4_key . path_element_list ( ) ) - <NUM_LIT:1> ) <EOL> return last_element . has_id ( ) or last_element . has_name ( ) <EOL> def v1_key_to_string ( v1_key ) : <EOL> """<STR_LIT>""" <EOL> path_element_strings = [ ] <EOL> for path_element in v1_key . path : <EOL> field = path_element . WhichOneof ( '<STR_LIT>' ) <EOL> if field == '<STR_LIT:id>' : <EOL> id_or_name = str ( path_element . id ) <EOL> elif field == '<STR_LIT:name>' : <EOL> id_or_name = path_element . name <EOL> else : <EOL> id_or_name = '<STR_LIT>' <EOL> path_element_strings . append ( '<STR_LIT>' % ( path_element . kind , id_or_name ) ) <EOL> return '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( path_element_strings ) <EOL> def is_complete_v1_key ( v1_key ) : <EOL> """<STR_LIT>""" <EOL> assert len ( v1_key . path ) >= <NUM_LIT:1> <EOL> last_element = v1_key . path [ len ( v1_key . path ) - <NUM_LIT:1> ] <EOL> return last_element . WhichOneof ( '<STR_LIT>' ) is not None <EOL> def is_complete_v3_key ( v3_key ) : <EOL> """<STR_LIT>""" <EOL> assert v3_key . path ( ) . element_size ( ) >= <NUM_LIT:1> <EOL> last_element = v3_key . path ( ) . element_list ( ) [ - <NUM_LIT:1> ] <EOL> return ( ( last_element . has_id ( ) and last_element . id ( ) != <NUM_LIT:0> ) or <EOL> ( last_element . has_name ( ) and last_element . name ( ) != '<STR_LIT>' ) ) <EOL> def get_v1_mutation_key_and_entity ( v1_mutation ) : <EOL> """<STR_LIT>""" <EOL> if v1_mutation . HasField ( '<STR_LIT>' ) : <EOL> return v1_mutation . delete , None <EOL> else : <EOL> v1_entity = getattr ( v1_mutation , v1_mutation . WhichOneof ( '<STR_LIT>' ) ) <EOL> return v1_entity . key , v1_entity <EOL> def is_valid_utf8 ( s ) : <EOL> if isinstance ( s , unicode ) : <EOL> return True <EOL> try : <EOL> s . decode ( '<STR_LIT:utf-8>' ) <EOL> return True <EOL> except UnicodeDecodeError : <EOL> return False <EOL> def check_conversion ( condition , message ) : <EOL> """<STR_LIT>""" <EOL> if not condition : <EOL> raise InvalidConversionError ( message ) <EOL> def is_in_rfc_3339_bounds ( microseconds ) : <EOL> return ( RFC_3339_MIN_MICROSECONDS_INCLUSIVE <= microseconds <EOL> <= RFC_3339_MAX_MICROSECONDS_INCLUSIVE ) <EOL> class InvalidConversionError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class IdResolver ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app_ids = ( ) ) : <EOL> """<STR_LIT>""" <EOL> resolver_map = { } <EOL> for app_id in app_ids : <EOL> resolver_map [ self . resolve_project_id ( app_id ) ] = app_id <EOL> self . _resolver_map = resolver_map <EOL> def resolve_project_id ( self , app_id ) : <EOL> """<STR_LIT>""" <EOL> return app_id . rsplit ( '<STR_LIT>' ) [ - <NUM_LIT:1> ] <EOL> def resolve_app_id ( self , project_id ) : <EOL> """<STR_LIT>""" <EOL> check_conversion ( project_id in self . _resolver_map , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % project_id ) <EOL> return self . _resolver_map [ project_id ] <EOL> class _IdentityIdResolver ( IdResolver ) : <EOL> """<STR_LIT>""" <EOL> def resolve_project_id ( self , app_id ) : <EOL> return app_id <EOL> def resolve_app_id ( self , project_id ) : <EOL> return project_id <EOL> class _EntityConverter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id_resolver ) : <EOL> """<STR_LIT>""" <EOL> self . _id_resolver = id_resolver <EOL> def v4_to_v3_reference ( self , v4_key , v3_ref ) : <EOL> """<STR_LIT>""" <EOL> v3_ref . Clear ( ) <EOL> if v4_key . has_partition_id ( ) : <EOL> if v4_key . partition_id ( ) . has_dataset_id ( ) : <EOL> v3_ref . set_app ( v4_key . partition_id ( ) . dataset_id ( ) ) <EOL> if v4_key . partition_id ( ) . has_namespace ( ) : <EOL> v3_ref . set_name_space ( v4_key . partition_id ( ) . namespace ( ) ) <EOL> for v4_element in v4_key . path_element_list ( ) : <EOL> v3_element = v3_ref . mutable_path ( ) . add_element ( ) <EOL> v3_element . set_type ( v4_element . kind ( ) ) <EOL> if v4_element . has_id ( ) : <EOL> v3_element . set_id ( v4_element . id ( ) ) <EOL> if v4_element . has_name ( ) : <EOL> v3_element . set_name ( v4_element . name ( ) ) <EOL> def v4_to_v3_references ( self , v4_keys ) : <EOL> """<STR_LIT>""" <EOL> v3_refs = [ ] <EOL> for v4_key in v4_keys : <EOL> v3_ref = entity_pb . Reference ( ) <EOL> self . v4_to_v3_reference ( v4_key , v3_ref ) <EOL> v3_refs . append ( v3_ref ) <EOL> return v3_refs <EOL> def v3_to_v4_key ( self , v3_ref , v4_key ) : <EOL> """<STR_LIT>""" <EOL> v4_key . Clear ( ) <EOL> if not v3_ref . app ( ) : <EOL> return <EOL> v4_key . mutable_partition_id ( ) . set_dataset_id ( v3_ref . app ( ) ) <EOL> if v3_ref . name_space ( ) : <EOL> v4_key . mutable_partition_id ( ) . set_namespace ( v3_ref . name_space ( ) ) <EOL> for v3_element in v3_ref . path ( ) . element_list ( ) : <EOL> v4_element = v4_key . add_path_element ( ) <EOL> v4_element . set_kind ( v3_element . type ( ) ) <EOL> if v3_element . has_id ( ) : <EOL> v4_element . set_id ( v3_element . id ( ) ) <EOL> if v3_element . has_name ( ) : <EOL> v4_element . set_name ( v3_element . name ( ) ) <EOL> def v3_to_v4_keys ( self , v3_refs ) : <EOL> """<STR_LIT>""" <EOL> v4_keys = [ ] <EOL> for v3_ref in v3_refs : <EOL> v4_key = entity_v4_pb . Key ( ) <EOL> self . v3_to_v4_key ( v3_ref , v4_key ) <EOL> v4_keys . append ( v4_key ) <EOL> return v4_keys <EOL> def v4_to_v3_entity ( self , v4_entity , v3_entity , is_projection = False ) : <EOL> """<STR_LIT>""" <EOL> v3_entity . Clear ( ) <EOL> for v4_property in v4_entity . property_list ( ) : <EOL> property_name = v4_property . name ( ) <EOL> v4_value = v4_property . value ( ) <EOL> if v4_value . list_value_list ( ) : <EOL> for v4_sub_value in v4_value . list_value_list ( ) : <EOL> self . __add_v3_property_from_v4 ( <EOL> property_name , True , is_projection , v4_sub_value , v3_entity ) <EOL> else : <EOL> self . __add_v3_property_from_v4 ( <EOL> property_name , False , is_projection , v4_value , v3_entity ) <EOL> if v4_entity . has_key ( ) : <EOL> v4_key = v4_entity . key ( ) <EOL> self . v4_to_v3_reference ( v4_key , v3_entity . mutable_key ( ) ) <EOL> v3_ref = v3_entity . key ( ) <EOL> self . v3_reference_to_group ( v3_ref , v3_entity . mutable_entity_group ( ) ) <EOL> else : <EOL> pass <EOL> def v3_to_v4_entity ( self , v3_entity , v4_entity ) : <EOL> """<STR_LIT>""" <EOL> v4_entity . Clear ( ) <EOL> self . v3_to_v4_key ( v3_entity . key ( ) , v4_entity . mutable_key ( ) ) <EOL> if not v3_entity . key ( ) . has_app ( ) : <EOL> v4_entity . clear_key ( ) <EOL> v4_properties = { } <EOL> for v3_property in v3_entity . property_list ( ) : <EOL> self . __add_v4_property_to_entity ( v4_entity , v4_properties , v3_property , <EOL> True ) <EOL> for v3_property in v3_entity . raw_property_list ( ) : <EOL> self . __add_v4_property_to_entity ( v4_entity , v4_properties , v3_property , <EOL> False ) <EOL> def v4_value_to_v3_property_value ( self , v4_value , v3_value ) : <EOL> """<STR_LIT>""" <EOL> v3_value . Clear ( ) <EOL> if v4_value . has_boolean_value ( ) : <EOL> v3_value . set_booleanvalue ( v4_value . boolean_value ( ) ) <EOL> elif v4_value . has_integer_value ( ) : <EOL> v3_value . set_int64value ( v4_value . integer_value ( ) ) <EOL> elif v4_value . has_double_value ( ) : <EOL> v3_value . set_doublevalue ( v4_value . double_value ( ) ) <EOL> elif v4_value . has_timestamp_microseconds_value ( ) : <EOL> v3_value . set_int64value ( v4_value . timestamp_microseconds_value ( ) ) <EOL> elif v4_value . has_key_value ( ) : <EOL> v3_ref = entity_pb . Reference ( ) <EOL> self . v4_to_v3_reference ( v4_value . key_value ( ) , v3_ref ) <EOL> self . v3_reference_to_v3_property_value ( v3_ref , v3_value ) <EOL> elif v4_value . has_blob_key_value ( ) : <EOL> v3_value . set_stringvalue ( v4_value . blob_key_value ( ) ) <EOL> elif v4_value . has_string_value ( ) : <EOL> v3_value . set_stringvalue ( v4_value . string_value ( ) ) <EOL> elif v4_value . has_blob_value ( ) : <EOL> v3_value . set_stringvalue ( v4_value . blob_value ( ) ) <EOL> elif v4_value . has_entity_value ( ) : <EOL> v4_entity_value = v4_value . entity_value ( ) <EOL> v4_meaning = v4_value . meaning ( ) <EOL> if ( v4_meaning == MEANING_GEORSS_POINT <EOL> or v4_meaning == MEANING_PREDEFINED_ENTITY_POINT ) : <EOL> self . __v4_to_v3_point_value ( v4_entity_value , <EOL> v3_value . mutable_pointvalue ( ) ) <EOL> elif v4_meaning == MEANING_PREDEFINED_ENTITY_USER : <EOL> self . v4_entity_to_v3_user_value ( v4_entity_value , <EOL> v3_value . mutable_uservalue ( ) ) <EOL> else : <EOL> v3_entity_value = entity_pb . EntityProto ( ) <EOL> self . v4_to_v3_entity ( v4_entity_value , v3_entity_value ) <EOL> v3_value . set_stringvalue ( v3_entity_value . SerializePartialToString ( ) ) <EOL> elif v4_value . has_geo_point_value ( ) : <EOL> point_value = v3_value . mutable_pointvalue ( ) <EOL> point_value . set_x ( v4_value . geo_point_value ( ) . latitude ( ) ) <EOL> point_value . set_y ( v4_value . geo_point_value ( ) . longitude ( ) ) <EOL> else : <EOL> pass <EOL> def v3_property_to_v4_value ( self , v3_property , indexed , v4_value ) : <EOL> """<STR_LIT>""" <EOL> v4_value . Clear ( ) <EOL> v3_property_value = v3_property . value ( ) <EOL> v3_meaning = v3_property . meaning ( ) <EOL> v3_uri_meaning = None <EOL> if v3_property . meaning_uri ( ) : <EOL> v3_uri_meaning = v3_property . meaning_uri ( ) <EOL> if not self . __is_v3_property_value_union_valid ( v3_property_value ) : <EOL> v3_meaning = None <EOL> v3_uri_meaning = None <EOL> elif v3_meaning == entity_pb . Property . NO_MEANING : <EOL> v3_meaning = None <EOL> elif not self . __is_v3_property_value_meaning_valid ( v3_property_value , <EOL> v3_meaning ) : <EOL> v3_meaning = None <EOL> is_zlib_value = False <EOL> if v3_uri_meaning : <EOL> if v3_uri_meaning == URI_MEANING_ZLIB : <EOL> if v3_property_value . has_stringvalue ( ) : <EOL> is_zlib_value = True <EOL> if v3_meaning != entity_pb . Property . BLOB : <EOL> v3_meaning = entity_pb . Property . BLOB <EOL> else : <EOL> pass <EOL> else : <EOL> pass <EOL> if v3_property_value . has_booleanvalue ( ) : <EOL> v4_value . set_boolean_value ( v3_property_value . booleanvalue ( ) ) <EOL> elif v3_property_value . has_int64value ( ) : <EOL> if v3_meaning == entity_pb . Property . GD_WHEN : <EOL> v4_value . set_timestamp_microseconds_value ( <EOL> v3_property_value . int64value ( ) ) <EOL> v3_meaning = None <EOL> else : <EOL> v4_value . set_integer_value ( v3_property_value . int64value ( ) ) <EOL> elif v3_property_value . has_doublevalue ( ) : <EOL> v4_value . set_double_value ( v3_property_value . doublevalue ( ) ) <EOL> elif v3_property_value . has_referencevalue ( ) : <EOL> v3_ref = entity_pb . Reference ( ) <EOL> self . __v3_reference_value_to_v3_reference ( <EOL> v3_property_value . referencevalue ( ) , v3_ref ) <EOL> self . v3_to_v4_key ( v3_ref , v4_value . mutable_key_value ( ) ) <EOL> elif v3_property_value . has_stringvalue ( ) : <EOL> if v3_meaning == entity_pb . Property . ENTITY_PROTO : <EOL> serialized_entity_v3 = v3_property_value . stringvalue ( ) <EOL> v3_entity = entity_pb . EntityProto ( ) <EOL> v3_entity . ParsePartialFromString ( serialized_entity_v3 ) <EOL> self . v3_to_v4_entity ( v3_entity , v4_value . mutable_entity_value ( ) ) <EOL> v3_meaning = None <EOL> elif ( v3_meaning == entity_pb . Property . BLOB <EOL> or v3_meaning == entity_pb . Property . BYTESTRING ) : <EOL> v4_value . set_blob_value ( v3_property_value . stringvalue ( ) ) <EOL> if indexed or v3_meaning == entity_pb . Property . BLOB : <EOL> v3_meaning = None <EOL> else : <EOL> string_value = v3_property_value . stringvalue ( ) <EOL> if is_valid_utf8 ( string_value ) : <EOL> if v3_meaning == entity_pb . Property . BLOBKEY : <EOL> v4_value . set_blob_key_value ( string_value ) <EOL> v3_meaning = None <EOL> else : <EOL> v4_value . set_string_value ( string_value ) <EOL> else : <EOL> v4_value . set_blob_value ( string_value ) <EOL> if v3_meaning != entity_pb . Property . INDEX_VALUE : <EOL> v3_meaning = None <EOL> elif v3_property_value . has_pointvalue ( ) : <EOL> if v3_meaning == MEANING_GEORSS_POINT : <EOL> point_value = v3_property_value . pointvalue ( ) <EOL> v4_value . mutable_geo_point_value ( ) . set_latitude ( point_value . x ( ) ) <EOL> v4_value . mutable_geo_point_value ( ) . set_longitude ( point_value . y ( ) ) <EOL> else : <EOL> self . __v3_to_v4_point_entity ( v3_property_value . pointvalue ( ) , <EOL> v4_value . mutable_entity_value ( ) ) <EOL> v4_value . set_meaning ( MEANING_PREDEFINED_ENTITY_POINT ) <EOL> v3_meaning = None <EOL> elif v3_property_value . has_uservalue ( ) : <EOL> self . v3_user_value_to_v4_entity ( v3_property_value . uservalue ( ) , <EOL> v4_value . mutable_entity_value ( ) ) <EOL> v4_value . set_meaning ( MEANING_PREDEFINED_ENTITY_USER ) <EOL> v3_meaning = None <EOL> else : <EOL> pass <EOL> if is_zlib_value : <EOL> v4_value . set_meaning ( MEANING_ZLIB ) <EOL> elif v3_meaning : <EOL> v4_value . set_meaning ( v3_meaning ) <EOL> if indexed != v4_value . indexed ( ) : <EOL> v4_value . set_indexed ( indexed ) <EOL> def v4_to_v3_property ( self , property_name , is_multi , is_projection , <EOL> v4_value , v3_property ) : <EOL> """<STR_LIT>""" <EOL> assert not v4_value . list_value_list ( ) , '<STR_LIT>' <EOL> v3_property . Clear ( ) <EOL> v3_property . set_name ( property_name ) <EOL> if v4_value . has_meaning ( ) and v4_value . meaning ( ) == MEANING_EMPTY_LIST : <EOL> v3_property . set_meaning ( MEANING_EMPTY_LIST ) <EOL> v3_property . set_multiple ( False ) <EOL> v3_property . mutable_value ( ) <EOL> return <EOL> v3_property . set_multiple ( is_multi ) <EOL> self . v4_value_to_v3_property_value ( v4_value , v3_property . mutable_value ( ) ) <EOL> v4_meaning = None <EOL> if v4_value . has_meaning ( ) : <EOL> v4_meaning = v4_value . meaning ( ) <EOL> if v4_value . has_timestamp_microseconds_value ( ) : <EOL> v3_property . set_meaning ( entity_pb . Property . GD_WHEN ) <EOL> elif v4_value . has_blob_key_value ( ) : <EOL> v3_property . set_meaning ( entity_pb . Property . BLOBKEY ) <EOL> elif v4_value . has_blob_value ( ) : <EOL> if v4_meaning == MEANING_ZLIB : <EOL> v3_property . set_meaning_uri ( URI_MEANING_ZLIB ) <EOL> if v4_meaning == entity_pb . Property . BYTESTRING : <EOL> if v4_value . indexed ( ) : <EOL> pass <EOL> else : <EOL> if v4_value . indexed ( ) : <EOL> v3_property . set_meaning ( entity_pb . Property . BYTESTRING ) <EOL> else : <EOL> v3_property . set_meaning ( entity_pb . Property . BLOB ) <EOL> v4_meaning = None <EOL> elif v4_value . has_entity_value ( ) : <EOL> if v4_meaning != MEANING_GEORSS_POINT : <EOL> if ( v4_meaning != MEANING_PREDEFINED_ENTITY_POINT <EOL> and v4_meaning != MEANING_PREDEFINED_ENTITY_USER ) : <EOL> v3_property . set_meaning ( entity_pb . Property . ENTITY_PROTO ) <EOL> v4_meaning = None <EOL> elif v4_value . has_geo_point_value ( ) : <EOL> v3_property . set_meaning ( MEANING_GEORSS_POINT ) <EOL> else : <EOL> pass <EOL> if v4_meaning is not None : <EOL> v3_property . set_meaning ( v4_meaning ) <EOL> if is_projection : <EOL> v3_property . set_meaning ( entity_pb . Property . INDEX_VALUE ) <EOL> def __add_v3_property_from_v4 ( self , property_name , is_multi , is_projection , <EOL> v4_value , v3_entity ) : <EOL> """<STR_LIT>""" <EOL> if v4_value . indexed ( ) : <EOL> self . v4_to_v3_property ( property_name , is_multi , is_projection , <EOL> v4_value , v3_entity . add_property ( ) ) <EOL> else : <EOL> self . v4_to_v3_property ( property_name , is_multi , is_projection , <EOL> v4_value , v3_entity . add_raw_property ( ) ) <EOL> def __build_name_to_v4_property_map ( self , v4_entity ) : <EOL> property_map = { } <EOL> for prop in v4_entity . property_list ( ) : <EOL> property_map [ prop . name ( ) ] = prop <EOL> return property_map <EOL> def __add_v4_property_to_entity ( self , v4_entity , property_map , v3_property , <EOL> indexed ) : <EOL> """<STR_LIT>""" <EOL> property_name = v3_property . name ( ) <EOL> if property_name in property_map : <EOL> v4_property = property_map [ property_name ] <EOL> else : <EOL> v4_property = v4_entity . add_property ( ) <EOL> v4_property . set_name ( property_name ) <EOL> property_map [ property_name ] = v4_property <EOL> if v3_property . multiple ( ) : <EOL> self . v3_property_to_v4_value ( v3_property , indexed , <EOL> v4_property . mutable_value ( ) . add_list_value ( ) ) <EOL> else : <EOL> self . v3_property_to_v4_value ( v3_property , indexed , <EOL> v4_property . mutable_value ( ) ) <EOL> def __get_v4_integer_value ( self , v4_property ) : <EOL> """<STR_LIT>""" <EOL> check_conversion ( v4_property . value ( ) . has_integer_value ( ) , <EOL> '<STR_LIT>' ) <EOL> return v4_property . value ( ) . integer_value ( ) <EOL> def __get_v4_double_value ( self , v4_property ) : <EOL> """<STR_LIT>""" <EOL> check_conversion ( v4_property . value ( ) . has_double_value ( ) , <EOL> '<STR_LIT>' ) <EOL> return v4_property . value ( ) . double_value ( ) <EOL> def __get_v4_string_value ( self , v4_property ) : <EOL> """<STR_LIT>""" <EOL> check_conversion ( v4_property . value ( ) . has_string_value ( ) , <EOL> '<STR_LIT>' ) <EOL> return v4_property . value ( ) . string_value ( ) <EOL> def __v4_integer_property ( self , name , value , indexed ) : <EOL> """<STR_LIT>""" <EOL> v4_property = entity_v4_pb . Property ( ) <EOL> v4_property . set_name ( name ) <EOL> v4_value = v4_property . mutable_value ( ) <EOL> v4_value . set_indexed ( indexed ) <EOL> v4_value . set_integer_value ( value ) <EOL> return v4_property <EOL> def __v4_double_property ( self , name , value , indexed ) : <EOL> """<STR_LIT>""" <EOL> v4_property = entity_v4_pb . Property ( ) <EOL> v4_property . set_name ( name ) <EOL> v4_value = v4_property . mutable_value ( ) <EOL> v4_value . set_indexed ( indexed ) <EOL> v4_value . set_double_value ( value ) <EOL> return v4_property <EOL> def __v4_string_property ( self , name , value , indexed ) : <EOL> """<STR_LIT>""" <EOL> v4_property = entity_v4_pb . Property ( ) <EOL> v4_property . set_name ( name ) <EOL> v4_value = v4_property . mutable_value ( ) <EOL> v4_value . set_indexed ( indexed ) <EOL> v4_value . set_string_value ( value ) <EOL> return v4_property <EOL> def __v4_to_v3_point_value ( self , v4_point_entity , v3_point_value ) : <EOL> """<STR_LIT>""" <EOL> v3_point_value . Clear ( ) <EOL> name_to_v4_property = self . __build_name_to_v4_property_map ( v4_point_entity ) <EOL> v3_point_value . set_x ( <EOL> self . __get_v4_double_value ( name_to_v4_property [ '<STR_LIT:x>' ] ) ) <EOL> v3_point_value . set_y ( <EOL> self . __get_v4_double_value ( name_to_v4_property [ '<STR_LIT:y>' ] ) ) <EOL> def __v3_to_v4_point_entity ( self , v3_point_value , v4_entity ) : <EOL> """<STR_LIT>""" <EOL> v4_entity . Clear ( ) <EOL> v4_entity . property_list ( ) . append ( <EOL> self . __v4_double_property ( PROPERTY_NAME_X , v3_point_value . x ( ) , False ) ) <EOL> v4_entity . property_list ( ) . append ( <EOL> self . __v4_double_property ( PROPERTY_NAME_Y , v3_point_value . y ( ) , False ) ) <EOL> def v4_entity_to_v3_user_value ( self , v4_user_entity , v3_user_value ) : <EOL> """<STR_LIT>""" <EOL> v3_user_value . Clear ( ) <EOL> name_to_v4_property = self . __build_name_to_v4_property_map ( v4_user_entity ) <EOL> v3_user_value . set_email ( self . __get_v4_string_value ( <EOL> name_to_v4_property [ PROPERTY_NAME_EMAIL ] ) ) <EOL> v3_user_value . set_auth_domain ( self . __get_v4_string_value ( <EOL> name_to_v4_property [ PROPERTY_NAME_AUTH_DOMAIN ] ) ) <EOL> if PROPERTY_NAME_USER_ID in name_to_v4_property : <EOL> v3_user_value . set_obfuscated_gaiaid ( <EOL> self . __get_v4_string_value ( <EOL> name_to_v4_property [ PROPERTY_NAME_USER_ID ] ) ) <EOL> if PROPERTY_NAME_INTERNAL_ID in name_to_v4_property : <EOL> v3_user_value . set_gaiaid ( self . __get_v4_integer_value ( <EOL> name_to_v4_property [ PROPERTY_NAME_INTERNAL_ID ] ) ) <EOL> else : <EOL> v3_user_value . set_gaiaid ( <NUM_LIT:0> ) <EOL> if PROPERTY_NAME_FEDERATED_IDENTITY in name_to_v4_property : <EOL> v3_user_value . set_federated_identity ( <EOL> self . __get_v4_string_value ( name_to_v4_property [ <EOL> PROPERTY_NAME_FEDERATED_IDENTITY ] ) ) <EOL> if PROPERTY_NAME_FEDERATED_PROVIDER in name_to_v4_property : <EOL> v3_user_value . set_federated_provider ( <EOL> self . __get_v4_string_value ( name_to_v4_property [ <EOL> PROPERTY_NAME_FEDERATED_PROVIDER ] ) ) <EOL> def v3_user_value_to_v4_entity ( self , v3_user_value , v4_entity ) : <EOL> """<STR_LIT>""" <EOL> v4_entity . Clear ( ) <EOL> v4_entity . property_list ( ) . append ( <EOL> self . __v4_string_property ( PROPERTY_NAME_EMAIL , v3_user_value . email ( ) , <EOL> False ) ) <EOL> v4_entity . property_list ( ) . append ( self . __v4_string_property ( <EOL> PROPERTY_NAME_AUTH_DOMAIN , <EOL> v3_user_value . auth_domain ( ) , False ) ) <EOL> if v3_user_value . gaiaid ( ) != <NUM_LIT:0> : <EOL> v4_entity . property_list ( ) . append ( self . __v4_integer_property ( <EOL> PROPERTY_NAME_INTERNAL_ID , <EOL> v3_user_value . gaiaid ( ) , <EOL> False ) ) <EOL> if v3_user_value . has_obfuscated_gaiaid ( ) : <EOL> v4_entity . property_list ( ) . append ( self . __v4_string_property ( <EOL> PROPERTY_NAME_USER_ID , <EOL> v3_user_value . obfuscated_gaiaid ( ) , <EOL> False ) ) <EOL> if v3_user_value . has_federated_identity ( ) : <EOL> v4_entity . property_list ( ) . append ( self . __v4_string_property ( <EOL> PROPERTY_NAME_FEDERATED_IDENTITY , <EOL> v3_user_value . federated_identity ( ) , <EOL> False ) ) <EOL> if v3_user_value . has_federated_provider ( ) : <EOL> v4_entity . property_list ( ) . append ( self . __v4_string_property ( <EOL> PROPERTY_NAME_FEDERATED_PROVIDER , <EOL> v3_user_value . federated_provider ( ) , <EOL> False ) ) <EOL> def v1_to_v3_reference ( self , v1_key , v3_ref ) : <EOL> """<STR_LIT>""" <EOL> v3_ref . Clear ( ) <EOL> if v1_key . HasField ( '<STR_LIT>' ) : <EOL> project_id = v1_key . partition_id . project_id <EOL> if project_id : <EOL> app_id = self . _id_resolver . resolve_app_id ( project_id ) <EOL> v3_ref . set_app ( app_id ) <EOL> if v1_key . partition_id . namespace_id : <EOL> v3_ref . set_name_space ( v1_key . partition_id . namespace_id ) <EOL> for v1_element in v1_key . path : <EOL> v3_element = v3_ref . mutable_path ( ) . add_element ( ) <EOL> v3_element . set_type ( v1_element . kind . encode ( '<STR_LIT:utf-8>' ) ) <EOL> id_type = v1_element . WhichOneof ( '<STR_LIT>' ) <EOL> if id_type == '<STR_LIT:id>' : <EOL> v3_element . set_id ( v1_element . id ) <EOL> elif id_type == '<STR_LIT:name>' : <EOL> v3_element . set_name ( v1_element . name . encode ( '<STR_LIT:utf-8>' ) ) <EOL> def v1_to_v3_references ( self , v1_keys ) : <EOL> """<STR_LIT>""" <EOL> v3_refs = [ ] <EOL> for v1_key in v1_keys : <EOL> v3_ref = entity_pb . Reference ( ) <EOL> self . v1_to_v3_reference ( v1_key , v3_ref ) <EOL> v3_refs . append ( v3_ref ) <EOL> return v3_refs <EOL> def v3_to_v1_key ( self , v3_ref , v1_key ) : <EOL> """<STR_LIT>""" <EOL> v1_key . Clear ( ) <EOL> if not v3_ref . app ( ) : <EOL> return <EOL> project_id = self . _id_resolver . resolve_project_id ( v3_ref . app ( ) ) <EOL> v1_key . partition_id . project_id = project_id <EOL> if v3_ref . name_space ( ) : <EOL> v1_key . partition_id . namespace_id = v3_ref . name_space ( ) <EOL> for v3_element in v3_ref . path ( ) . element_list ( ) : <EOL> v1_element = v1_key . path . add ( ) <EOL> v1_element . kind = v3_element . type ( ) <EOL> if v3_element . has_id ( ) : <EOL> v1_element . id = v3_element . id ( ) <EOL> if v3_element . has_name ( ) : <EOL> v1_element . name = v3_element . name ( ) <EOL> def v3_to_v1_keys ( self , v3_refs ) : <EOL> """<STR_LIT>""" <EOL> v1_keys = [ ] <EOL> for v3_ref in v3_refs : <EOL> v1_key = googledatastore . Key ( ) <EOL> self . v3_to_v1_key ( v3_ref , v1_key ) <EOL> v1_keys . append ( v1_key ) <EOL> return v1_keys <EOL> def project_to_app_id ( self , project_id ) : <EOL> """<STR_LIT>""" <EOL> return self . _id_resolver . resolve_app_id ( project_id ) <EOL> def app_to_project_id ( self , app_id ) : <EOL> """<STR_LIT>""" <EOL> return self . _id_resolver . resolve_project_id ( app_id ) <EOL> def __new_v3_property ( self , v3_entity , is_indexed ) : <EOL> if is_indexed : <EOL> return v3_entity . add_property ( ) <EOL> else : <EOL> return v3_entity . add_raw_property ( ) <EOL> def v1_to_v3_entity ( self , v1_entity , v3_entity , is_projection = False ) : <EOL> """<STR_LIT>""" <EOL> v3_entity . Clear ( ) <EOL> for property_name , v1_value in v1_entity . properties . iteritems ( ) : <EOL> if v1_value . HasField ( '<STR_LIT>' ) : <EOL> if len ( v1_value . array_value . values ) == <NUM_LIT:0> : <EOL> empty_list = self . __new_v3_property ( v3_entity , <EOL> not v1_value . exclude_from_indexes ) <EOL> empty_list . set_name ( property_name . encode ( '<STR_LIT:utf-8>' ) ) <EOL> empty_list . set_multiple ( False ) <EOL> empty_list . set_meaning ( MEANING_EMPTY_LIST ) <EOL> empty_list . mutable_value ( ) <EOL> else : <EOL> for v1_sub_value in v1_value . array_value . values : <EOL> list_element = self . __new_v3_property ( <EOL> v3_entity , not v1_sub_value . exclude_from_indexes ) <EOL> self . v1_to_v3_property ( <EOL> property_name , True , is_projection , v1_sub_value , list_element ) <EOL> else : <EOL> value_property = self . __new_v3_property ( <EOL> v3_entity , not v1_value . exclude_from_indexes ) <EOL> self . v1_to_v3_property ( <EOL> property_name , False , is_projection , v1_value , value_property ) <EOL> if v1_entity . HasField ( '<STR_LIT:key>' ) : <EOL> v1_key = v1_entity . key <EOL> self . v1_to_v3_reference ( v1_key , v3_entity . mutable_key ( ) ) <EOL> v3_ref = v3_entity . key ( ) <EOL> self . v3_reference_to_group ( v3_ref , v3_entity . mutable_entity_group ( ) ) <EOL> else : <EOL> pass <EOL> def v3_to_v1_entity ( self , v3_entity , v1_entity ) : <EOL> """<STR_LIT>""" <EOL> v1_entity . Clear ( ) <EOL> self . v3_to_v1_key ( v3_entity . key ( ) , v1_entity . key ) <EOL> if not v3_entity . key ( ) . has_app ( ) : <EOL> v1_entity . ClearField ( '<STR_LIT:key>' ) <EOL> for v3_property in v3_entity . property_list ( ) : <EOL> self . __add_v1_property_to_entity ( v1_entity , v3_property , True ) <EOL> for v3_property in v3_entity . raw_property_list ( ) : <EOL> self . __add_v1_property_to_entity ( v1_entity , v3_property , False ) <EOL> def v1_value_to_v3_property_value ( self , v1_value , v3_value ) : <EOL> """<STR_LIT>""" <EOL> v3_value . Clear ( ) <EOL> field = v1_value . WhichOneof ( '<STR_LIT>' ) <EOL> if field == '<STR_LIT>' : <EOL> v3_value . set_booleanvalue ( v1_value . boolean_value ) <EOL> elif field == '<STR_LIT>' : <EOL> v3_value . set_int64value ( v1_value . integer_value ) <EOL> elif field == '<STR_LIT>' : <EOL> v3_value . set_doublevalue ( v1_value . double_value ) <EOL> elif field == '<STR_LIT>' : <EOL> v3_value . set_int64value ( <EOL> googledatastore . helper . micros_from_timestamp ( <EOL> v1_value . timestamp_value ) ) <EOL> elif field == '<STR_LIT>' : <EOL> v3_ref = entity_pb . Reference ( ) <EOL> self . v1_to_v3_reference ( v1_value . key_value , v3_ref ) <EOL> self . v3_reference_to_v3_property_value ( v3_ref , v3_value ) <EOL> elif field == '<STR_LIT>' : <EOL> v3_value . set_stringvalue ( v1_value . string_value . encode ( '<STR_LIT:utf-8>' ) ) <EOL> elif field == '<STR_LIT>' : <EOL> v3_value . set_stringvalue ( v1_value . blob_value ) <EOL> elif field == '<STR_LIT>' : <EOL> v1_entity_value = v1_value . entity_value <EOL> v1_meaning = v1_value . meaning <EOL> if v1_meaning == MEANING_PREDEFINED_ENTITY_USER : <EOL> self . v1_entity_to_v3_user_value ( v1_entity_value , <EOL> v3_value . mutable_uservalue ( ) ) <EOL> else : <EOL> v3_entity_value = entity_pb . EntityProto ( ) <EOL> self . v1_to_v3_entity ( v1_entity_value , v3_entity_value ) <EOL> v3_value . set_stringvalue ( v3_entity_value . SerializePartialToString ( ) ) <EOL> elif field == '<STR_LIT>' : <EOL> point_value = v3_value . mutable_pointvalue ( ) <EOL> point_value . set_x ( v1_value . geo_point_value . latitude ) <EOL> point_value . set_y ( v1_value . geo_point_value . longitude ) <EOL> elif field == '<STR_LIT>' : <EOL> pass <EOL> else : <EOL> pass <EOL> def v3_property_to_v1_value ( self , v3_property , indexed , v1_value ) : <EOL> """<STR_LIT>""" <EOL> v1_value . Clear ( ) <EOL> v3_property_value = v3_property . value ( ) <EOL> v3_meaning = v3_property . meaning ( ) <EOL> v3_uri_meaning = None <EOL> if v3_property . meaning_uri ( ) : <EOL> v3_uri_meaning = v3_property . meaning_uri ( ) <EOL> if not self . __is_v3_property_value_union_valid ( v3_property_value ) : <EOL> v3_meaning = None <EOL> v3_uri_meaning = None <EOL> elif v3_meaning == entity_pb . Property . NO_MEANING : <EOL> v3_meaning = None <EOL> elif not self . __is_v3_property_value_meaning_valid ( v3_property_value , <EOL> v3_meaning ) : <EOL> v3_meaning = None <EOL> is_zlib_value = False <EOL> if v3_uri_meaning : <EOL> if v3_uri_meaning == URI_MEANING_ZLIB : <EOL> if v3_property_value . has_stringvalue ( ) : <EOL> is_zlib_value = True <EOL> if v3_meaning != entity_pb . Property . BLOB : <EOL> v3_meaning = entity_pb . Property . BLOB <EOL> else : <EOL> pass <EOL> else : <EOL> pass <EOL> if v3_property . meaning ( ) == entity_pb . Property . EMPTY_LIST : <EOL> v1_value . array_value . values . extend ( [ ] ) <EOL> v3_meaning = None <EOL> elif v3_property_value . has_booleanvalue ( ) : <EOL> v1_value . boolean_value = v3_property_value . booleanvalue ( ) <EOL> elif v3_property_value . has_int64value ( ) : <EOL> if ( v3_meaning == entity_pb . Property . GD_WHEN <EOL> and is_in_rfc_3339_bounds ( v3_property_value . int64value ( ) ) ) : <EOL> googledatastore . helper . micros_to_timestamp ( <EOL> v3_property_value . int64value ( ) , v1_value . timestamp_value ) <EOL> v3_meaning = None <EOL> else : <EOL> v1_value . integer_value = v3_property_value . int64value ( ) <EOL> elif v3_property_value . has_doublevalue ( ) : <EOL> v1_value . double_value = v3_property_value . doublevalue ( ) <EOL> elif v3_property_value . has_referencevalue ( ) : <EOL> v3_ref = entity_pb . Reference ( ) <EOL> self . __v3_reference_value_to_v3_reference ( <EOL> v3_property_value . referencevalue ( ) , v3_ref ) <EOL> self . v3_to_v1_key ( v3_ref , v1_value . key_value ) <EOL> elif v3_property_value . has_stringvalue ( ) : <EOL> if v3_meaning == entity_pb . Property . ENTITY_PROTO : <EOL> serialized_entity_v3 = v3_property_value . stringvalue ( ) <EOL> v3_entity = entity_pb . EntityProto ( ) <EOL> v3_entity . ParsePartialFromString ( serialized_entity_v3 ) <EOL> self . v3_to_v1_entity ( v3_entity , v1_value . entity_value ) <EOL> v3_meaning = None <EOL> elif ( v3_meaning == entity_pb . Property . BLOB <EOL> or v3_meaning == entity_pb . Property . BYTESTRING ) : <EOL> v1_value . blob_value = v3_property_value . stringvalue ( ) <EOL> if indexed or v3_meaning == entity_pb . Property . BLOB : <EOL> v3_meaning = None <EOL> else : <EOL> string_value = v3_property_value . stringvalue ( ) <EOL> if is_valid_utf8 ( string_value ) : <EOL> v1_value . string_value = string_value <EOL> else : <EOL> v1_value . blob_value = string_value <EOL> if v3_meaning != entity_pb . Property . INDEX_VALUE : <EOL> v3_meaning = None <EOL> elif v3_property_value . has_pointvalue ( ) : <EOL> if v3_meaning != MEANING_GEORSS_POINT : <EOL> v1_value . meaning = MEANING_POINT_WITHOUT_V3_MEANING <EOL> point_value = v3_property_value . pointvalue ( ) <EOL> v1_value . geo_point_value . latitude = point_value . x ( ) <EOL> v1_value . geo_point_value . longitude = point_value . y ( ) <EOL> v3_meaning = None <EOL> elif v3_property_value . has_uservalue ( ) : <EOL> self . v3_user_value_to_v1_entity ( v3_property_value . uservalue ( ) , <EOL> v1_value . entity_value ) <EOL> v1_value . meaning = MEANING_PREDEFINED_ENTITY_USER <EOL> v3_meaning = None <EOL> else : <EOL> v1_value . null_value = googledatastore . NULL_VALUE <EOL> if is_zlib_value : <EOL> v1_value . meaning = MEANING_ZLIB <EOL> elif v3_meaning : <EOL> v1_value . meaning = v3_meaning <EOL> if indexed == v1_value . exclude_from_indexes : <EOL> v1_value . exclude_from_indexes = not indexed <EOL> def v1_to_v3_property ( self , property_name , is_multi , is_projection , <EOL> v1_value , v3_property ) : <EOL> """<STR_LIT>""" <EOL> v1_value_type = v1_value . WhichOneof ( '<STR_LIT>' ) <EOL> if v1_value_type == '<STR_LIT>' : <EOL> assert False , '<STR_LIT>' <EOL> v3_property . Clear ( ) <EOL> v3_property . set_name ( property_name . encode ( '<STR_LIT:utf-8>' ) ) <EOL> v3_property . set_multiple ( is_multi ) <EOL> self . v1_value_to_v3_property_value ( v1_value , v3_property . mutable_value ( ) ) <EOL> v1_meaning = None <EOL> if v1_value . meaning : <EOL> v1_meaning = v1_value . meaning <EOL> if v1_value_type == '<STR_LIT>' : <EOL> v3_property . set_meaning ( entity_pb . Property . GD_WHEN ) <EOL> elif v1_value_type == '<STR_LIT>' : <EOL> if v1_meaning == MEANING_ZLIB : <EOL> v3_property . set_meaning_uri ( URI_MEANING_ZLIB ) <EOL> if v1_meaning == entity_pb . Property . BYTESTRING : <EOL> if not v1_value . exclude_from_indexes : <EOL> pass <EOL> else : <EOL> if not v1_value . exclude_from_indexes : <EOL> v3_property . set_meaning ( entity_pb . Property . BYTESTRING ) <EOL> else : <EOL> v3_property . set_meaning ( entity_pb . Property . BLOB ) <EOL> v1_meaning = None <EOL> elif v1_value_type == '<STR_LIT>' : <EOL> if v1_meaning != MEANING_PREDEFINED_ENTITY_USER : <EOL> v3_property . set_meaning ( entity_pb . Property . ENTITY_PROTO ) <EOL> v1_meaning = None <EOL> elif v1_value_type == '<STR_LIT>' : <EOL> if v1_meaning != MEANING_POINT_WITHOUT_V3_MEANING : <EOL> v3_property . set_meaning ( MEANING_GEORSS_POINT ) <EOL> v1_meaning = None <EOL> elif v1_value_type == '<STR_LIT>' : <EOL> if v1_meaning == MEANING_NON_RFC_3339_TIMESTAMP : <EOL> v3_property . set_meaning ( entity_pb . Property . GD_WHEN ) <EOL> v1_meaning = None <EOL> else : <EOL> pass <EOL> if v1_meaning is not None : <EOL> v3_property . set_meaning ( v1_meaning ) <EOL> if is_projection : <EOL> v3_property . set_meaning ( entity_pb . Property . INDEX_VALUE ) <EOL> def __add_v1_property_to_entity ( self , v1_entity , v3_property , indexed ) : <EOL> """<STR_LIT>""" <EOL> property_name = v3_property . name ( ) <EOL> v1_value = v1_entity . properties [ property_name ] <EOL> if v3_property . multiple ( ) : <EOL> self . v3_property_to_v1_value ( v3_property , indexed , <EOL> v1_value . array_value . values . add ( ) ) <EOL> else : <EOL> self . v3_property_to_v1_value ( v3_property , indexed , v1_value ) <EOL> def __get_v1_integer_value ( self , v1_value ) : <EOL> """<STR_LIT>""" <EOL> check_conversion ( v1_value . HasField ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> return v1_value . integer_value <EOL> def __get_v1_double_value ( self , v1_value ) : <EOL> """<STR_LIT>""" <EOL> check_conversion ( v1_value . HasField ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> return v1_value . double_value <EOL> def __get_v1_string_value ( self , v1_value ) : <EOL> """<STR_LIT>""" <EOL> check_conversion ( v1_value . HasField ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' ) <EOL> return v1_value . string_value <EOL> def __v1_integer_property ( self , entity , name , value , indexed ) : <EOL> """<STR_LIT>""" <EOL> v1_value = entity . properties [ name ] <EOL> v1_value . exclude_from_indexes = not indexed <EOL> v1_value . integer_value = value <EOL> def __v1_double_property ( self , entity , name , value , indexed ) : <EOL> """<STR_LIT>""" <EOL> v1_value = entity . properties [ name ] <EOL> v1_value . exclude_from_indexes = not indexed <EOL> v1_value . double_value = value <EOL> def __v1_string_property ( self , entity , name , value , indexed ) : <EOL> """<STR_LIT>""" <EOL> v1_value = entity . properties [ name ] <EOL> v1_value . exclude_from_indexes = not indexed <EOL> v1_value . string_value = value <EOL> def v1_entity_to_v3_user_value ( self , v1_user_entity , v3_user_value ) : <EOL> """<STR_LIT>""" <EOL> v3_user_value . Clear ( ) <EOL> properties = v1_user_entity . properties <EOL> v3_user_value . set_email ( self . __get_v1_string_value ( <EOL> properties [ PROPERTY_NAME_EMAIL ] ) ) <EOL> v3_user_value . set_auth_domain ( self . __get_v1_string_value ( <EOL> properties [ PROPERTY_NAME_AUTH_DOMAIN ] ) ) <EOL> if PROPERTY_NAME_USER_ID in properties : <EOL> v3_user_value . set_obfuscated_gaiaid ( <EOL> self . __get_v1_string_value ( properties [ PROPERTY_NAME_USER_ID ] ) ) <EOL> if PROPERTY_NAME_INTERNAL_ID in properties : <EOL> v3_user_value . set_gaiaid ( self . __get_v1_integer_value ( <EOL> properties [ PROPERTY_NAME_INTERNAL_ID ] ) ) <EOL> else : <EOL> v3_user_value . set_gaiaid ( <NUM_LIT:0> ) <EOL> if PROPERTY_NAME_FEDERATED_IDENTITY in properties : <EOL> v3_user_value . set_federated_identity ( <EOL> self . __get_v1_string_value ( properties [ <EOL> PROPERTY_NAME_FEDERATED_IDENTITY ] ) ) <EOL> if PROPERTY_NAME_FEDERATED_PROVIDER in properties : <EOL> v3_user_value . set_federated_provider ( <EOL> self . __get_v1_string_value ( properties [ <EOL> PROPERTY_NAME_FEDERATED_PROVIDER ] ) ) <EOL> def v3_user_value_to_v1_entity ( self , v3_user_value , v1_entity ) : <EOL> """<STR_LIT>""" <EOL> v1_entity . Clear ( ) <EOL> self . __v1_string_property ( v1_entity , PROPERTY_NAME_EMAIL , <EOL> v3_user_value . email ( ) , False ) <EOL> self . __v1_string_property ( v1_entity , PROPERTY_NAME_AUTH_DOMAIN , <EOL> v3_user_value . auth_domain ( ) , False ) <EOL> if v3_user_value . gaiaid ( ) != <NUM_LIT:0> : <EOL> self . __v1_integer_property ( <EOL> v1_entity , <EOL> PROPERTY_NAME_INTERNAL_ID , <EOL> v3_user_value . gaiaid ( ) , <EOL> False ) <EOL> if v3_user_value . has_obfuscated_gaiaid ( ) : <EOL> self . __v1_string_property ( <EOL> v1_entity , <EOL> PROPERTY_NAME_USER_ID , <EOL> v3_user_value . obfuscated_gaiaid ( ) , <EOL> False ) <EOL> if v3_user_value . has_federated_identity ( ) : <EOL> self . __v1_string_property ( <EOL> v1_entity , <EOL> PROPERTY_NAME_FEDERATED_IDENTITY , <EOL> v3_user_value . federated_identity ( ) , <EOL> False ) <EOL> if v3_user_value . has_federated_provider ( ) : <EOL> self . __v1_string_property ( <EOL> v1_entity , <EOL> PROPERTY_NAME_FEDERATED_PROVIDER , <EOL> v3_user_value . federated_provider ( ) , <EOL> False ) <EOL> def __is_v3_property_value_union_valid ( self , v3_property_value ) : <EOL> """<STR_LIT>""" <EOL> num_sub_values = ( v3_property_value . has_booleanvalue ( ) <EOL> + v3_property_value . has_int64value ( ) <EOL> + v3_property_value . has_doublevalue ( ) <EOL> + v3_property_value . has_referencevalue ( ) <EOL> + v3_property_value . has_stringvalue ( ) <EOL> + v3_property_value . has_pointvalue ( ) <EOL> + v3_property_value . has_uservalue ( ) ) <EOL> return num_sub_values <= <NUM_LIT:1> <EOL> def __is_v3_property_value_meaning_valid ( self , v3_property_value , v3_meaning ) : <EOL> """<STR_LIT>""" <EOL> def ReturnTrue ( ) : <EOL> return True <EOL> def HasStringValue ( ) : <EOL> return v3_property_value . has_stringvalue ( ) <EOL> def HasInt64Value ( ) : <EOL> return v3_property_value . has_int64value ( ) <EOL> def HasPointValue ( ) : <EOL> return v3_property_value . has_pointvalue ( ) <EOL> def ReturnFalse ( ) : <EOL> return False <EOL> value_checkers = { <EOL> entity_pb . Property . NO_MEANING : ReturnTrue , <EOL> entity_pb . Property . INDEX_VALUE : ReturnTrue , <EOL> entity_pb . Property . BLOB : HasStringValue , <EOL> entity_pb . Property . TEXT : HasStringValue , <EOL> entity_pb . Property . BYTESTRING : HasStringValue , <EOL> entity_pb . Property . ATOM_CATEGORY : HasStringValue , <EOL> entity_pb . Property . ATOM_LINK : HasStringValue , <EOL> entity_pb . Property . ATOM_TITLE : HasStringValue , <EOL> entity_pb . Property . ATOM_CONTENT : HasStringValue , <EOL> entity_pb . Property . ATOM_SUMMARY : HasStringValue , <EOL> entity_pb . Property . ATOM_AUTHOR : HasStringValue , <EOL> entity_pb . Property . GD_EMAIL : HasStringValue , <EOL> entity_pb . Property . GD_IM : HasStringValue , <EOL> entity_pb . Property . GD_PHONENUMBER : HasStringValue , <EOL> entity_pb . Property . GD_POSTALADDRESS : HasStringValue , <EOL> entity_pb . Property . BLOBKEY : HasStringValue , <EOL> entity_pb . Property . ENTITY_PROTO : HasStringValue , <EOL> entity_pb . Property . GD_WHEN : HasInt64Value , <EOL> entity_pb . Property . GD_RATING : HasInt64Value , <EOL> entity_pb . Property . GEORSS_POINT : HasPointValue , <EOL> entity_pb . Property . EMPTY_LIST : ReturnTrue , <EOL> } <EOL> default = ReturnFalse <EOL> return value_checkers . get ( v3_meaning , default ) ( ) <EOL> def __v3_reference_has_id_or_name ( self , v3_ref ) : <EOL> """<STR_LIT>""" <EOL> path = v3_ref . path ( ) <EOL> assert path . element_size ( ) >= <NUM_LIT:1> <EOL> last_element = path . element ( path . element_size ( ) - <NUM_LIT:1> ) <EOL> return last_element . has_id ( ) or last_element . has_name ( ) <EOL> def v3_reference_to_group ( self , v3_ref , group ) : <EOL> """<STR_LIT>""" <EOL> group . Clear ( ) <EOL> path = v3_ref . path ( ) <EOL> assert path . element_size ( ) >= <NUM_LIT:1> <EOL> group . add_element ( ) . CopyFrom ( path . element ( <NUM_LIT:0> ) ) <EOL> def v3_reference_to_v3_property_value ( self , v3_ref , v3_property_value ) : <EOL> """<STR_LIT>""" <EOL> v3_property_value . Clear ( ) <EOL> reference_value = v3_property_value . mutable_referencevalue ( ) <EOL> if v3_ref . has_app ( ) : <EOL> reference_value . set_app ( v3_ref . app ( ) ) <EOL> if v3_ref . has_name_space ( ) : <EOL> reference_value . set_name_space ( v3_ref . name_space ( ) ) <EOL> for v3_path_element in v3_ref . path ( ) . element_list ( ) : <EOL> v3_ref_value_path_element = reference_value . add_pathelement ( ) <EOL> if v3_path_element . has_type ( ) : <EOL> v3_ref_value_path_element . set_type ( v3_path_element . type ( ) ) <EOL> if v3_path_element . has_id ( ) : <EOL> v3_ref_value_path_element . set_id ( v3_path_element . id ( ) ) <EOL> if v3_path_element . has_name ( ) : <EOL> v3_ref_value_path_element . set_name ( v3_path_element . name ( ) ) <EOL> def __v3_reference_value_to_v3_reference ( self , v3_ref_value , v3_ref ) : <EOL> """<STR_LIT>""" <EOL> v3_ref . Clear ( ) <EOL> if v3_ref_value . has_app ( ) : <EOL> v3_ref . set_app ( v3_ref_value . app ( ) ) <EOL> if v3_ref_value . has_name_space ( ) : <EOL> v3_ref . set_name_space ( v3_ref_value . name_space ( ) ) <EOL> for v3_ref_value_path_element in v3_ref_value . pathelement_list ( ) : <EOL> v3_path_element = v3_ref . mutable_path ( ) . add_element ( ) <EOL> if v3_ref_value_path_element . has_type ( ) : <EOL> v3_path_element . set_type ( v3_ref_value_path_element . type ( ) ) <EOL> if v3_ref_value_path_element . has_id ( ) : <EOL> v3_path_element . set_id ( v3_ref_value_path_element . id ( ) ) <EOL> if v3_ref_value_path_element . has_name ( ) : <EOL> v3_path_element . set_name ( v3_ref_value_path_element . name ( ) ) <EOL> class _QueryConverter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , entity_converter ) : <EOL> self . _entity_converter = entity_converter <EOL> def get_entity_converter ( self ) : <EOL> return self . _entity_converter <EOL> def _v3_filter_to_v1_property_filter ( self , v3_filter , v1_property_filter ) : <EOL> """<STR_LIT>""" <EOL> check_conversion ( v3_filter . property_size ( ) == <NUM_LIT:1> , <EOL> '<STR_LIT>' ) <EOL> check_conversion ( v3_filter . op ( ) <= <NUM_LIT:5> , <EOL> '<STR_LIT>' % v3_filter . op ( ) ) <EOL> v1_property_filter . Clear ( ) <EOL> v1_property_filter . op = v3_filter . op ( ) <EOL> v1_property_filter . property . name = v3_filter . property ( <NUM_LIT:0> ) . name ( ) <EOL> self . _entity_converter . v3_property_to_v1_value ( <EOL> v3_filter . property ( <NUM_LIT:0> ) , True , v1_property_filter . value ) <EOL> def _v3_query_to_v1_ancestor_filter ( self , v3_query , v1_property_filter ) : <EOL> """<STR_LIT>""" <EOL> v1_property_filter . Clear ( ) <EOL> v1_property_filter . set_operator ( <EOL> googledatastore . PropertyFilter . HAS_ANCESTOR ) <EOL> prop = v1_property_filter . property <EOL> prop . set_name ( PROPERTY_NAME_KEY ) <EOL> self . _entity_converter . v3_to_v1_key ( <EOL> v3_query . ancestor ( ) , <EOL> v1_property_filter . value . mutable_key_value ) <EOL> def v3_order_to_v1_order ( self , v3_order , v1_order ) : <EOL> """<STR_LIT>""" <EOL> v1_order . property . name = v3_order . property ( ) <EOL> if v3_order . has_direction ( ) : <EOL> v1_order . direction = v3_order . direction ( ) <EOL> def _v3_filter_to_v4_property_filter ( self , v3_filter , v4_property_filter ) : <EOL> """<STR_LIT>""" <EOL> check_conversion ( v3_filter . property_size ( ) == <NUM_LIT:1> , <EOL> '<STR_LIT>' ) <EOL> check_conversion ( v3_filter . op ( ) <= <NUM_LIT:5> , <EOL> '<STR_LIT>' % v3_filter . op ( ) ) <EOL> v4_property_filter . Clear ( ) <EOL> v4_property_filter . set_operator ( v3_filter . op ( ) ) <EOL> v4_property_filter . mutable_property ( ) . set_name ( v3_filter . property ( <NUM_LIT:0> ) . name ( ) ) <EOL> self . _entity_converter . v3_property_to_v4_value ( <EOL> v3_filter . property ( <NUM_LIT:0> ) , True , v4_property_filter . mutable_value ( ) ) <EOL> def _v3_query_to_v4_ancestor_filter ( self , v3_query , v4_property_filter ) : <EOL> """<STR_LIT>""" <EOL> v4_property_filter . Clear ( ) <EOL> v4_property_filter . set_operator ( <EOL> datastore_v4_pb . PropertyFilter . HAS_ANCESTOR ) <EOL> prop = v4_property_filter . mutable_property ( ) <EOL> prop . set_name ( PROPERTY_NAME_KEY ) <EOL> self . _entity_converter . v3_to_v4_key ( <EOL> v3_query . ancestor ( ) , <EOL> v4_property_filter . mutable_value ( ) . mutable_key_value ( ) ) <EOL> def v3_order_to_v4_order ( self , v3_order , v4_order ) : <EOL> """<STR_LIT>""" <EOL> v4_order . mutable_property ( ) . set_name ( v3_order . property ( ) ) <EOL> if v3_order . has_direction ( ) : <EOL> v4_order . set_direction ( v3_order . direction ( ) ) <EOL> def get_entity_converter ( id_resolver = None ) : <EOL> """<STR_LIT>""" <EOL> id_resolver = id_resolver or _IdentityIdResolver ( ) <EOL> return _EntityConverter ( id_resolver ) </s>
