Ticket #13334: 13334.diff

File 13334.diff, 4.2 KB (added by kmtracey, 5 years ago)
  • django/template/__init__.py

     
    6363from django.utils.safestring import SafeData, EscapeData, mark_safe, mark_for_escaping
    6464from django.utils.formats import localize
    6565from django.utils.html import escape
     66from django.utils.module_loading import module_has_submodule
    6667
    6768__all__ = ('Template', 'Context', 'RequestContext', 'compile_string')
    6869
     
    988989    # an actual import problem with the module.
    989990    app_path, taglib = taglib_module.rsplit('.',1)
    990991    app_module = import_module(app_path)
    991     try:
    992         imp.find_module(taglib, app_module.__path__)
    993     except ImportError,e:
     992    if not module_has_submodule(app_module, taglib):
    994993        return None
    995     mod = import_module(taglib_module)
    996994    try:
     995        mod = import_module(taglib_module)
     996    except ImportError, e:
     997        raise InvalidTemplateLibrary("ImportError raised loading %s: %s" % (taglib_module, e))
     998    try:
    997999        return mod.register
    9981000    except AttributeError:
    9991001        raise InvalidTemplateLibrary("Template library %s does not have a variable named 'register'" % taglib_module)
  • tests/regressiontests/templates/tests.py

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    
    Property changes on: tests\regressiontests\templates\eggs\tagsegg.egg
    ___________________________________________________________________
    Added: svn:mime-type
       + application/octet-stream
    
     
    12871287            'autoescape-filtertag01': ("{{ first }}{% filter safe %}{{ first }} x<y{% endfilter %}", {"first": "<a>"}, template.TemplateSyntaxError),
    12881288        }
    12891289
     1290
     1291class TemplateTagLoading(unittest.TestCase):
     1292
     1293    def setUp(self):
     1294        self.old_path = sys.path
     1295        self.old_apps = settings.INSTALLED_APPS
     1296        self.egg_dir = '%s/eggs' % os.path.dirname(__file__)
     1297        self.old_tag_modules = template.templatetags_modules
     1298        template.templatetags_modules = []
     1299
     1300    def tearDown(self):
     1301        settings.INSTALLED_APPS = self.old_apps
     1302        sys.path = self.old_path
     1303        template.templatetags_modules = self.old_tag_modules
     1304
     1305    def test_load_error(self):
     1306        ttext = "{% load broken_tag %}"
     1307        self.assertRaises(template.TemplateSyntaxError, template.Template, ttext)
     1308        try:
     1309            template.Template(ttext)
     1310        except template.TemplateSyntaxError, e:
     1311            self.assertTrue('ImportError' in e.args[0])
     1312            self.assertTrue('Xtemplate' in e.args[0])
     1313
     1314    def test_load_error_egg(self):
     1315        ttext = "{% load broken_egg %}"
     1316        egg_name = '%s/tagsegg.egg' % self.egg_dir
     1317        sys.path.append(egg_name)
     1318        settings.INSTALLED_APPS = ('tagsegg',)
     1319        self.assertRaises(template.TemplateSyntaxError, template.Template, ttext)
     1320        try:
     1321            template.Template(ttext)
     1322        except template.TemplateSyntaxError, e:
     1323            self.assertTrue('ImportError' in e.args[0])
     1324            self.assertTrue('Xtemplate' in e.args[0])
     1325
     1326    def test_load_working_egg(self):
     1327        ttext = "{% load working_egg %}"
     1328        egg_name = '%s/tagsegg.egg' % self.egg_dir
     1329        sys.path.append(egg_name)
     1330        settings.INSTALLED_APPS = ('tagsegg',)
     1331        t = template.Template(ttext)
     1332
    12901333if __name__ == "__main__":
    12911334    unittest.main()
  • tests/regressiontests/templates/templatetags/broken_tag.py

     
     1from django import Xtemplate
Back to Top