<s> import re <EOL> from django . conf import settings <EOL> from django . views . static import serve <EOL> from django . shortcuts import redirect <EOL> from . exceptions import Redirect <EOL> class StaticServe ( object ) : <EOL> """<STR_LIT>""" <EOL> regex = re . compile ( r'<STR_LIT>' % settings . MEDIA_URL ) <EOL> def process_request ( self , request ) : <EOL> if settings . DEBUG : <EOL> match = self . regex . search ( request . path ) <EOL> if match : <EOL> return serve ( request , match . group ( <NUM_LIT:1> ) , settings . MEDIA_ROOT ) <EOL> class RedirectMiddleware ( object ) : <EOL> """<STR_LIT>""" <EOL> def process_exception ( self , request , exception ) : <EOL> if not isinstance ( exception , Redirect ) : <EOL> return <EOL> return redirect ( * exception . args , ** exception . kwargs ) </s>
