<s> import os <EOL> from django . conf import settings <EOL> from django . contrib . staticfiles . finders import BaseFinder <EOL> from django . utils . datastructures import SortedDict <EOL> from django . utils . importlib import import_module <EOL> from django . utils . _os import safe_join <EOL> from django . contrib . staticfiles import utils <EOL> from ionyweb . loaders . storage import ThemeStorage <EOL> class StaticFinder ( BaseFinder ) : <EOL> def __init__ ( self , apps = None , * args , ** kwargs ) : <EOL> self . locations = list ( getattr ( settings , '<STR_LIT>' , [ ] ) ) <EOL> self . storages = SortedDict ( ) <EOL> for root in self . locations : <EOL> filesystem_storage = ThemeStorage ( location = root ) <EOL> self . storages [ root ] = filesystem_storage <EOL> super ( StaticFinder , self ) . __init__ ( * args , ** kwargs ) <EOL> def find ( self , path , all = False ) : <EOL> """<STR_LIT>""" <EOL> matches = [ ] <EOL> for root in self . locations : <EOL> matched_path = self . find_location ( root , path ) <EOL> if matched_path : <EOL> if not all : <EOL> return matched_path <EOL> matches . append ( matched_path ) <EOL> return matches <EOL> def find_location ( self , root , path ) : <EOL> """<STR_LIT>""" <EOL> dirs = path . split ( '<STR_LIT:/>' ) <EOL> if len ( dirs ) >= <NUM_LIT:3> and dirs [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> path = u'<STR_LIT:/>' . join ( dirs [ <NUM_LIT:1> : ] ) <EOL> if path . find ( '<STR_LIT>' ) != - <NUM_LIT:1> : <EOL> return None <EOL> else : <EOL> path = safe_join ( root , path ) <EOL> if os . path . exists ( path ) : <EOL> return path <EOL> else : <EOL> return None <EOL> def list ( self , ignore_patterns ) : <EOL> """<STR_LIT>""" <EOL> for root in self . locations : <EOL> storage = self . storages [ root ] <EOL> for path in utils . get_files ( storage , ignore_patterns ) : <EOL> yield path , storage </s>
