<s> """<STR_LIT>""" <EOL> import cgi <EOL> import csv <EOL> import cStringIO <EOL> import datetime <EOL> import logging <EOL> import math <EOL> import mimetypes <EOL> import os <EOL> import os . path <EOL> import pickle <EOL> import pprint <EOL> import random <EOL> import sys <EOL> import time <EOL> import traceback <EOL> import types <EOL> import urllib <EOL> import urlparse <EOL> import wsgiref . handlers <EOL> try : <EOL> from google . appengine . cron import groctimespecification <EOL> from google . appengine . api import croninfo <EOL> except ImportError : <EOL> HAVE_CRON = False <EOL> else : <EOL> HAVE_CRON = True <EOL> from google . appengine . api import apiproxy_stub_map <EOL> from google . appengine . api import datastore <EOL> from google . appengine . api import datastore_admin <EOL> from google . appengine . api import datastore_types <EOL> from google . appengine . api import datastore_errors <EOL> from google . appengine . api import memcache <EOL> from google . appengine . api . labs import taskqueue <EOL> from google . appengine . api import users <EOL> from google . appengine . ext import db <EOL> from google . appengine . ext import webapp <EOL> from google . appengine . ext . webapp import template <EOL> _DEBUG = True <EOL> class ImageHandler ( webapp . RequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = '<STR_LIT>' <EOL> def get ( self ) : <EOL> image_name = os . path . basename ( self . request . path ) <EOL> content_type , encoding = mimetypes . guess_type ( image_name ) <EOL> if not content_type or not content_type . startswith ( '<STR_LIT>' ) : <EOL> logging . debug ( '<STR_LIT>' , <EOL> image_name , content_type , encoding ) <EOL> self . error ( <NUM_LIT> ) <EOL> return <EOL> directory = os . path . dirname ( __file__ ) <EOL> path = os . path . join ( directory , '<STR_LIT>' , '<STR_LIT>' , image_name ) <EOL> try : <EOL> image_stream = open ( path , '<STR_LIT:rb>' ) <EOL> except IOError , e : <EOL> logging . error ( '<STR_LIT>' , image_name , e ) <EOL> self . error ( <NUM_LIT> ) <EOL> return <EOL> try : <EOL> image_data = image_stream . read ( ) <EOL> finally : <EOL> image_stream . close ( ) <EOL> self . response . headers [ '<STR_LIT:Content-Type>' ] = content_type <EOL> self . response . out . write ( image_data ) <EOL> class BaseRequestHandler ( webapp . RequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def generate ( self , template_name , template_values = { } ) : <EOL> base_path = self . base_path ( ) <EOL> values = { <EOL> '<STR_LIT>' : self . request . environ [ '<STR_LIT>' ] , <EOL> '<STR_LIT:user>' : users . get_current_user ( ) , <EOL> '<STR_LIT>' : self . request , <EOL> '<STR_LIT>' : base_path + DefaultPageHandler . PATH , <EOL> '<STR_LIT>' : base_path + DatastoreQueryHandler . PATH , <EOL> '<STR_LIT>' : base_path + DatastoreEditHandler . PATH , <EOL> '<STR_LIT>' : base_path + DatastoreBatchEditHandler . PATH , <EOL> '<STR_LIT>' : base_path + InteractivePageHandler . PATH , <EOL> '<STR_LIT>' : base_path + InteractiveExecuteHandler . PATH , <EOL> '<STR_LIT>' : base_path + MemcachePageHandler . PATH , <EOL> '<STR_LIT>' : base_path + QueuesPageHandler . PATH , <EOL> '<STR_LIT>' : base_path + XMPPPageHandler . PATH , <EOL> '<STR_LIT>' : base_path + InboundMailPageHandler . PATH , <EOL> } <EOL> if HAVE_CRON : <EOL> values [ '<STR_LIT>' ] = base_path + CronPageHandler . PATH <EOL> values . update ( template_values ) <EOL> directory = os . path . dirname ( __file__ ) <EOL> path = os . path . join ( directory , os . path . join ( '<STR_LIT>' , template_name ) ) <EOL> self . response . out . write ( template . render ( path , values , debug = _DEBUG ) ) <EOL> def base_path ( self ) : <EOL> """<STR_LIT>""" <EOL> path = self . __class__ . PATH <EOL> return self . request . path [ : - len ( path ) ] <EOL> def filter_url ( self , args ) : <EOL> """<STR_LIT>""" <EOL> queries = [ ] <EOL> for arg in args : <EOL> value = self . request . get ( arg ) <EOL> if value : <EOL> queries . append ( arg + '<STR_LIT:=>' + urllib . quote_plus ( self . request . get ( arg ) ) ) <EOL> return self . request . path + '<STR_LIT:?>' + '<STR_LIT:&>' . join ( queries ) <EOL> def in_production ( self ) : <EOL> """<STR_LIT>""" <EOL> server_software = os . environ [ '<STR_LIT>' ] <EOL> return not server_software . startswith ( '<STR_LIT>' ) <EOL> class DefaultPageHandler ( BaseRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = '<STR_LIT:/>' <EOL> def get ( self ) : <EOL> if self . request . path . endswith ( '<STR_LIT:/>' ) : <EOL> base = self . request . path [ : - <NUM_LIT:1> ] <EOL> else : <EOL> base = self . request . path <EOL> self . redirect ( base + DatastoreQueryHandler . PATH ) <EOL> class InteractivePageHandler ( BaseRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = '<STR_LIT>' <EOL> def get ( self ) : <EOL> self . generate ( '<STR_LIT>' ) <EOL> class InteractiveExecuteHandler ( BaseRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = InteractivePageHandler . PATH + '<STR_LIT>' <EOL> def post ( self ) : <EOL> save_stdout = sys . stdout <EOL> results_io = cStringIO . StringIO ( ) <EOL> try : <EOL> sys . stdout = results_io <EOL> code = self . request . get ( '<STR_LIT:code>' ) <EOL> code = code . replace ( "<STR_LIT:\r\n>" , "<STR_LIT:\n>" ) <EOL> try : <EOL> compiled_code = compile ( code , '<STR_LIT>' , '<STR_LIT>' ) <EOL> exec ( compiled_code , globals ( ) ) <EOL> except Exception , e : <EOL> traceback . print_exc ( file = results_io ) <EOL> finally : <EOL> sys . stdout = save_stdout <EOL> results = results_io . getvalue ( ) <EOL> self . generate ( '<STR_LIT>' , { '<STR_LIT>' : results } ) <EOL> class CronPageHandler ( BaseRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = '<STR_LIT>' <EOL> def get ( self , now = None ) : <EOL> """<STR_LIT>""" <EOL> if not now : <EOL> now = datetime . datetime . now ( ) <EOL> values = { '<STR_LIT>' : self . request } <EOL> cron_info = _ParseCronYaml ( ) <EOL> values [ '<STR_LIT>' ] = [ ] <EOL> values [ '<STR_LIT>' ] = str ( now ) <EOL> if cron_info and cron_info . cron : <EOL> for entry in cron_info . cron : <EOL> job = { } <EOL> values [ '<STR_LIT>' ] . append ( job ) <EOL> if entry . description : <EOL> job [ '<STR_LIT:description>' ] = entry . description <EOL> else : <EOL> job [ '<STR_LIT:description>' ] = '<STR_LIT>' <EOL> if entry . timezone : <EOL> job [ '<STR_LIT>' ] = entry . timezone <EOL> job [ '<STR_LIT:url>' ] = entry . url <EOL> job [ '<STR_LIT>' ] = entry . schedule <EOL> schedule = groctimespecification . GrocTimeSpecification ( entry . schedule ) <EOL> matches = schedule . GetMatches ( now , <NUM_LIT:3> ) <EOL> job [ '<STR_LIT>' ] = [ ] <EOL> for match in matches : <EOL> job [ '<STR_LIT>' ] . append ( { '<STR_LIT>' : match . strftime ( "<STR_LIT>" ) , <EOL> '<STR_LIT>' : str ( match - now ) } ) <EOL> self . generate ( '<STR_LIT>' , values ) <EOL> class XMPPPageHandler ( BaseRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = '<STR_LIT>' <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> xmpp_configured = True <EOL> values = { <EOL> '<STR_LIT>' : xmpp_configured , <EOL> '<STR_LIT>' : self . request <EOL> } <EOL> self . generate ( '<STR_LIT>' , values ) <EOL> class InboundMailPageHandler ( BaseRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = '<STR_LIT>' <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> inboundmail_configured = True <EOL> values = { <EOL> '<STR_LIT>' : inboundmail_configured , <EOL> '<STR_LIT>' : self . request <EOL> } <EOL> self . generate ( '<STR_LIT>' , values ) <EOL> class QueuesPageHandler ( BaseRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> self . stub = apiproxy_stub_map . apiproxy . GetStub ( '<STR_LIT>' ) <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> values = { <EOL> '<STR_LIT>' : self . request , <EOL> '<STR_LIT>' : self . stub . GetQueues ( ) , <EOL> } <EOL> self . generate ( '<STR_LIT>' , values ) <EOL> def post ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . request . get ( '<STR_LIT>' ) : <EOL> self . stub . FlushQueue ( self . request . get ( '<STR_LIT>' ) ) <EOL> self . redirect ( self . request . path_url ) <EOL> class TasksPageHandler ( BaseRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = '<STR_LIT>' <EOL> PAGE_SIZE = <NUM_LIT:20> <EOL> def __init__ ( self ) : <EOL> self . stub = apiproxy_stub_map . apiproxy . GetStub ( '<STR_LIT>' ) <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> queue = self . request . get ( '<STR_LIT>' ) <EOL> start = int ( self . request . get ( '<STR_LIT:start>' , <NUM_LIT:0> ) ) <EOL> all_tasks = self . stub . GetTasks ( queue ) <EOL> next_start = start + self . PAGE_SIZE <EOL> tasks = all_tasks [ start : next_start ] <EOL> current_page = int ( start / self . PAGE_SIZE ) + <NUM_LIT:1> <EOL> pages = [ ] <EOL> for number in xrange ( int ( math . ceil ( len ( all_tasks ) / <EOL> float ( self . PAGE_SIZE ) ) ) ) : <EOL> pages . append ( { <EOL> '<STR_LIT>' : number + <NUM_LIT:1> , <EOL> '<STR_LIT:start>' : number * self . PAGE_SIZE <EOL> } ) <EOL> if not all_tasks [ next_start : ] : <EOL> next_start = - <NUM_LIT:1> <EOL> prev_start = start - self . PAGE_SIZE <EOL> if prev_start < <NUM_LIT:0> : <EOL> prev_start = - <NUM_LIT:1> <EOL> values = { <EOL> '<STR_LIT>' : self . request , <EOL> '<STR_LIT>' : queue , <EOL> '<STR_LIT>' : tasks , <EOL> '<STR_LIT>' : self . filter_url ( [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : prev_start , <EOL> '<STR_LIT>' : next_start , <EOL> '<STR_LIT>' : pages , <EOL> '<STR_LIT>' : current_page , <EOL> } <EOL> self . generate ( '<STR_LIT>' , values ) <EOL> def post ( self ) : <EOL> if self . request . get ( '<STR_LIT>' ) : <EOL> self . stub . DeleteTask ( self . request . get ( '<STR_LIT>' ) , self . request . get ( '<STR_LIT>' ) ) <EOL> self . redirect ( self . request . path_url + '<STR_LIT>' + self . request . get ( '<STR_LIT>' ) ) <EOL> return <EOL> class MemcachePageHandler ( BaseRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = '<STR_LIT>' <EOL> TYPES = ( ( str , str , '<STR_LIT>' ) , <EOL> ( unicode , unicode , '<STR_LIT>' ) , <EOL> ( bool , lambda value : MemcachePageHandler . _ToBool ( value ) , '<STR_LIT>' ) , <EOL> ( int , int , '<STR_LIT>' ) , <EOL> ( long , long , '<STR_LIT>' ) , <EOL> ( float , float , '<STR_LIT>' ) ) <EOL> DEFAULT_TYPESTR_FOR_NEW = '<STR_LIT>' <EOL> @ staticmethod <EOL> def _ToBool ( string_value ) : <EOL> """<STR_LIT>""" <EOL> string_value_low = string_value . lower ( ) <EOL> if string_value_low not in ( '<STR_LIT:false>' , '<STR_LIT:true>' ) : <EOL> raise ValueError ( '<STR_LIT>' % string_value ) <EOL> return string_value_low == '<STR_LIT:true>' <EOL> def _GetValueAndType ( self , key ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> value = memcache . get ( key ) <EOL> except ( pickle . UnpicklingError , AttributeError , EOFError , ImportError , <EOL> IndexError ) , e : <EOL> msg = '<STR_LIT>' % e <EOL> return msg , '<STR_LIT:error>' <EOL> if value is None : <EOL> return None , self . DEFAULT_TYPESTR_FOR_NEW <EOL> for typeobj , _ , typestr in self . TYPES : <EOL> if isinstance ( value , typeobj ) : <EOL> break <EOL> else : <EOL> typestr = '<STR_LIT>' <EOL> value = pprint . pformat ( value , indent = <NUM_LIT:2> ) <EOL> return value , typestr <EOL> def _SetValue ( self , key , type_ , value ) : <EOL> """<STR_LIT>""" <EOL> for _ , converter , typestr in self . TYPES : <EOL> if typestr == type_ : <EOL> value = converter ( value ) <EOL> break <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' % type_ ) <EOL> return memcache . set ( key , value ) <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> values = { '<STR_LIT>' : self . request , <EOL> '<STR_LIT:message>' : self . request . get ( '<STR_LIT:message>' ) } <EOL> edit = self . request . get ( '<STR_LIT>' ) <EOL> key = self . request . get ( '<STR_LIT:key>' ) <EOL> if edit : <EOL> key = edit <EOL> values [ '<STR_LIT>' ] = False <EOL> values [ '<STR_LIT>' ] = False <EOL> values [ '<STR_LIT>' ] = True <EOL> values [ '<STR_LIT>' ] = [ typestr for _ , _ , typestr in self . TYPES ] <EOL> elif key : <EOL> values [ '<STR_LIT>' ] = True <EOL> values [ '<STR_LIT>' ] = True <EOL> values [ '<STR_LIT>' ] = False <EOL> else : <EOL> values [ '<STR_LIT>' ] = True <EOL> values [ '<STR_LIT>' ] = False <EOL> values [ '<STR_LIT>' ] = False <EOL> if key : <EOL> values [ '<STR_LIT:key>' ] = key <EOL> values [ '<STR_LIT:value>' ] , values [ '<STR_LIT:type>' ] = self . _GetValueAndType ( key ) <EOL> values [ '<STR_LIT>' ] = values [ '<STR_LIT:value>' ] is not None <EOL> if values [ '<STR_LIT:type>' ] in ( '<STR_LIT>' , '<STR_LIT:error>' ) : <EOL> values [ '<STR_LIT>' ] = False <EOL> else : <EOL> values [ '<STR_LIT>' ] = True <EOL> if values [ '<STR_LIT>' ] : <EOL> memcache_stats = memcache . get_stats ( ) <EOL> if not memcache_stats : <EOL> memcache_stats = { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> } <EOL> values [ '<STR_LIT>' ] = memcache_stats <EOL> try : <EOL> hitratio = memcache_stats [ '<STR_LIT>' ] * <NUM_LIT:100> / ( memcache_stats [ '<STR_LIT>' ] <EOL> + memcache_stats [ '<STR_LIT>' ] ) <EOL> except ZeroDivisionError : <EOL> hitratio = <NUM_LIT:0> <EOL> values [ '<STR_LIT>' ] = hitratio <EOL> delta_t = datetime . timedelta ( seconds = memcache_stats [ '<STR_LIT>' ] ) <EOL> values [ '<STR_LIT>' ] = datetime . datetime . now ( ) - delta_t <EOL> self . generate ( '<STR_LIT>' , values ) <EOL> def _urlencode ( self , query ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:&>' . join ( '<STR_LIT>' % ( urllib . quote_plus ( k . encode ( '<STR_LIT:utf8>' ) ) , <EOL> urllib . quote_plus ( v . encode ( '<STR_LIT:utf8>' ) ) ) <EOL> for k , v in query . iteritems ( ) ) <EOL> def post ( self ) : <EOL> """<STR_LIT>""" <EOL> next_param = { } <EOL> if self . request . get ( '<STR_LIT>' ) : <EOL> if memcache . flush_all ( ) : <EOL> next_param [ '<STR_LIT:message>' ] = '<STR_LIT>' <EOL> else : <EOL> next_param [ '<STR_LIT:message>' ] = '<STR_LIT>' <EOL> elif self . request . get ( '<STR_LIT>' ) : <EOL> next_param [ '<STR_LIT:key>' ] = self . request . get ( '<STR_LIT:key>' ) <EOL> elif self . request . get ( '<STR_LIT>' ) : <EOL> next_param [ '<STR_LIT>' ] = self . request . get ( '<STR_LIT:key>' ) <EOL> elif self . request . get ( '<STR_LIT>' ) : <EOL> key = self . request . get ( '<STR_LIT:key>' ) <EOL> result = memcache . delete ( key ) <EOL> if result == memcache . DELETE_NETWORK_FAILURE : <EOL> next_param [ '<STR_LIT:message>' ] = ( '<STR_LIT>' <EOL> % key ) <EOL> elif result == memcache . DELETE_ITEM_MISSING : <EOL> next_param [ '<STR_LIT:message>' ] = '<STR_LIT>' % key <EOL> elif result == memcache . DELETE_SUCCESSFUL : <EOL> next_param [ '<STR_LIT:message>' ] = '<STR_LIT>' % key <EOL> else : <EOL> next_param [ '<STR_LIT:message>' ] = ( '<STR_LIT>' <EOL> '<STR_LIT>' % key ) <EOL> elif self . request . get ( '<STR_LIT>' ) : <EOL> key = self . request . get ( '<STR_LIT:key>' ) <EOL> value = self . request . get ( '<STR_LIT:value>' ) <EOL> type_ = self . request . get ( '<STR_LIT:type>' ) <EOL> next_param [ '<STR_LIT:key>' ] = key <EOL> try : <EOL> if self . _SetValue ( key , type_ , value ) : <EOL> next_param [ '<STR_LIT:message>' ] = '<STR_LIT>' % key <EOL> else : <EOL> next_param [ '<STR_LIT:message>' ] = '<STR_LIT>' % key <EOL> except ValueError , e : <EOL> next_param [ '<STR_LIT:message>' ] = '<STR_LIT>' % e <EOL> elif self . request . get ( '<STR_LIT>' ) : <EOL> next_param [ '<STR_LIT:key>' ] = self . request . get ( '<STR_LIT:key>' ) <EOL> else : <EOL> next_param [ '<STR_LIT:message>' ] = '<STR_LIT>' <EOL> next = self . request . path_url <EOL> if next_param : <EOL> next = '<STR_LIT>' % ( next , self . _urlencode ( next_param ) ) <EOL> self . redirect ( next ) <EOL> class DatastoreRequestHandler ( BaseRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def start ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . request . get_range ( '<STR_LIT:start>' , min_value = <NUM_LIT:0> , default = <NUM_LIT:0> ) <EOL> def num ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . request . get_range ( '<STR_LIT>' , min_value = <NUM_LIT:1> , max_value = <NUM_LIT:100> , <EOL> default = <NUM_LIT:10> ) <EOL> def execute_query ( self , start = <NUM_LIT:0> , num = <NUM_LIT:0> , no_order = False ) : <EOL> """<STR_LIT>""" <EOL> kind = self . request . get ( '<STR_LIT>' ) <EOL> if not kind : <EOL> return ( [ ] , <NUM_LIT:0> ) <EOL> query = datastore . Query ( kind ) <EOL> order = self . request . get ( '<STR_LIT>' ) <EOL> order_type = self . request . get ( '<STR_LIT>' ) <EOL> if order and order_type : <EOL> order_type = DataType . get_by_name ( order_type ) . python_type ( ) <EOL> if order . startswith ( '<STR_LIT:->' ) : <EOL> direction = datastore . Query . DESCENDING <EOL> order = order [ <NUM_LIT:1> : ] <EOL> else : <EOL> direction = datastore . Query . ASCENDING <EOL> try : <EOL> query . Order ( ( order , order_type , direction ) ) <EOL> except datastore_errors . BadArgumentError : <EOL> pass <EOL> if not start : <EOL> start = self . start ( ) <EOL> if not num : <EOL> num = self . num ( ) <EOL> total = query . Count ( ) <EOL> entities = query . Get ( start + num ) [ start : ] <EOL> return ( entities , total ) <EOL> def get_key_values ( self , entities ) : <EOL> """<STR_LIT>""" <EOL> key_dict = { } <EOL> for entity in entities : <EOL> for key , value in entity . iteritems ( ) : <EOL> if key_dict . has_key ( key ) : <EOL> key_dict [ key ] . append ( value ) <EOL> else : <EOL> key_dict [ key ] = [ value ] <EOL> return key_dict <EOL> class DatastoreQueryHandler ( DatastoreRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = '<STR_LIT>' <EOL> def get_kinds ( self ) : <EOL> """<STR_LIT>""" <EOL> schema = datastore_admin . GetSchema ( ) <EOL> kinds = [ ] <EOL> for entity_proto in schema : <EOL> kinds . append ( entity_proto . key ( ) . path ( ) . element_list ( ) [ - <NUM_LIT:1> ] . type ( ) ) <EOL> kinds . sort ( ) <EOL> return kinds <EOL> def get ( self ) : <EOL> """<STR_LIT>""" <EOL> result_set , total = self . execute_query ( ) <EOL> key_values = self . get_key_values ( result_set ) <EOL> keys = key_values . keys ( ) <EOL> keys . sort ( ) <EOL> headers = [ ] <EOL> for key in keys : <EOL> sample_value = key_values [ key ] [ <NUM_LIT:0> ] <EOL> headers . append ( { <EOL> '<STR_LIT:name>' : key , <EOL> '<STR_LIT:type>' : DataType . get ( sample_value ) . name ( ) , <EOL> } ) <EOL> entities = [ ] <EOL> edit_path = self . base_path ( ) + DatastoreEditHandler . PATH <EOL> for entity in result_set : <EOL> attributes = [ ] <EOL> for key in keys : <EOL> if entity . has_key ( key ) : <EOL> raw_value = entity [ key ] <EOL> data_type = DataType . get ( raw_value ) <EOL> value = data_type . format ( raw_value ) <EOL> short_value = data_type . short_format ( raw_value ) <EOL> additional_html = data_type . additional_short_value_html ( raw_value ) <EOL> else : <EOL> value = '<STR_LIT>' <EOL> short_value = '<STR_LIT>' <EOL> additional_html = '<STR_LIT>' <EOL> attributes . append ( { <EOL> '<STR_LIT:name>' : key , <EOL> '<STR_LIT:value>' : value , <EOL> '<STR_LIT>' : short_value , <EOL> '<STR_LIT>' : additional_html , <EOL> } ) <EOL> entities . append ( { <EOL> '<STR_LIT:key>' : str ( entity . key ( ) ) , <EOL> '<STR_LIT>' : entity . key ( ) . name ( ) , <EOL> '<STR_LIT>' : entity . key ( ) . id ( ) , <EOL> '<STR_LIT>' : str ( entity . key ( ) ) [ : <NUM_LIT:8> ] + '<STR_LIT>' , <EOL> '<STR_LIT>' : attributes , <EOL> '<STR_LIT>' : edit_path + '<STR_LIT>' + str ( entity . key ( ) ) + '<STR_LIT>' + urllib . quote ( self . request . get ( '<STR_LIT>' ) ) + '<STR_LIT>' + urllib . quote ( self . request . uri ) , <EOL> } ) <EOL> start = self . start ( ) <EOL> num = self . num ( ) <EOL> max_pager_links = <NUM_LIT:8> <EOL> current_page = start / num <EOL> num_pages = int ( math . ceil ( total * <NUM_LIT:1.0> / num ) ) <EOL> page_start = max ( math . floor ( current_page - max_pager_links / <NUM_LIT:2> ) , <NUM_LIT:0> ) <EOL> page_end = min ( page_start + max_pager_links , num_pages ) <EOL> pages = [ ] <EOL> for page in range ( page_start + <NUM_LIT:1> , page_end + <NUM_LIT:1> ) : <EOL> pages . append ( { <EOL> '<STR_LIT>' : page , <EOL> '<STR_LIT:start>' : ( page - <NUM_LIT:1> ) * num , <EOL> } ) <EOL> current_page += <NUM_LIT:1> <EOL> in_production = self . in_production ( ) <EOL> if in_production : <EOL> kinds = None <EOL> else : <EOL> kinds = self . get_kinds ( ) <EOL> values = { <EOL> '<STR_LIT>' : self . request , <EOL> '<STR_LIT>' : in_production , <EOL> '<STR_LIT>' : kinds , <EOL> '<STR_LIT>' : self . request . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . request . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : headers , <EOL> '<STR_LIT>' : entities , <EOL> '<STR_LIT:message>' : self . request . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : pages , <EOL> '<STR_LIT>' : current_page , <EOL> '<STR_LIT>' : num , <EOL> '<STR_LIT>' : - <NUM_LIT:1> , <EOL> '<STR_LIT>' : - <NUM_LIT:1> , <EOL> '<STR_LIT:start>' : start , <EOL> '<STR_LIT>' : total , <EOL> '<STR_LIT>' : self . filter_url ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : self . filter_url ( [ '<STR_LIT>' , '<STR_LIT>' ] ) , <EOL> } <EOL> if current_page > <NUM_LIT:1> : <EOL> values [ '<STR_LIT>' ] = int ( ( current_page - <NUM_LIT:2> ) * num ) <EOL> if current_page < num_pages : <EOL> values [ '<STR_LIT>' ] = int ( current_page * num ) <EOL> self . generate ( '<STR_LIT>' , values ) <EOL> class DatastoreBatchEditHandler ( DatastoreRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = DatastoreQueryHandler . PATH + '<STR_LIT>' <EOL> def post ( self ) : <EOL> kind = self . request . get ( '<STR_LIT>' ) <EOL> keys = [ ] <EOL> index = <NUM_LIT:0> <EOL> num_keys = int ( self . request . get ( '<STR_LIT>' ) ) <EOL> for i in xrange ( <NUM_LIT:1> , num_keys + <NUM_LIT:1> ) : <EOL> key = self . request . get ( '<STR_LIT>' % i ) <EOL> if key : <EOL> keys . append ( key ) <EOL> if self . request . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> num_deleted = <NUM_LIT:0> <EOL> for key in keys : <EOL> datastore . Delete ( datastore . Key ( key ) ) <EOL> num_deleted = num_deleted + <NUM_LIT:1> <EOL> message = '<STR_LIT>' % ( <EOL> num_deleted , ( '<STR_LIT>' , '<STR_LIT:y>' ) [ num_deleted == <NUM_LIT:1> ] ) <EOL> self . redirect ( <EOL> '<STR_LIT>' % ( self . request . get ( '<STR_LIT>' ) , urllib . quote_plus ( message ) ) ) <EOL> return <EOL> self . error ( <NUM_LIT> ) <EOL> class DatastoreEditHandler ( DatastoreRequestHandler ) : <EOL> """<STR_LIT>""" <EOL> PATH = DatastoreQueryHandler . PATH + '<STR_LIT>' <EOL> def get ( self ) : <EOL> entity_key = self . request . get ( '<STR_LIT:key>' ) <EOL> if entity_key : <EOL> key_instance = datastore . Key ( entity_key ) <EOL> entity_key_name = key_instance . name ( ) <EOL> entity_key_id = key_instance . id ( ) <EOL> parent_key = key_instance . parent ( ) <EOL> kind = key_instance . kind ( ) <EOL> entity = datastore . Get ( key_instance ) <EOL> sample_entities = [ entity ] <EOL> else : <EOL> kind = self . request . get ( '<STR_LIT>' ) <EOL> sample_entities = self . execute_query ( ) [ <NUM_LIT:0> ] <EOL> if len ( sample_entities ) < <NUM_LIT:1> : <EOL> next_uri = self . request . get ( '<STR_LIT>' ) <EOL> kind_param = '<STR_LIT>' % kind <EOL> if not kind_param in next_uri : <EOL> if '<STR_LIT:?>' in next_uri : <EOL> next_uri += '<STR_LIT:&>' + kind_param <EOL> else : <EOL> next_uri += '<STR_LIT:?>' + kind_param <EOL> self . redirect ( next_uri ) <EOL> return <EOL> if not entity_key : <EOL> key_instance = None <EOL> entity_key_name = None <EOL> entity_key_id = None <EOL> parent_key = None <EOL> entity = None <EOL> if parent_key : <EOL> parent_kind = parent_key . kind ( ) <EOL> parent_key_string = PseudoBreadcrumbs ( parent_key ) <EOL> else : <EOL> parent_kind = None <EOL> parent_key_string = None <EOL> fields = [ ] <EOL> key_values = self . get_key_values ( sample_entities ) <EOL> for key , sample_values in key_values . iteritems ( ) : <EOL> if entity and entity . has_key ( key ) : <EOL> data_type = DataType . get ( entity [ key ] ) <EOL> else : <EOL> data_type = DataType . get ( sample_values [ <NUM_LIT:0> ] ) <EOL> name = data_type . name ( ) + "<STR_LIT:|>" + key <EOL> if entity and entity . has_key ( key ) : <EOL> value = entity [ key ] <EOL> else : <EOL> value = None <EOL> field = data_type . input_field ( name , value , sample_values ) <EOL> fields . append ( ( key , data_type . name ( ) , field ) ) <EOL> self . generate ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : kind , <EOL> '<STR_LIT:key>' : entity_key , <EOL> '<STR_LIT>' : entity_key_name , <EOL> '<STR_LIT>' : entity_key_id , <EOL> '<STR_LIT>' : fields , <EOL> '<STR_LIT>' : self . request . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : self . request . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : parent_key , <EOL> '<STR_LIT>' : parent_kind , <EOL> '<STR_LIT>' : parent_key_string , <EOL> } ) <EOL> def post ( self ) : <EOL> kind = self . request . get ( '<STR_LIT>' ) <EOL> entity_key = self . request . get ( '<STR_LIT:key>' ) <EOL> if entity_key : <EOL> if self . request . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> datastore . Delete ( datastore . Key ( entity_key ) ) <EOL> self . redirect ( self . request . get ( '<STR_LIT>' ) ) <EOL> return <EOL> entity = datastore . Get ( datastore . Key ( entity_key ) ) <EOL> else : <EOL> entity = datastore . Entity ( kind ) <EOL> args = self . request . arguments ( ) <EOL> for arg in args : <EOL> bar = arg . find ( '<STR_LIT:|>' ) <EOL> if bar > <NUM_LIT:0> : <EOL> data_type_name = arg [ : bar ] <EOL> field_name = arg [ bar + <NUM_LIT:1> : ] <EOL> form_value = self . request . get ( arg ) <EOL> data_type = DataType . get_by_name ( data_type_name ) <EOL> if entity and entity . has_key ( field_name ) : <EOL> old_formatted_value = data_type . format ( entity [ field_name ] ) <EOL> if old_formatted_value == form_value : <EOL> continue <EOL> if len ( form_value ) > <NUM_LIT:0> : <EOL> value = data_type . parse ( form_value ) <EOL> entity [ field_name ] = value <EOL> elif entity . has_key ( field_name ) : <EOL> del entity [ field_name ] <EOL> datastore . Put ( entity ) <EOL> self . redirect ( self . request . get ( '<STR_LIT>' ) ) <EOL> class DataType ( object ) : <EOL> """<STR_LIT>""" <EOL> @ staticmethod <EOL> def get ( value ) : <EOL> return _DATA_TYPES [ value . __class__ ] <EOL> @ staticmethod <EOL> def get_by_name ( name ) : <EOL> return _NAMED_DATA_TYPES [ name ] <EOL> def format ( self , value ) : <EOL> return str ( value ) <EOL> def short_format ( self , value ) : <EOL> return self . format ( value ) <EOL> def input_field ( self , name , value , sample_values ) : <EOL> if value is not None : <EOL> string_value = self . format ( value ) <EOL> else : <EOL> string_value = '<STR_LIT>' <EOL> return '<STR_LIT>' % ( cgi . escape ( self . name ( ) ) , cgi . escape ( name ) , self . input_field_size ( ) , <EOL> cgi . escape ( string_value , True ) ) <EOL> def input_field_size ( self ) : <EOL> return <NUM_LIT:30> <EOL> def additional_short_value_html ( self , unused_value ) : <EOL> return '<STR_LIT>' <EOL> class StringType ( DataType ) : <EOL> def format ( self , value ) : <EOL> return value <EOL> def input_field ( self , name , value , sample_values ) : <EOL> value = str ( value ) <EOL> sample_values = [ str ( s ) for s in sample_values ] <EOL> multiline = False <EOL> if value : <EOL> multiline = len ( value ) > <NUM_LIT:255> or value . find ( '<STR_LIT:\n>' ) >= <NUM_LIT:0> <EOL> if not multiline : <EOL> for sample_value in sample_values : <EOL> if sample_value and ( len ( sample_value ) > <NUM_LIT:255> or <EOL> sample_value . find ( '<STR_LIT:\n>' ) >= <NUM_LIT:0> ) : <EOL> multiline = True <EOL> break <EOL> if multiline : <EOL> if not value : <EOL> value = '<STR_LIT>' <EOL> return '<STR_LIT>' % ( cgi . escape ( name ) , cgi . escape ( value ) ) <EOL> else : <EOL> return DataType . input_field ( self , name , value , sample_values ) <EOL> def name ( self ) : <EOL> return '<STR_LIT:string>' <EOL> def parse ( self , value ) : <EOL> return value <EOL> def python_type ( self ) : <EOL> return str <EOL> def input_field_size ( self ) : <EOL> return <NUM_LIT:50> <EOL> class TextType ( StringType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def input_field ( self , name , value , sample_values ) : <EOL> return '<STR_LIT>' % ( cgi . escape ( name ) , cgi . escape ( str ( value ) ) ) <EOL> def parse ( self , value ) : <EOL> return datastore_types . Text ( value ) <EOL> def python_type ( self ) : <EOL> return datastore_types . Text <EOL> class BlobType ( StringType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def input_field ( self , name , value , sample_values ) : <EOL> return '<STR_LIT>' <EOL> def format ( self , value ) : <EOL> return '<STR_LIT>' <EOL> def python_type ( self ) : <EOL> return datastore_types . Blob <EOL> class TimeType ( DataType ) : <EOL> _FORMAT = '<STR_LIT>' <EOL> def format ( self , value ) : <EOL> return value . strftime ( TimeType . _FORMAT ) <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return datetime . datetime ( * ( time . strptime ( value , TimeType . _FORMAT ) [ <NUM_LIT:0> : <NUM_LIT:6> ] ) ) <EOL> def python_type ( self ) : <EOL> return datetime . datetime <EOL> class ListType ( DataType ) : <EOL> def format ( self , value ) : <EOL> value_file = cStringIO . StringIO ( ) <EOL> try : <EOL> writer = csv . writer ( value_file ) <EOL> writer . writerow ( value ) <EOL> return value_file . getvalue ( ) <EOL> finally : <EOL> value_file . close ( ) <EOL> def name ( self ) : <EOL> return '<STR_LIT:list>' <EOL> def parse ( self , value ) : <EOL> value_file = cStringIO . StringIO ( value ) <EOL> try : <EOL> reader = csv . reader ( value_file ) <EOL> return reader . next ( ) <EOL> finally : <EOL> value_file . close ( ) <EOL> def python_type ( self ) : <EOL> return list <EOL> class BoolType ( DataType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT:bool>' <EOL> def input_field ( self , name , value , sample_values ) : <EOL> selected = { None : '<STR_LIT>' , False : '<STR_LIT>' , True : '<STR_LIT>' } ; <EOL> selected [ value ] = "<STR_LIT>" <EOL> return """<STR_LIT>""" % ( cgi . escape ( self . name ( ) ) , cgi . escape ( name ) , selected [ None ] , <EOL> selected [ False ] , selected [ True ] ) <EOL> def parse ( self , value ) : <EOL> if value . lower ( ) is '<STR_LIT:true>' : <EOL> return True <EOL> if value . lower ( ) is '<STR_LIT:false>' : <EOL> return False <EOL> return bool ( int ( value ) ) <EOL> def python_type ( self ) : <EOL> return bool <EOL> class NumberType ( DataType ) : <EOL> def input_field_size ( self ) : <EOL> return <NUM_LIT:10> <EOL> class IntType ( NumberType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT:int>' <EOL> def parse ( self , value ) : <EOL> return int ( value ) <EOL> def python_type ( self ) : <EOL> return int <EOL> class LongType ( NumberType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return long ( value ) <EOL> def python_type ( self ) : <EOL> return long <EOL> class FloatType ( NumberType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT:float>' <EOL> def parse ( self , value ) : <EOL> return float ( value ) <EOL> def python_type ( self ) : <EOL> return float <EOL> class UserType ( DataType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return users . User ( value ) <EOL> def python_type ( self ) : <EOL> return users . User <EOL> def input_field_size ( self ) : <EOL> return <NUM_LIT:15> <EOL> class ReferenceType ( DataType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def short_format ( self , value ) : <EOL> return str ( value ) [ : <NUM_LIT:8> ] + '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return datastore_types . Key ( value ) <EOL> def python_type ( self ) : <EOL> return datastore_types . Key <EOL> def input_field ( self , name , value , sample_values ) : <EOL> if value is not None : <EOL> string_value = self . format ( value ) <EOL> else : <EOL> string_value = '<STR_LIT>' <EOL> html = '<STR_LIT>' % ( cgi . escape ( self . name ( ) ) , cgi . escape ( name ) , self . input_field_size ( ) , <EOL> cgi . escape ( string_value , True ) ) <EOL> if value : <EOL> html += '<STR_LIT>' % ( cgi . escape ( string_value , True ) , <EOL> cgi . escape ( PseudoBreadcrumbs ( value ) , True ) ) <EOL> return html <EOL> def input_field_size ( self ) : <EOL> return <NUM_LIT> <EOL> def additional_short_value_html ( self , value ) : <EOL> if not value : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' % ( cgi . escape ( str ( value ) , True ) , <EOL> cgi . escape ( PseudoBreadcrumbs ( value ) , True ) ) <EOL> class EmailType ( StringType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return datastore_types . Email ( value ) <EOL> def python_type ( self ) : <EOL> return datastore_types . Email <EOL> class CategoryType ( StringType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return datastore_types . Category ( value ) <EOL> def python_type ( self ) : <EOL> return datastore_types . Category <EOL> class LinkType ( StringType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return datastore_types . Link ( value ) <EOL> def python_type ( self ) : <EOL> return datastore_types . Link <EOL> class GeoPtType ( DataType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return datastore_types . GeoPt ( value ) <EOL> def python_type ( self ) : <EOL> return datastore_types . GeoPt <EOL> class ImType ( DataType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return datastore_types . IM ( value ) <EOL> def python_type ( self ) : <EOL> return datastore_types . IM <EOL> class PhoneNumberType ( StringType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return datastore_types . PhoneNumber ( value ) <EOL> def python_type ( self ) : <EOL> return datastore_types . PhoneNumber <EOL> class PostalAddressType ( StringType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return datastore_types . PostalAddress ( value ) <EOL> def python_type ( self ) : <EOL> return datastore_types . PostalAddress <EOL> class RatingType ( NumberType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return datastore_types . Rating ( value ) <EOL> def python_type ( self ) : <EOL> return datastore_types . Rating <EOL> class NoneType ( DataType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT:None>' <EOL> def parse ( self , value ) : <EOL> return None <EOL> def python_type ( self ) : <EOL> return None <EOL> def format ( self , value ) : <EOL> return '<STR_LIT:None>' <EOL> class BlobKeyType ( StringType ) : <EOL> def name ( self ) : <EOL> return '<STR_LIT>' <EOL> def parse ( self , value ) : <EOL> return datastore_types . BlobKey ( value ) <EOL> def python_type ( self ) : <EOL> return datastore_types . BlobKey <EOL> _DATA_TYPES = { <EOL> types . NoneType : NoneType ( ) , <EOL> types . StringType : StringType ( ) , <EOL> types . UnicodeType : StringType ( ) , <EOL> datastore_types . Text : TextType ( ) , <EOL> datastore_types . Blob : BlobType ( ) , <EOL> types . BooleanType : BoolType ( ) , <EOL> types . IntType : IntType ( ) , <EOL> types . LongType : LongType ( ) , <EOL> types . FloatType : FloatType ( ) , <EOL> datetime . datetime : TimeType ( ) , <EOL> users . User : UserType ( ) , <EOL> datastore_types . Key : ReferenceType ( ) , <EOL> types . ListType : ListType ( ) , <EOL> datastore_types . Email : EmailType ( ) , <EOL> datastore_types . Category : CategoryType ( ) , <EOL> datastore_types . Link : LinkType ( ) , <EOL> datastore_types . GeoPt : GeoPtType ( ) , <EOL> datastore_types . IM : ImType ( ) , <EOL> datastore_types . PhoneNumber : PhoneNumberType ( ) , <EOL> datastore_types . PostalAddress : PostalAddressType ( ) , <EOL> datastore_types . Rating : RatingType ( ) , <EOL> datastore_types . BlobKey : BlobKeyType ( ) , <EOL> } <EOL> _NAMED_DATA_TYPES = { } <EOL> for data_type in _DATA_TYPES . values ( ) : <EOL> _NAMED_DATA_TYPES [ data_type . name ( ) ] = data_type <EOL> def _ParseCronYaml ( ) : <EOL> """<STR_LIT>""" <EOL> cronyaml_files = '<STR_LIT>' , '<STR_LIT>' <EOL> for cronyaml in cronyaml_files : <EOL> try : <EOL> fh = open ( cronyaml , "<STR_LIT:r>" ) <EOL> except IOError : <EOL> continue <EOL> try : <EOL> cron_info = croninfo . LoadSingleCron ( fh ) <EOL> return cron_info <EOL> finally : <EOL> fh . close ( ) <EOL> return None <EOL> def PseudoBreadcrumbs ( key ) : <EOL> """<STR_LIT>""" <EOL> path = key . to_path ( ) <EOL> parts = [ ] <EOL> for i in range ( <NUM_LIT:0> , len ( path ) // <NUM_LIT:2> ) : <EOL> kind = path [ i * <NUM_LIT:2> ] <EOL> if isinstance ( kind , unicode ) : <EOL> kind = kind . encode ( '<STR_LIT:utf8>' ) <EOL> value = path [ i * <NUM_LIT:2> + <NUM_LIT:1> ] <EOL> if isinstance ( value , ( int , long ) ) : <EOL> parts . append ( '<STR_LIT>' % ( kind , value ) ) <EOL> else : <EOL> if isinstance ( value , unicode ) : <EOL> value = value . encode ( '<STR_LIT:utf8>' ) <EOL> parts . append ( '<STR_LIT>' % ( kind , value ) ) <EOL> return '<STR_LIT>' . join ( parts ) <EOL> def main ( ) : <EOL> handlers = [ <EOL> ( '<STR_LIT>' + DatastoreQueryHandler . PATH , DatastoreQueryHandler ) , <EOL> ( '<STR_LIT>' + DatastoreEditHandler . PATH , DatastoreEditHandler ) , <EOL> ( '<STR_LIT>' + DatastoreBatchEditHandler . PATH , DatastoreBatchEditHandler ) , <EOL> ( '<STR_LIT>' + InteractivePageHandler . PATH , InteractivePageHandler ) , <EOL> ( '<STR_LIT>' + InteractiveExecuteHandler . PATH , InteractiveExecuteHandler ) , <EOL> ( '<STR_LIT>' + MemcachePageHandler . PATH , MemcachePageHandler ) , <EOL> ( '<STR_LIT>' + ImageHandler . PATH , ImageHandler ) , <EOL> ( '<STR_LIT>' + QueuesPageHandler . PATH , QueuesPageHandler ) , <EOL> ( '<STR_LIT>' + TasksPageHandler . PATH , TasksPageHandler ) , <EOL> ( '<STR_LIT>' + XMPPPageHandler . PATH , XMPPPageHandler ) , <EOL> ( '<STR_LIT>' + InboundMailPageHandler . PATH , InboundMailPageHandler ) , <EOL> ( '<STR_LIT>' , DefaultPageHandler ) , <EOL> ] <EOL> if HAVE_CRON : <EOL> handlers . insert ( <NUM_LIT:0> , ( '<STR_LIT>' + CronPageHandler . PATH , CronPageHandler ) ) <EOL> application = webapp . WSGIApplication ( handlers , debug = _DEBUG ) <EOL> wsgiref . handlers . CGIHandler ( ) . run ( application ) <EOL> import django <EOL> if django . VERSION [ : <NUM_LIT:2> ] < ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> from django . template import defaultfilters <EOL> def safe ( text , dummy = None ) : <EOL> return text <EOL> defaultfilters . register . filter ( "<STR_LIT>" , safe ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
