<s> from six . moves . urllib . parse import urlparse <EOL> class CORS ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app , origins = None ) : <EOL> self . app = app <EOL> self . origins = origins <EOL> def __call__ ( self , environ , start_response ) : <EOL> origin = environ . get ( '<STR_LIT>' ) <EOL> if origin is None or self . origins is None : <EOL> return self . app ( environ , start_response ) <EOL> netloc = urlparse ( origin ) . netloc <EOL> if netloc in self . origins or '<STR_LIT:*>' in self . origins : <EOL> allow_origin = [ <EOL> ( '<STR_LIT>' , origin ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:true>' ) , <EOL> ] <EOL> if environ [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> start_response ( '<STR_LIT>' , allow_origin ) <EOL> return [ ] <EOL> def custom_start_response ( status , headers , exc_info = None ) : <EOL> headers . extend ( allow_origin ) <EOL> return start_response ( status , headers , exc_info ) <EOL> else : <EOL> custom_start_response = start_response <EOL> return self . app ( environ , custom_start_response ) <EOL> class TrailingSlash ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , app ) : <EOL> self . app = app <EOL> def __call__ ( self , environ , start_response ) : <EOL> path_info = environ [ '<STR_LIT>' ] <EOL> if len ( path_info ) > <NUM_LIT:1> and path_info . endswith ( '<STR_LIT:/>' ) : <EOL> environ [ '<STR_LIT>' ] = path_info . rstrip ( '<STR_LIT:/>' ) <EOL> return self . app ( environ , start_response ) </s>
