<s> import os <EOL> import json <EOL> import hashlib <EOL> import bottle <EOL> from bottle import request , response , static_file , abort <EOL> def md5sum ( b ) : <EOL> return hashlib . md5 ( b ) . hexdigest ( ) <EOL> def mb_code ( s , encoding = '<STR_LIT:utf-8>' ) : <EOL> for c in ( '<STR_LIT:utf-8>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> try : <EOL> return s . decode ( c ) . encode ( encoding ) <EOL> except : pass <EOL> try : <EOL> return s . encode ( encoding ) <EOL> except : raise <EOL> def normal_formsdict ( ) : <EOL> d = { } <EOL> d [ '<STR_LIT:url>' ] = request . url <EOL> d [ '<STR_LIT:path>' ] = request . path <EOL> d [ '<STR_LIT>' ] = request . fullpath <EOL> d [ '<STR_LIT>' ] = request . method <EOL> d [ '<STR_LIT>' ] = request . query_string <EOL> d [ '<STR_LIT>' ] = request . script_name <EOL> d [ '<STR_LIT>' ] = request . is_xhr <EOL> d [ '<STR_LIT>' ] = request . is_ajax <EOL> d [ '<STR_LIT>' ] = request . auth <EOL> d [ '<STR_LIT>' ] = request . remote_addr <EOL> d [ '<STR_LIT>' ] = dict ( request . headers ) <EOL> d [ '<STR_LIT>' ] = dict ( request . forms ) <EOL> d [ '<STR_LIT>' ] = dict ( request . params ) <EOL> d [ '<STR_LIT>' ] = dict ( request . GET ) <EOL> d [ '<STR_LIT>' ] = dict ( request . POST ) <EOL> d [ '<STR_LIT>' ] = dict ( request . files ) <EOL> for i in d [ '<STR_LIT>' ] : <EOL> del d [ '<STR_LIT>' ] [ i ] <EOL> d [ '<STR_LIT>' ] [ i ] = ( d [ '<STR_LIT>' ] [ i ] . name , d [ '<STR_LIT>' ] [ i ] . filename , md5sum ( d [ '<STR_LIT>' ] [ i ] . file . read ( ) ) ) <EOL> d [ '<STR_LIT>' ] = dict ( request . cookies ) <EOL> return json . dumps ( d ) <EOL> app = bottle . app ( ) <EOL> @ app . route ( '<STR_LIT:/>' , method = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def index ( ) : <EOL> return normal_formsdict ( ) <EOL> def basic_auth_check ( username , password ) : <EOL> if username == "<STR_LIT>" and password == "<STR_LIT>" : <EOL> return True <EOL> return False <EOL> @ app . route ( '<STR_LIT>' , method = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> @ bottle . auth_basic ( basic_auth_check ) <EOL> def basic_auth ( ) : <EOL> return normal_formsdict ( ) <EOL> @ app . route ( '<STR_LIT>' , method = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def sleep ( seconds ) : <EOL> import time <EOL> time . sleep ( seconds ) <EOL> return normal_formsdict ( ) <EOL> @ app . route ( '<STR_LIT>' , method = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def setcookie ( name , value ) : <EOL> response . set_cookie ( name , value ) <EOL> return normal_formsdict ( ) <EOL> @ app . route ( '<STR_LIT>' , method = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def proxy ( ) : <EOL> return normal_formsdict ( ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def utf8_file ( ) : <EOL> return static_file ( '<STR_LIT>' , root = os . path . dirname ( __file__ ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def gbk_file ( ) : <EOL> return static_file ( '<STR_LIT>' , root = os . path . dirname ( __file__ ) ) <EOL> @ app . route ( '<STR_LIT>' , method = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def redirect ( max , now ) : <EOL> max = int ( max ) <EOL> now = int ( now ) <EOL> if now == max : <EOL> return normal_formsdict ( ) <EOL> elif now < max : <EOL> return bottle . redirect ( '<STR_LIT>' % ( max , now + <NUM_LIT:1> ) ) <EOL> else : <EOL> abort ( <NUM_LIT> ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def content_encoding_invalid_header ( ) : <EOL> response . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return os . urandom ( <NUM_LIT:64> ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def content_encoding_invalid_body ( ) : <EOL> response . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return os . urandom ( <NUM_LIT:64> ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def content_encoding_invalid_body ( ) : <EOL> response . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return os . urandom ( <NUM_LIT:64> ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def links ( n ) : <EOL> try : <EOL> n = int ( n ) <EOL> except : <EOL> n = None <EOL> if n == <NUM_LIT:1> : <EOL> response . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif n == <NUM_LIT:2> : <EOL> response . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif n == <NUM_LIT:3> : <EOL> response . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif n is None : <EOL> response . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> response . set_header ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return normal_formsdict ( ) <EOL> @ app . route ( '<STR_LIT>' , method = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def sleep ( n ) : <EOL> return os . urandom ( int ( n ) ) <EOL> def run ( ) : <EOL> import sys <EOL> try : <EOL> port = int ( sys . argv [ <NUM_LIT:1> ] ) <EOL> except : <EOL> port = <NUM_LIT> <EOL> quiet = False <EOL> for arg in sys . argv [ <NUM_LIT:1> : ] : <EOL> if arg == '<STR_LIT>' : <EOL> quiet = True <EOL> break <EOL> bottle . debug ( not quiet ) <EOL> bottle . run ( app = app , host = '<STR_LIT:127.0.0.1>' , port = port , server = '<STR_LIT>' , <EOL> quiet = quiet , debug = not quiet , ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> run ( ) </s>
