<s> """<STR_LIT>""" <EOL> import cgi <EOL> import os <EOL> import urlparse <EOL> CHANNEL_POLL_PATTERN = '<STR_LIT>' <EOL> CHANNEL_JSAPI_PATTERN = '<STR_LIT>' <EOL> def CreateChannelDispatcher ( channel_service_stub ) : <EOL> """<STR_LIT>""" <EOL> from google . appengine . tools import dev_appserver <EOL> class ChannelDispatcher ( dev_appserver . URLDispatcher ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , channel_service_stub ) : <EOL> """<STR_LIT>""" <EOL> self . _channel_service_stub = channel_service_stub <EOL> def Dispatch ( self , <EOL> request , <EOL> outfile , <EOL> base_env_dict = None ) : <EOL> """<STR_LIT>""" <EOL> ( unused_scheme , unused_netloc , <EOL> path , query , <EOL> unused_fragment ) = urlparse . urlsplit ( request . relative_url ) <EOL> param_dict = cgi . parse_qs ( query , True ) <EOL> page = path . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] <EOL> if page == '<STR_LIT>' : <EOL> path = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> outfile . write ( '<STR_LIT>' ) <EOL> outfile . write ( '<STR_LIT>' ) <EOL> outfile . write ( open ( path ) . read ( ) ) <EOL> elif page == '<STR_LIT>' : <EOL> token = param_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> ( syntax_valid , time_valid ) = ( <EOL> self . _channel_service_stub . check_token_validity ( token ) ) <EOL> if not ( syntax_valid and time_valid ) : <EOL> if not syntax_valid : <EOL> token_error = '<STR_LIT>' <EOL> else : <EOL> token_error = '<STR_LIT>' <EOL> outfile . write ( '<STR_LIT>' % token_error ) <EOL> return <EOL> outfile . write ( '<STR_LIT>' ) <EOL> outfile . write ( '<STR_LIT:\r\n>' ) <EOL> command = param_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> if command == '<STR_LIT>' : <EOL> self . _channel_service_stub . connect_channel ( token ) <EOL> outfile . write ( '<STR_LIT:1>' ) <EOL> elif command == '<STR_LIT>' : <EOL> self . _channel_service_stub . connect_channel ( token ) <EOL> if self . _channel_service_stub . has_channel_messages ( token ) : <EOL> outfile . write ( self . _channel_service_stub . pop_first_message ( token ) ) <EOL> return ChannelDispatcher ( channel_service_stub ) </s>
