Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
a1s committed Mar 10, 2015
1 parent 2eb1fa3 commit 84abeed
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions hamlpy/template/utils.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
import imp
from os import listdir
from os.path import dirname, splitext
from os.path import dirname
from pkgutil import iter_modules

try:
from django.template import loaders
_django_available = True
except ImportError, e:
_django_available = False

MODULE_EXTENSIONS = tuple([suffix[0] for suffix in imp.get_suffixes()])

def get_django_template_loaders():
if not _django_available:
return []
return [(loader.__name__.rsplit('.',1)[1], loader)
return [(loader.__name__.rsplit('.',1)[1], loader)
for loader in get_submodules(loaders)
if hasattr(loader, 'Loader')]

def get_submodules(package):
submodules = ("%s.%s" % (package.__name__, module)
for module in package_contents(package))
return [__import__(module, {}, {}, [module.rsplit(".", 1)[-1]])
return [__import__(module, {}, {}, [module.rsplit(".", 1)[-1]])
for module in submodules]

def package_contents(package):
package_path = dirname(loaders.__file__)
contents = set([splitext(module)[0]
for module in listdir(package_path)
if module.endswith(MODULE_EXTENSIONS)])
return contents
package_path = dirname(package.__file__)
return set([name for (ldr, name, ispkg) in iter_modules([package_path])])

0 comments on commit 84abeed

Please sign in to comment.