Python 3.3 (shakes fist)

This commit is contained in:
James Socol
2015-09-21 13:41:10 -04:00
parent 46dfa4ee33
commit 72e73d4a9c

View File

@@ -6,12 +6,32 @@ import functools
import logging
import re
from django.apps import apps
from django.conf import settings
from django.template.base import Origin, TemplateDoesNotExist
from django.template.loader import BaseLoader
from django.utils.importlib import import_module
try:
import importlib.util
def has_helpers(path):
return importlib.util.find_spec('helpers', path) is not None
if hasattr(importlib.util, 'find_spec'): # Py3>=3.4
def has_helpers(path):
return importlib.util.find_spec('helpers', path) is not None
else: # Py3<3.4
def has_helpers(path):
# For Python 3.3, just try to import the module. Unfortunately,
# this changes the contract slightly for Python 3.3: if there is an
# module but this raises a legitimate ImportError, jingo will act
# as if the module doesn't exist. The intent is that we raise
# legitimate ImportErrors but ignore missing modules.
try:
import_module('helpers', path)
return True
except ImportError:
return False
except ImportError:
import imp
def has_helpers(path):
try:
imp.find_module('helpers', path)
@@ -19,12 +39,6 @@ except ImportError:
except ImportError:
return False
from django.apps import apps
from django.conf import settings
from django.template.base import Origin, TemplateDoesNotExist
from django.template.loader import BaseLoader
from django.utils.importlib import import_module
import jinja2
try: