Coverage for templateselector/handlers.py: 98%

# Coverage for templateselector/handlers.py : 98%

## 33 statements 33 run 0 missing 11 excluded 1 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # -*- coding: utf-8 -*- from __future__ import unicode_literals, absolute_import from django.template.loaders import app_directories, filesystem, cached try: from os import scandir except ImportError: # pragma: no cover try: from scandir import scandir except ImportError as e: import sys from django.utils import six message = ("You're probably using Python 2.x, so you'll need to " "install the backport: `pip install scandir\>=1.5`") flattened = " ".join(e.args) + "\n" + message e.args = (flattened,) e.message = flattened six.reraise(*sys.exc_info()) __all__ = ['get_results_from_registry'] def scandir_recursive(path): for item in scandir(path): yield item if item.is_dir(follow_symlinks=False): for subitem in scandir_recursive(item.path): yield subitem usable_loaders = {} def from_filesystem(instance): dirs = instance.get_dirs() for directory in dirs: strip_first = len(directory) for item in scandir_recursive(directory): if item.is_file(): yield item.path[strip_first+1:] def from_cached(instance): """ Just go and look at the registry again using the child loaders... """ loaders = instance.loaders for result in get_results_from_registry(loaders): yield result usable_loaders[app_directories.Loader] = from_filesystem usable_loaders[filesystem.Loader] = from_filesystem usable_loaders[cached.Loader] = from_cached def get_results_from_registry(loaders): for loader in loaders: cls = loader.__class__ 56 ↛ 54line 56 didn't jump to line 54, because the condition on line 56 was never false if cls in usable_loaders: finder = usable_loaders[cls] for result in finder(instance=loader): yield result