<s> """<STR_LIT>""" <EOL> import hashlib <EOL> import random <EOL> import sys <EOL> from twisted . internet import reactor <EOL> from cyclone . web import asynchronous <EOL> from sockjs . cyclone . basehandler import BaseHandler , PreflightHandler <EOL> from sockjs . cyclone . proto import json_encode <EOL> IFRAME_TEXT = '''<STR_LIT>''' . strip ( ) <EOL> class IFrameHandler ( BaseHandler ) : <EOL> """<STR_LIT>""" <EOL> def get ( self ) : <EOL> data = IFRAME_TEXT % self . server . settings [ '<STR_LIT>' ] <EOL> hsh = hashlib . md5 ( data ) . hexdigest ( ) <EOL> value = self . request . headers . get ( '<STR_LIT>' ) <EOL> if value and value . find ( hsh ) != - <NUM_LIT:1> : <EOL> self . clear ( ) <EOL> del self . _headers [ '<STR_LIT:Content-Type>' ] <EOL> self . set_status ( <NUM_LIT> ) <EOL> return <EOL> self . enable_cache ( ) <EOL> self . set_header ( '<STR_LIT>' , hsh ) <EOL> self . write ( data ) <EOL> class GreetingsHandler ( BaseHandler ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self , server ) : <EOL> self . server = server <EOL> def get ( self ) : <EOL> self . enable_cache ( ) <EOL> self . set_header ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) <EOL> self . write ( '<STR_LIT>' ) <EOL> class ChunkingTestHandler ( PreflightHandler ) : <EOL> """<STR_LIT>""" <EOL> steps = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> def initialize ( self , server ) : <EOL> self . server = server <EOL> self . step = <NUM_LIT:0> <EOL> @ asynchronous <EOL> def post ( self ) : <EOL> self . preflight ( ) <EOL> self . set_header ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) <EOL> self . write ( '<STR_LIT>' ) <EOL> self . flush ( ) <EOL> self . write ( '<STR_LIT>' % '<STR_LIT:U+0020>' * <NUM_LIT> ) <EOL> self . flush ( ) <EOL> def run_step ( ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> self . flush ( ) <EOL> self . step += <NUM_LIT:1> <EOL> if self . step < len ( self . steps ) : <EOL> reactor . callLater ( self . steps [ self . step ] , run_step ) <EOL> else : <EOL> self . finish ( ) <EOL> reactor . callLater ( self . steps [ self . step ] , run_step ) <EOL> class InfoHandler ( PreflightHandler ) : <EOL> """<STR_LIT>""" <EOL> def initialize ( self , server ) : <EOL> self . server = server <EOL> self . access_methods = '<STR_LIT>' <EOL> def get ( self ) : <EOL> self . preflight ( ) <EOL> self . disable_cache ( ) <EOL> self . set_header ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) <EOL> options = dict ( websocket = self . server . websockets_enabled , <EOL> cookie_needed = self . server . cookie_needed , <EOL> origins = [ '<STR_LIT>' ] , <EOL> entropy = random . randint ( <NUM_LIT:0> , sys . maxint ) ) <EOL> self . write ( json_encode ( options ) ) </s>
