<s> """<STR_LIT>""" <EOL> import datetime <EOL> import logging <EOL> import os <EOL> import pickle <EOL> import struct <EOL> import sys <EOL> import tempfile <EOL> import threading <EOL> import types <EOL> import warnings <EOL> from google . appengine . api import api_base_pb <EOL> from google . appengine . api import datastore <EOL> from google . appengine . api import datastore_admin <EOL> from google . appengine . api import datastore_errors <EOL> from google . appengine . api import datastore_types <EOL> from google . appengine . api import users <EOL> from google . appengine . datastore import datastore_pb <EOL> from google . appengine . datastore import datastore_index <EOL> from google . appengine . runtime import apiproxy_errors <EOL> from google . net . proto import ProtocolBuffer <EOL> from google . appengine . datastore import entity_pb <EOL> warnings . filterwarnings ( '<STR_LIT:ignore>' , '<STR_LIT>' ) <EOL> entity_pb . Reference . __hash__ = lambda self : hash ( self . Encode ( ) ) <EOL> datastore_pb . Query . __hash__ = lambda self : hash ( self . Encode ( ) ) <EOL> class DatastoreFileStub ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app_id , datastore_file , history_file , <EOL> require_indexes = False ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( app_id , types . StringTypes ) and app_id != '<STR_LIT>' <EOL> self . __app_id = app_id <EOL> self . __datastore_file = datastore_file <EOL> self . __history_file = history_file <EOL> self . __entities = { } <EOL> self . __tx_snapshot = { } <EOL> self . __queries = { } <EOL> self . __transactions = { } <EOL> self . __indexes = { } <EOL> self . __require_indexes = require_indexes <EOL> self . __query_history = { } <EOL> self . __next_id = <NUM_LIT:1> <EOL> self . __next_cursor = <NUM_LIT:1> <EOL> self . __next_tx_handle = <NUM_LIT:1> <EOL> self . __next_index_id = <NUM_LIT:1> <EOL> self . __id_lock = threading . Lock ( ) <EOL> self . __cursor_lock = threading . Lock ( ) <EOL> self . __tx_handle_lock = threading . Lock ( ) <EOL> self . __index_id_lock = threading . Lock ( ) <EOL> self . __tx_lock = threading . Lock ( ) <EOL> self . __entities_lock = threading . Lock ( ) <EOL> self . __file_lock = threading . Lock ( ) <EOL> self . __indexes_lock = threading . Lock ( ) <EOL> self . Read ( ) <EOL> def Clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . __entities = { } <EOL> self . __queries = { } <EOL> self . __transactions = { } <EOL> self . __query_history = { } <EOL> def Read ( self ) : <EOL> """<STR_LIT>""" <EOL> pb_exceptions = ( ProtocolBuffer . ProtocolBufferDecodeError , LookupError , <EOL> TypeError , ValueError ) <EOL> error_msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if self . __datastore_file and self . __datastore_file != '<STR_LIT>' : <EOL> for encoded_entity in self . __ReadPickled ( self . __datastore_file ) : <EOL> try : <EOL> entity = entity_pb . EntityProto ( encoded_entity ) <EOL> except pb_exceptions , e : <EOL> raise datastore_errors . InternalError ( error_msg % <EOL> ( self . __datastore_file , e ) ) <EOL> last_path = entity . key ( ) . path ( ) . element_list ( ) [ - <NUM_LIT:1> ] <EOL> app_kind = ( entity . key ( ) . app ( ) , last_path . type ( ) ) <EOL> kind_dict = self . __entities . setdefault ( app_kind , { } ) <EOL> kind_dict [ entity . key ( ) ] = entity <EOL> if last_path . has_id ( ) and last_path . id ( ) >= self . __next_id : <EOL> self . __next_id = last_path . id ( ) + <NUM_LIT:1> <EOL> self . __query_history = { } <EOL> for encoded_query , count in self . __ReadPickled ( self . __history_file ) : <EOL> try : <EOL> query_pb = datastore_pb . Query ( encoded_query ) <EOL> except pb_exceptions , e : <EOL> raise datastore_errors . InternalError ( error_msg % <EOL> ( self . __history_file , e ) ) <EOL> if query_pb in self . __query_history : <EOL> self . __query_history [ query_pb ] += count <EOL> else : <EOL> self . __query_history [ query_pb ] = count <EOL> def Write ( self ) : <EOL> """<STR_LIT>""" <EOL> self . __WriteDatastore ( ) <EOL> self . __WriteHistory ( ) <EOL> def __WriteDatastore ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __datastore_file and self . __datastore_file != '<STR_LIT>' : <EOL> encoded = [ ] <EOL> for kind_dict in self . __entities . values ( ) : <EOL> for entity in kind_dict . values ( ) : <EOL> encoded . append ( entity . Encode ( ) ) <EOL> self . __WritePickled ( encoded , self . __datastore_file ) <EOL> def __WriteHistory ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __history_file and self . __history_file != '<STR_LIT>' : <EOL> encoded = [ ( query . Encode ( ) , count ) <EOL> for query , count in self . __query_history . items ( ) ] <EOL> self . __WritePickled ( encoded , self . __history_file ) <EOL> def __ReadPickled ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> self . __file_lock . acquire ( ) <EOL> try : <EOL> try : <EOL> if filename and filename != '<STR_LIT>' and os . path . isfile ( filename ) : <EOL> return pickle . load ( open ( filename , '<STR_LIT:rb>' ) ) <EOL> else : <EOL> logging . warning ( '<STR_LIT>' , filename ) <EOL> except ( AttributeError , LookupError , NameError , TypeError , <EOL> ValueError , struct . error , pickle . PickleError ) , e : <EOL> raise datastore_errors . InternalError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( filename , e ) ) <EOL> finally : <EOL> self . __file_lock . release ( ) <EOL> return [ ] <EOL> def __WritePickled ( self , obj , filename , openfile = file ) : <EOL> """<STR_LIT>""" <EOL> if not filename or filename == '<STR_LIT>' or not obj : <EOL> return <EOL> tmpfile = openfile ( os . tempnam ( os . path . dirname ( filename ) ) , '<STR_LIT:wb>' ) <EOL> pickle . dump ( obj , tmpfile , <NUM_LIT:1> ) <EOL> tmpfile . close ( ) <EOL> self . __file_lock . acquire ( ) <EOL> try : <EOL> try : <EOL> os . rename ( tmpfile . name , filename ) <EOL> except OSError : <EOL> try : <EOL> os . remove ( filename ) <EOL> except : <EOL> pass <EOL> os . rename ( tmpfile . name , filename ) <EOL> finally : <EOL> self . __file_lock . release ( ) <EOL> def MakeSyncCall ( self , service , call , request , response ) : <EOL> """<STR_LIT>""" <EOL> assert service == '<STR_LIT>' <EOL> explanation = [ ] <EOL> assert request . IsInitialized ( explanation ) , explanation <EOL> ( getattr ( self , "<STR_LIT>" + call ) ) ( request , response ) <EOL> assert response . IsInitialized ( explanation ) , explanation <EOL> def ResolveAppId ( self , app ) : <EOL> """<STR_LIT>""" <EOL> assert app != '<STR_LIT>' <EOL> if app == datastore . _LOCAL_APP_ID : <EOL> return self . __app_id <EOL> else : <EOL> return app <EOL> def QueryHistory ( self ) : <EOL> """<STR_LIT>""" <EOL> return dict ( ( pb , times ) for pb , times in self . __query_history . items ( ) <EOL> if pb . app ( ) == self . __app_id ) <EOL> def _Dynamic_Put ( self , put_request , put_response ) : <EOL> clones = [ ] <EOL> for entity in put_request . entity_list ( ) : <EOL> clone = entity_pb . EntityProto ( ) <EOL> clone . CopyFrom ( entity ) <EOL> clones . append ( clone ) <EOL> assert clone . has_key ( ) <EOL> assert clone . key ( ) . path ( ) . element_size ( ) > <NUM_LIT:0> <EOL> app = self . ResolveAppId ( clone . key ( ) . app ( ) ) <EOL> clone . mutable_key ( ) . set_app ( app ) <EOL> last_path = clone . key ( ) . path ( ) . element_list ( ) [ - <NUM_LIT:1> ] <EOL> if last_path . id ( ) == <NUM_LIT:0> and not last_path . has_name ( ) : <EOL> self . __id_lock . acquire ( ) <EOL> last_path . set_id ( self . __next_id ) <EOL> self . __next_id += <NUM_LIT:1> <EOL> self . __id_lock . release ( ) <EOL> assert clone . entity_group ( ) . element_size ( ) == <NUM_LIT:0> <EOL> group = clone . mutable_entity_group ( ) <EOL> root = clone . key ( ) . path ( ) . element ( <NUM_LIT:0> ) <EOL> group . add_element ( ) . CopyFrom ( root ) <EOL> else : <EOL> assert ( clone . has_entity_group ( ) and <EOL> clone . entity_group ( ) . element_size ( ) > <NUM_LIT:0> ) <EOL> self . __entities_lock . acquire ( ) <EOL> try : <EOL> for clone in clones : <EOL> last_path = clone . key ( ) . path ( ) . element_list ( ) [ - <NUM_LIT:1> ] <EOL> kind_dict = self . __entities . setdefault ( ( app , last_path . type ( ) ) , { } ) <EOL> kind_dict [ clone . key ( ) ] = clone <EOL> finally : <EOL> self . __entities_lock . release ( ) <EOL> if not put_request . has_transaction ( ) : <EOL> self . __WriteDatastore ( ) <EOL> put_response . key_list ( ) . extend ( [ c . key ( ) for c in clones ] ) <EOL> def _Dynamic_Get ( self , get_request , get_response ) : <EOL> for key in get_request . key_list ( ) : <EOL> app = self . ResolveAppId ( key . app ( ) ) <EOL> key . set_app ( app ) <EOL> last_path = key . path ( ) . element_list ( ) [ - <NUM_LIT:1> ] <EOL> group = get_response . add_entity ( ) <EOL> try : <EOL> entity = self . __entities [ app , last_path . type ( ) ] [ key ] <EOL> except KeyError : <EOL> entity = None <EOL> if entity : <EOL> group . mutable_entity ( ) . CopyFrom ( entity ) <EOL> def _Dynamic_Delete ( self , delete_request , delete_response ) : <EOL> self . __entities_lock . acquire ( ) <EOL> try : <EOL> for key in delete_request . key_list ( ) : <EOL> try : <EOL> app = self . ResolveAppId ( key . app ( ) ) <EOL> key . set_app ( app ) <EOL> kind = key . path ( ) . element_list ( ) [ - <NUM_LIT:1> ] . type ( ) <EOL> del self . __entities [ app , kind ] [ key ] <EOL> if not self . __entities [ app , kind ] : <EOL> del self . __entities [ app , kind ] <EOL> except KeyError : <EOL> pass <EOL> if not delete_request . has_transaction ( ) : <EOL> self . __WriteDatastore ( ) <EOL> finally : <EOL> self . __entities_lock . release ( ) <EOL> def _Dynamic_RunQuery ( self , query , query_result ) : <EOL> if not self . __tx_lock . acquire ( False ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> datastore_pb . Error . BAD_REQUEST , "<STR_LIT>" ) <EOL> else : <EOL> self . __tx_lock . release ( ) <EOL> app = self . ResolveAppId ( query . app ( ) ) <EOL> if self . __require_indexes : <EOL> required_index = datastore_index . CompositeIndexForQuery ( query ) <EOL> if required_index is not None : <EOL> kind , ancestor , props , num_eq_filters = required_index <EOL> required_key = kind , ancestor , props <EOL> indexes = self . __indexes . get ( app ) <EOL> if not indexes : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> datastore_pb . Error . BAD_REQUEST , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> eq_filters_set = set ( props [ : num_eq_filters ] ) <EOL> remaining_filters = props [ num_eq_filters : ] <EOL> for index in indexes : <EOL> definition = datastore_admin . ProtoToIndexDefinition ( index ) <EOL> index_key = datastore_index . IndexToKey ( definition ) <EOL> if required_key == index_key : <EOL> break <EOL> if num_eq_filters > <NUM_LIT:1> and ( kind , ancestor ) == index_key [ : <NUM_LIT:2> ] : <EOL> this_props = index_key [ <NUM_LIT:2> ] <EOL> this_eq_filters_set = set ( this_props [ : num_eq_filters ] ) <EOL> this_remaining_filters = this_props [ num_eq_filters : ] <EOL> if ( eq_filters_set == this_eq_filters_set and <EOL> remaining_filters == this_remaining_filters ) : <EOL> break <EOL> else : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> datastore_pb . Error . BAD_REQUEST , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> try : <EOL> query . set_app ( app ) <EOL> results = self . __entities [ app , query . kind ( ) ] . values ( ) <EOL> results = [ datastore . Entity . _FromPb ( pb ) for pb in results ] <EOL> except KeyError : <EOL> results = [ ] <EOL> if query . has_ancestor ( ) : <EOL> ancestor_path = query . ancestor ( ) . path ( ) . element_list ( ) <EOL> def is_descendant ( entity ) : <EOL> path = entity . key ( ) . _Key__reference . path ( ) . element_list ( ) <EOL> return path [ : len ( ancestor_path ) ] == ancestor_path <EOL> results = filter ( is_descendant , results ) <EOL> operators = { datastore_pb . Query_Filter . LESS_THAN : '<STR_LIT:<>' , <EOL> datastore_pb . Query_Filter . LESS_THAN_OR_EQUAL : '<STR_LIT>' , <EOL> datastore_pb . Query_Filter . GREATER_THAN : '<STR_LIT:>>' , <EOL> datastore_pb . Query_Filter . GREATER_THAN_OR_EQUAL : '<STR_LIT>' , <EOL> datastore_pb . Query_Filter . EQUAL : '<STR_LIT>' , <EOL> } <EOL> for filt in query . filter_list ( ) : <EOL> assert filt . op ( ) != datastore_pb . Query_Filter . IN <EOL> prop = filt . property ( <NUM_LIT:0> ) . name ( ) . decode ( '<STR_LIT:utf-8>' ) <EOL> op = operators [ filt . op ( ) ] <EOL> def passes ( entity ) : <EOL> """<STR_LIT>""" <EOL> entity_vals = entity . get ( prop , [ ] ) <EOL> if type ( entity_vals ) is not types . ListType : <EOL> entity_vals = [ entity_vals ] <EOL> entity_property_list = [ datastore_types . ToPropertyPb ( prop , value ) <EOL> for value in entity_vals ] <EOL> for entity_prop in entity_property_list : <EOL> fixed_entity_val = datastore_types . FromPropertyPb ( entity_prop ) <EOL> for filter_prop in filt . property_list ( ) : <EOL> filter_val = datastore_types . FromPropertyPb ( filter_prop ) <EOL> comp = u'<STR_LIT>' % ( fixed_entity_val , op , filter_val ) <EOL> logging . log ( logging . DEBUG - <NUM_LIT:1> , <EOL> '<STR_LIT>' , comp ) <EOL> if eval ( comp ) : <EOL> return True <EOL> return False <EOL> results = filter ( passes , results ) <EOL> for order in query . order_list ( ) : <EOL> prop = order . property ( ) . decode ( '<STR_LIT:utf-8>' ) <EOL> results = [ entity for entity in results if prop in entity ] <EOL> def order_compare ( a , b ) : <EOL> """<STR_LIT>""" <EOL> for o in query . order_list ( ) : <EOL> prop = o . property ( ) . decode ( '<STR_LIT:utf-8>' ) <EOL> a_values = a [ prop ] <EOL> if not isinstance ( a_values , types . ListType ) : <EOL> a_values = [ a_values ] <EOL> b_values = b [ prop ] <EOL> if not isinstance ( b_values , types . ListType ) : <EOL> b_values = [ b_values ] <EOL> cmped = cmp ( min ( a_values ) , min ( b_values ) ) <EOL> if o . direction ( ) is datastore_pb . Query_Order . DESCENDING : <EOL> cmped = - cmped <EOL> if cmped != <NUM_LIT:0> : <EOL> return cmped <EOL> return <NUM_LIT:0> <EOL> results . sort ( order_compare ) <EOL> if query . has_limit ( ) : <EOL> results = results [ : query . limit ( ) ] <EOL> clone = datastore_pb . Query ( ) <EOL> clone . CopyFrom ( query ) <EOL> clone . clear_hint ( ) <EOL> if clone in self . __query_history : <EOL> self . __query_history [ clone ] += <NUM_LIT:1> <EOL> else : <EOL> self . __query_history [ clone ] = <NUM_LIT:1> <EOL> self . __WriteHistory ( ) <EOL> results = [ e . _ToPb ( ) for e in results ] <EOL> self . __cursor_lock . acquire ( ) <EOL> cursor = self . __next_cursor <EOL> self . __next_cursor += <NUM_LIT:1> <EOL> self . __cursor_lock . release ( ) <EOL> self . __queries [ cursor ] = ( results , len ( results ) ) <EOL> query_result . mutable_cursor ( ) . set_cursor ( cursor ) <EOL> query_result . set_more_results ( len ( results ) > <NUM_LIT:0> ) <EOL> def _Dynamic_Next ( self , next_request , query_result ) : <EOL> cursor = next_request . cursor ( ) . cursor ( ) <EOL> try : <EOL> results , orig_count = self . __queries [ cursor ] <EOL> except KeyError : <EOL> raise apiproxy_errors . ApplicationError ( datastore_pb . Error . BAD_REQUEST , <EOL> '<STR_LIT>' % cursor ) <EOL> count = next_request . count ( ) <EOL> for r in results [ : count ] : <EOL> query_result . add_result ( ) . CopyFrom ( r ) <EOL> del results [ : count ] <EOL> query_result . set_more_results ( len ( results ) > <NUM_LIT:0> ) <EOL> def _Dynamic_Count ( self , query , integer64proto ) : <EOL> query_result = datastore_pb . QueryResult ( ) <EOL> self . _Dynamic_RunQuery ( query , query_result ) <EOL> cursor = query_result . cursor ( ) . cursor ( ) <EOL> results , count = self . __queries [ cursor ] <EOL> integer64proto . set_value ( count ) <EOL> del self . __queries [ cursor ] <EOL> def _Dynamic_BeginTransaction ( self , request , transaction ) : <EOL> self . __tx_handle_lock . acquire ( ) <EOL> handle = self . __next_tx_handle <EOL> self . __next_tx_handle += <NUM_LIT:1> <EOL> self . __tx_handle_lock . release ( ) <EOL> self . __transactions [ handle ] = None <EOL> transaction . set_handle ( handle ) <EOL> self . __tx_lock . acquire ( ) <EOL> snapshot = [ ( app_kind , dict ( entities ) ) <EOL> for app_kind , entities in self . __entities . items ( ) ] <EOL> self . __tx_snapshot = dict ( snapshot ) <EOL> def _Dynamic_Commit ( self , transaction , transaction_response ) : <EOL> if not self . __transactions . has_key ( transaction . handle ( ) ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> datastore_pb . Error . BAD_REQUEST , <EOL> '<STR_LIT>' % transaction . handle ( ) ) <EOL> self . __tx_snapshot = { } <EOL> try : <EOL> self . __WriteDatastore ( ) <EOL> finally : <EOL> self . __tx_lock . release ( ) <EOL> def _Dynamic_Rollback ( self , transaction , transaction_response ) : <EOL> if not self . __transactions . has_key ( transaction . handle ( ) ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> datastore_pb . Error . BAD_REQUEST , <EOL> '<STR_LIT>' % transaction . handle ( ) ) <EOL> self . __entities = self . __tx_snapshot <EOL> self . __tx_snapshot = { } <EOL> self . __tx_lock . release ( ) <EOL> def _Dynamic_GetSchema ( self , app_str , schema ) : <EOL> minint = - sys . maxint - <NUM_LIT:1> <EOL> app_str = self . ResolveAppId ( app_str . value ( ) ) <EOL> kinds = [ ] <EOL> for app , kind in self . __entities : <EOL> if app == app_str : <EOL> kind_pb = entity_pb . EntityProto ( ) <EOL> kind_pb . mutable_key ( ) . set_app ( '<STR_LIT>' ) <EOL> kind_pb . mutable_key ( ) . mutable_path ( ) . add_element ( ) . set_type ( kind ) <EOL> kind_pb . mutable_entity_group ( ) <EOL> kinds . append ( kind_pb ) <EOL> props = { } <EOL> for entity in self . __entities [ ( app , kind ) ] . values ( ) : <EOL> for prop in entity . property_list ( ) : <EOL> if prop . name ( ) not in props : <EOL> props [ prop . name ( ) ] = entity_pb . PropertyValue ( ) <EOL> props [ prop . name ( ) ] . MergeFrom ( prop . value ( ) ) <EOL> for value_pb in props . values ( ) : <EOL> if value_pb . has_int64value ( ) : <EOL> value_pb . set_int64value ( minint ) <EOL> if value_pb . has_booleanvalue ( ) : <EOL> value_pb . set_booleanvalue ( False ) <EOL> if value_pb . has_stringvalue ( ) : <EOL> value_pb . set_stringvalue ( '<STR_LIT>' ) <EOL> if value_pb . has_doublevalue ( ) : <EOL> value_pb . set_doublevalue ( float ( '<STR_LIT>' ) ) <EOL> if value_pb . has_pointvalue ( ) : <EOL> value_pb . mutable_pointvalue ( ) . set_x ( float ( '<STR_LIT>' ) ) <EOL> value_pb . mutable_pointvalue ( ) . set_y ( float ( '<STR_LIT>' ) ) <EOL> if value_pb . has_uservalue ( ) : <EOL> value_pb . mutable_uservalue ( ) . set_gaiaid ( minint ) <EOL> value_pb . mutable_uservalue ( ) . set_email ( '<STR_LIT>' ) <EOL> value_pb . mutable_uservalue ( ) . set_auth_domain ( '<STR_LIT>' ) <EOL> value_pb . mutable_uservalue ( ) . set_nickname ( '<STR_LIT>' ) <EOL> elif value_pb . has_referencevalue ( ) : <EOL> value_pb . clear_referencevalue ( ) <EOL> value_pb . mutable_referencevalue ( ) . set_app ( '<STR_LIT>' ) <EOL> for name , value_pb in props . items ( ) : <EOL> prop_pb = kind_pb . add_property ( ) <EOL> prop_pb . set_name ( name ) <EOL> prop_pb . mutable_value ( ) . CopyFrom ( value_pb ) <EOL> schema . kind_list ( ) . extend ( kinds ) <EOL> def _Dynamic_CreateIndex ( self , index , id_response ) : <EOL> if index . id ( ) != <NUM_LIT:0> : <EOL> raise apiproxy_errors . ApplicationError ( datastore_pb . Error . BAD_REQUEST , <EOL> '<STR_LIT>' ) <EOL> elif self . __FindIndex ( index ) : <EOL> raise apiproxy_errors . ApplicationError ( datastore_pb . Error . BAD_REQUEST , <EOL> '<STR_LIT>' ) <EOL> self . __index_id_lock . acquire ( ) <EOL> index . set_id ( self . __next_index_id ) <EOL> id_response . set_value ( self . __next_index_id ) <EOL> self . __next_index_id += <NUM_LIT:1> <EOL> self . __index_id_lock . release ( ) <EOL> clone = entity_pb . CompositeIndex ( ) <EOL> clone . CopyFrom ( index ) <EOL> app = self . ResolveAppId ( index . app_id ( ) ) <EOL> clone . set_app_id ( app ) <EOL> self . __indexes_lock . acquire ( ) <EOL> try : <EOL> if app not in self . __indexes : <EOL> self . __indexes [ app ] = [ ] <EOL> self . __indexes [ app ] . append ( clone ) <EOL> finally : <EOL> self . __indexes_lock . release ( ) <EOL> def _Dynamic_GetIndices ( self , app_str , composite_indices ) : <EOL> composite_indices . index_list ( ) . extend ( <EOL> self . __indexes . get ( self . ResolveAppId ( app_str . value ( ) ) , [ ] ) ) <EOL> def _Dynamic_UpdateIndex ( self , index , void ) : <EOL> stored_index = self . __FindIndex ( index ) <EOL> if not stored_index : <EOL> raise apiproxy_errors . ApplicationError ( datastore_pb . Error . BAD_REQUEST , <EOL> "<STR_LIT>" ) <EOL> elif index . state ( ) != stored_index . state ( ) + <NUM_LIT:1> : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> datastore_pb . Error . BAD_REQUEST , <EOL> "<STR_LIT>" % <EOL> ( entity_pb . CompositeIndex . State_Name ( stored_index . state ( ) ) , <EOL> ( entity_pb . CompositeIndex . State_Name ( index . state ( ) ) ) ) ) <EOL> self . __indexes_lock . acquire ( ) <EOL> try : <EOL> stored_index . set_state ( index . state ( ) ) <EOL> finally : <EOL> self . __indexes_lock . release ( ) <EOL> def _Dynamic_DeleteIndex ( self , index , void ) : <EOL> stored_index = self . __FindIndex ( index ) <EOL> if not stored_index : <EOL> raise apiproxy_errors . ApplicationError ( datastore_pb . Error . BAD_REQUEST , <EOL> "<STR_LIT>" ) <EOL> app = self . ResolveAppId ( index . app_id ( ) ) <EOL> self . __indexes_lock . acquire ( ) <EOL> try : <EOL> self . __indexes [ app ] . remove ( stored_index ) <EOL> finally : <EOL> self . __indexes_lock . release ( ) <EOL> def __FindIndex ( self , index ) : <EOL> """<STR_LIT>""" <EOL> app = self . ResolveAppId ( index . app_id ( ) ) <EOL> if app in self . __indexes : <EOL> for stored_index in self . __indexes [ app ] : <EOL> if index . definition ( ) == stored_index . definition ( ) : <EOL> return stored_index <EOL> return None </s>
