<s> """<STR_LIT>""" <EOL> from google . appengine . api import namespace_manager <EOL> from google . appengine . ext import ndb <EOL> import webapp2 <EOL> class Counter ( ndb . Model ) : <EOL> count = ndb . IntegerProperty ( ) <EOL> @ ndb . transactional <EOL> def update_counter ( name ) : <EOL> """<STR_LIT>""" <EOL> counter = Counter . get_by_id ( name ) <EOL> if counter is None : <EOL> counter = Counter ( id = name , count = <NUM_LIT:0> ) <EOL> counter . count += <NUM_LIT:1> <EOL> counter . put ( ) <EOL> return counter . count <EOL> class DatastoreCounterHandler ( webapp2 . RequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def get ( self , namespace = '<STR_LIT:default>' ) : <EOL> global_count = update_counter ( '<STR_LIT>' ) <EOL> previous_namespace = namespace_manager . get_namespace ( ) <EOL> try : <EOL> namespace_manager . set_namespace ( namespace ) <EOL> namespace_count = update_counter ( '<STR_LIT>' ) <EOL> finally : <EOL> namespace_manager . set_namespace ( previous_namespace ) <EOL> self . response . write ( '<STR_LIT>' . format ( <EOL> global_count , namespace , namespace_count ) ) <EOL> app = webapp2 . WSGIApplication ( [ <EOL> ( r'<STR_LIT>' , DatastoreCounterHandler ) , <EOL> ( r'<STR_LIT>' , DatastoreCounterHandler ) <EOL> ] , debug = True ) </s>
