Ticket #9666: 9666-with-tests.diff
File 9666-with-tests.diff, 5.6 KB (added by , 16 years ago) |
---|
-
django/template/defaulttags.py
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 835b1a9..91bc169 100644
a b 2 2 3 3 import sys 4 4 import re 5 import os 5 6 from itertools import cycle as itertools_cycle 6 7 try: 7 8 reversed … … class SsiNode(Node): 287 288 self.filepath, self.parsed = filepath, parsed 288 289 289 290 def render(self, context): 290 if not include_is_allowed(self.filepath): 291 filepath = self.filepath 292 try: 293 filepath = filepath.resolve(context) 294 except (AttributeError, VariableDoesNotExist): 295 pass 296 if not include_is_allowed(filepath): 291 297 if settings.DEBUG: 292 298 return "[Didn't have permission to include file]" 293 299 else: 294 300 return '' # Fail silently for invalid includes. 295 301 try: 296 fp = open( self.filepath, 'r')302 fp = open(filepath, 'r') 297 303 output = fp.read() 298 304 fp.close() 299 305 except IOError: 300 306 output = '' 301 307 if self.parsed: 302 308 try: 303 t = Template(output, name= self.filepath)309 t = Template(output, name=filepath) 304 310 return t.render(context) 305 311 except TemplateSyntaxError, e: 306 312 if settings.DEBUG: … … class URLNode(Node): 377 383 except NoReverseMatch: 378 384 if self.asvar is None: 379 385 # Re-raise the original exception, not the one with 380 # the path relative to the project. This makes a 386 # the path relative to the project. This makes a 381 387 # better error message. 382 388 raise e 383 389 else: … … def ssi(parser, token): 897 903 else: 898 904 raise TemplateSyntaxError("Second (optional) argument to %s tag" 899 905 " must be 'parsed'" % bits[0]) 900 return SsiNode(bits[1], parsed) 906 var = bits[1] 907 #For backwards compatibility, let things that look like a path be quoted. 908 if os.path.sep in var and var[0] != "'" and var[0] != '"': 909 var = '"' + var + '"' 910 var = parser.compile_filter(var) 911 return SsiNode(var, parsed) 901 912 ssi = register.tag(ssi) 902 913 903 914 #@register.tag -
new file tests/regressiontests/templates/ssi_include.html
diff --git a/tests/regressiontests/templates/ssi_include.html b/tests/regressiontests/templates/ssi_include.html new file mode 100755 index 0000000..58d5926
- + 1 This is for testing an ssi include. {{ test }} -
tests/regressiontests/templates/tests.py
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index 953e8fa..6767778 100644
a b class SomeException(Exception): 69 69 70 70 class SomeOtherException(Exception): 71 71 pass 72 72 73 73 class ContextStackException(Exception): 74 74 pass 75 75 … … class Templates(unittest.TestCase): 211 211 old_invalid = settings.TEMPLATE_STRING_IF_INVALID 212 212 expected_invalid_str = 'INVALID' 213 213 214 #Set ALLOWED_INCLUDE_ROOTS so that ssi works. 215 old_allowed, settings.ALLOWED_INCLUDE_ROOTS = settings.ALLOWED_INCLUDE_ROOTS, os.path.dirname(os.path.abspath(__file__)) 216 214 217 for name, vals in tests: 215 218 if isinstance(vals[2], tuple): 216 219 normal_string_result = vals[2][0] … … class Templates(unittest.TestCase): 257 260 deactivate() 258 261 settings.TEMPLATE_DEBUG = old_td 259 262 settings.TEMPLATE_STRING_IF_INVALID = old_invalid 263 settings.ALLOWED_INCLUDE_ROOTS = old_allowed 260 264 261 265 self.assertEqual(failures, [], "Tests failed:\n%s\n%s" % 262 266 ('-'*70, ("\n%s\n" % ('-'*70)).join(failures))) … … class Templates(unittest.TestCase): 915 919 '{% endfor %}', 916 920 {}, ''), 917 921 922 ### SSI TAG ######################################################## 923 #Test normal behavior 924 'ssi01': ('{%% ssi %s %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'ssi_include.html'), {}, 'This is for testing an ssi include. {{ test }}\n'), 925 'ssi02': ('{%% ssi %s %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {}, ''), 926 #Test passing as a variable 927 'ssi03': ('{% ssi ssi_file %}', {'ssi_file': os.path.join(os.path.dirname(os.path.abspath(__file__)), 'ssi_include.html')}, 'This is for testing an ssi include. {{ test }}\n'), 928 'ssi04': ('{% ssi ssi_file %}', {'ssi_file': 'no_file'}, ''), 929 #Test parsed output 930 'ssi05': ('{%% ssi %s parsed %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'ssi_include.html'), {'test': 'Look ma! It parsed!'}, 'This is for testing an ssi include. Look ma! It parsed!\n'), 931 'ssi06': ('{%% ssi %s parsed %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {'test': 'Look ma! It parsed!'}, ''), 932 #Test quoting 933 'ssi07': ('{%% ssi "%s" %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'ssi_include.html'), {}, 'This is for testing an ssi include. {{ test }}\n'), 934 'ssi08': ('{%% ssi "%s" %%}' % os.path.join(os.path.dirname(os.path.abspath(__file__)), 'not_here'), {}, ''), 935 918 936 ### TEMPLATETAG TAG ####################################################### 919 937 'templatetag01': ('{% templatetag openblock %}', {}, '{%'), 920 938 'templatetag02': ('{% templatetag closeblock %}', {}, '%}'),