<s> from __future__ import unicode_literals <EOL> from django . conf import settings <EOL> from django . contrib . staticfiles import utils <EOL> from django . contrib . staticfiles . views import serve <EOL> from django . utils . six . moves . urllib . parse import urlparse <EOL> from django . utils . six . moves . urllib . request import url2pathname <EOL> from . handler import AsgiHandler , ViewConsumer <EOL> class StaticFilesHandler ( AsgiHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( StaticFilesHandler , self ) . __init__ ( ) <EOL> self . base_url = urlparse ( self . get_base_url ( ) ) <EOL> def get_base_url ( self ) : <EOL> utils . check_settings ( ) <EOL> return settings . STATIC_URL <EOL> def _should_handle ( self , path ) : <EOL> """<STR_LIT>""" <EOL> return path . startswith ( self . base_url [ <NUM_LIT:2> ] ) and not self . base_url [ <NUM_LIT:1> ] <EOL> def file_path ( self , url ) : <EOL> """<STR_LIT>""" <EOL> relative_url = url [ len ( self . base_url [ <NUM_LIT:2> ] ) : ] <EOL> return url2pathname ( relative_url ) <EOL> def serve ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return serve ( request , self . file_path ( request . path ) , insecure = True ) <EOL> def get_response ( self , request ) : <EOL> from django . http import Http404 <EOL> if self . _should_handle ( request . path ) : <EOL> try : <EOL> return self . serve ( request ) <EOL> except Http404 as e : <EOL> if settings . DEBUG : <EOL> from django . views import debug <EOL> return debug . technical_404_response ( request , e ) <EOL> return super ( StaticFilesHandler , self ) . get_response ( request ) <EOL> class StaticFilesConsumer ( ViewConsumer ) : <EOL> """<STR_LIT>""" <EOL> handler_class = StaticFilesHandler </s>
