<s> from flask import Flask , request , render_template , url_for , redirect <EOL> from hash_function import hashFunction <EOL> app = Flask ( __name__ ) <EOL> URL_TABLE = { } <EOL> @ app . route ( '<STR_LIT:/>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> def homepage ( ) : <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def find_short_url ( ) : <EOL> long_url = request . form [ '<STR_LIT:url>' ] <EOL> key = hashFunction ( long_url ) <EOL> URL_TABLE [ key ] = long_url <EOL> short_url = HOST + key <EOL> return render_template ( '<STR_LIT>' , new_url = short_url ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> def redirect_short_url ( key ) : <EOL> try : <EOL> long_url = URL_TABLE [ key ] <EOL> return redirect ( long_url , code = <NUM_LIT> ) <EOL> except : <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ app . errorhandler ( <NUM_LIT> ) <EOL> def error404 ( error ) : <EOL> return render_template ( '<STR_LIT>' ) , <NUM_LIT> <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> HOST = '<STR_LIT>' <EOL> app . run ( ) </s>
