o 3a~(@sddlZddlZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z mZmZddlmZdd lmZmZdd lmZgZGd d d ZGd ddeZGdddeZGdddeZGdddeZdddZddZejddddZ dS)N)apps)settings)utils)Error)ImproperlyConfigured)FileSystemStorageStoragedefault_storage) safe_join) LazyObjectempty) import_stringc@s*eZdZdZddZd ddZddZd S) BaseFinderzN A base file finder to be used for custom staticfiles finder classes. cKtd)NzUsubclasses may provide a check() method to verify the finder is configured correctly.NotImplementedError)selfkwargsrD/usr/lib/python3/dist-packages/django/contrib/staticfiles/finders.pycheckszBaseFinder.checkFcCr)z Given a relative file path, find an absolute file path. If the ``all`` parameter is False (default) return only the first found file path; if True, return a list of all found files paths. z5subclasses of BaseFinder must provide a find() methodr)rpathallrrrfindszBaseFinder.findcCr)z Given an optional list of paths to ignore, return a two item iterable consisting of the relative path and storage instance. z5subclasses of BaseFinder must provide a list() methodr)rignore_patternsrrrlist'szBaseFinder.listNF)__name__ __module__ __qualname____doc__rrrrrrrrs   rcsFeZdZdZdfdd ZddZddd Zdd d Zd d ZZ S)FileSystemFinderz_ A static files finder that uses the ``STATICFILES_DIRS`` setting to locate files. Ncsg|_i|_tjD]}t|ttfr|\}}nd}||f|jvr(|j||fq |jD]\}}t|d}||_ ||j|<q,t j |i|dS)N)location) locationsstoragesrSTATICFILES_DIRS isinstancertupleappendrprefixsuper__init__)r app_namesargsrrootr*filesystem_storage __class__rrr,4s    zFileSystemFinder.__init__cKsg}ttjttfs|tddddtjD]6}t|ttfr4|\}}|dr4|td|ddtjrMt j tjt j |krM|td d dq|S) Nz4The STATICFILES_DIRS setting is not a tuple or list.z$Perhaps you forgot a trailing comma?zstaticfiles.E001)hintid/zHThe prefix %r in the STATICFILES_DIRS setting must not end with a slash.zstaticfiles.E003)r4zHThe STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.zstaticfiles.E002) r'rr&rr(r)rendswith STATIC_ROOTosrabspath)rrerrorsr/r*rrrrFs0   zFileSystemFinder.checkFcCsRg}|jD]!\}}|tvrt|||||}|r&|s!|S||q|S)zW Look for files in the extra locations as defined in STATICFILES_DIRS. )r$searched_locationsr) find_location)rrrmatchesr*r/ matched_pathrrrr_s  zFileSystemFinder.findcCsN|rd|tjf}||sdS|t|d}t||}tj|r%|SdS)z Find a requested static file in a location and return the found absolute path (or ``None`` if no match). z%s%sN)r8sep startswithlenr rexists)rr/rr*rrrr<ns   zFileSystemFinder.find_locationccs<|jD]\}}|j|}t||D]}||fVqqdS)z2 List all files in all locations. N)r$r%r get_files)rrr*r/storagerrrrr|s  zFileSystemFinder.listNr) rrrr r,rrr<r __classcell__rrr1rr!/s  r!csDeZdZdZeZdZd fdd ZddZdd d Z d d Z Z S)AppDirectoriesFinderzu A static files finder that looks in the directory of each app as specified in the source_dir attribute. staticNcsg|_i|_t}rtfdd|D}|D](}|tj|j|j}tj |j rC||j|j <|j |jvrC|j |j qt j|i|dS)Ncsg|] }|jvr|qSr)name).0acr-rr sz1AppDirectoriesFinder.__init__..)rr%get_app_configsset storage_classr8rjoin source_dirisdirr#rIr)r+r,)rr-r.r app_configs app_config app_storager1rLrr,s   zAppDirectoriesFinder.__init__ccs<|jD]}|drt||D]}||fVqqdS)z5 List all files in all app storages. r"N)r%valuesrBrrC)rrrDrrrrrs  zAppDirectoriesFinder.listFcCsXg}|jD]$}|j|j}|tvrt||||}|r)|s$|S||q|S)z8 Look for files in the app directories. )rr%r#r;r) find_in_app)rrrr=app app_locationmatchrrrrs     zAppDirectoriesFinder.findcCs8|j|}|r||r||}|r|SdSdSdS)zL Find a requested static file in an app's static locations. N)r%getrBr)rrYrrDr>rrrrXs  z AppDirectoriesFinder.find_in_apprEr) rrrr rrPrRr,rrrXrFrrr1rrGs rGcs8eZdZdZdZd fdd Zd ddZdd ZZS) BaseStorageFinderzZ A base static files finder to be used to extended with an own storage class. NcsV|dur||_|jdurtd|jt|jttfs ||_tj|i|dS)NzHThe staticfiles storage finder %r doesn't have a storage class assigned.)rDrr2r'rr r+r,)rrDr.rr1rrr,s  zBaseStorageFinder.__init__FcCsjz|jdWn tyYgSw|jjtvr t|jj|j|r3|j|}|r1|g}|SgS)zL Look for files in the default file storage, if it's local. r")rDrrr#r;r)rB)rrrr[rrrrs     zBaseStorageFinder.findccs&t|j|D]}||jfVqdS)z0 List all files of the storage. N)rrCrD)rrrrrrrszBaseStorageFinder.listrEr) rrrr rDr,rrrFrrr1rr]s  r]cs$eZdZdZeZfddZZS)DefaultStorageFinderzF A static files finder that uses the default storage backend. cs6tj|i|t|jdt}|std|jdS)N base_locationzOThe storage backend of the staticfiles finder %r doesn't have a valid location.)r+r,getattrrDr rr2)rr.rr_r1rrr,szDefaultStorageFinder.__init__)rrrr r rDr,rFrrr1rr^sr^FcCslgtdd<g}tD] }|j||d}|s|r|St|ttfs&|g}||q |r0|S|r4gSdS)z Find a static file with the given path using all enabled finders. If ``all`` is ``False`` (default), return the first matching absolute path (or ``None`` if no match). Otherwise return a list. N)r)r; get_findersrr'rr(extend)rrr=finderresultrrrrs    rccstjD]}t|VqdSrE)rSTATICFILES_FINDERS get_finder) finder_pathrrrras  ra)maxsizecCs(t|}t|tstd|tf|S)z Import the staticfiles finder class described by import_path, where import_path is the full Python path to the class. z%Finder "%s" is not a subclass of "%s")r issubclassrr) import_pathFinderrrrrfs  rfr)! functoolsr8 django.appsr django.confrdjango.contrib.staticfilesrdjango.core.checksrdjango.core.exceptionsrdjango.core.files.storagerrr django.utils._osr django.utils.functionalr r django.utils.module_loadingr r;rr!rGr]r^rra lru_cacherfrrrrs*       W?-