<s> """<STR_LIT>""" <EOL> import re <EOL> from werkzeug . wrappers import BaseRequest , BaseResponse <EOL> from werkzeug . exceptions import HTTPException , MethodNotAllowed , NotImplemented , NotFound <EOL> class Request ( BaseRequest ) : <EOL> """<STR_LIT>""" <EOL> class Response ( BaseResponse ) : <EOL> """<STR_LIT>""" <EOL> class View ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app , req ) : <EOL> self . app = app <EOL> self . req = req <EOL> def GET ( self ) : <EOL> raise MethodNotAllowed ( ) <EOL> POST = DELETE = PUT = GET <EOL> def HEAD ( self ) : <EOL> return self . GET ( ) <EOL> class WebPyApp ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , urls , views ) : <EOL> self . urls = [ ( re . compile ( '<STR_LIT>' % urls [ i ] ) , urls [ i + <NUM_LIT:1> ] ) <EOL> for i in xrange ( <NUM_LIT:0> , len ( urls ) , <NUM_LIT:2> ) ] <EOL> self . views = views <EOL> def __call__ ( self , environ , start_response ) : <EOL> try : <EOL> req = Request ( environ ) <EOL> for regex , view in self . urls : <EOL> match = regex . match ( req . path ) <EOL> if match is not None : <EOL> view = self . views [ view ] ( self , req ) <EOL> if req . method not in ( '<STR_LIT:GET>' , '<STR_LIT>' , '<STR_LIT:POST>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) : <EOL> raise NotImplemented ( ) <EOL> resp = getattr ( view , req . method ) ( * match . groups ( ) ) <EOL> break <EOL> else : <EOL> raise NotFound ( ) <EOL> except HTTPException , e : <EOL> resp = e <EOL> return resp ( environ , start_response ) </s>
