<s> """<STR_LIT>""" <EOL> import os <EOL> import google <EOL> import webapp2 <EOL> from google . appengine . api import apiproxy_stub_map <EOL> from google . appengine . api . channel import channel_service_stub <EOL> CHANNEL_URL_PATTERN = '<STR_LIT>' <EOL> _JSAPI_PATH = os . path . join ( os . path . dirname ( os . path . dirname ( __file__ ) ) , <EOL> '<STR_LIT>' ) <EOL> INVALID_TOKEN_STATUS = '<STR_LIT>' <EOL> TOKEN_TIMED_OUT_STATUS = '<STR_LIT>' <EOL> def _get_channel_stub ( ) : <EOL> """<STR_LIT>""" <EOL> return apiproxy_stub_map . apiproxy . GetStub ( '<STR_LIT>' ) <EOL> class DevHandler ( webapp2 . RequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def get ( self ) : <EOL> del self . response . headers [ '<STR_LIT:Content-Type>' ] <EOL> stub = _get_channel_stub ( ) <EOL> command = self . request . get ( '<STR_LIT>' , None ) <EOL> token = self . request . get ( '<STR_LIT>' , None ) <EOL> if command is None or token is None : <EOL> self . response . status = <NUM_LIT> <EOL> return <EOL> if command == '<STR_LIT>' : <EOL> try : <EOL> stub . connect_channel ( token ) <EOL> except channel_service_stub . InvalidTokenError : <EOL> self . response . status = INVALID_TOKEN_STATUS <EOL> return <EOL> except channel_service_stub . TokenTimedOutError : <EOL> self . response . status = TOKEN_TIMED_OUT_STATUS <EOL> return <EOL> self . response . headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> self . response . out . write ( '<STR_LIT:1>' ) <EOL> elif command == '<STR_LIT>' : <EOL> try : <EOL> message = stub . connect_and_pop_first_message ( token ) <EOL> except channel_service_stub . InvalidTokenError : <EOL> self . response . status = INVALID_TOKEN_STATUS <EOL> return <EOL> except channel_service_stub . TokenTimedOutError : <EOL> self . response . status = TOKEN_TIMED_OUT_STATUS <EOL> return <EOL> if message is not None : <EOL> self . response . headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT:application/json>' <EOL> self . response . out . write ( message ) <EOL> else : <EOL> self . response . status = <NUM_LIT> <EOL> class JSAPIHandler ( webapp2 . RequestHandler ) : <EOL> """<STR_LIT>""" <EOL> def get ( self ) : <EOL> self . response . headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> self . response . out . write ( open ( _JSAPI_PATH ) . read ( ) ) <EOL> application = webapp2 . WSGIApplication ( [ <EOL> ( '<STR_LIT>' , DevHandler ) , <EOL> ( '<STR_LIT>' , JSAPIHandler ) , <EOL> ] , debug = True ) </s>
