#NEWLINE# @ view_config ( route_name = 'shortener_v1' , renderer = 'jsonp' ) #NEWLINE# def url_shortener( request ) : #NEWLINE# #INDENT# incoming_url = request . params . get ( 'url' ) #NEWLINE# if ( not incoming_url ) : #NEWLINE# #INDENT# raise httpexceptions . HTTPBadRequest ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# url_handler = Url ( request , url = incoming_url ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise httpexceptions . HTTPBadRequest ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# short_url = url_handler . shorten ( ) #NEWLINE# #UNINDENT# except ShortenGenerationError : #NEWLINE# #INDENT# raise httpexceptions . HTTPInternalServerError ( ) #NEWLINE# #UNINDENT# return short_url