Ticket #1199: sprint-patch1.diff
File sprint-patch1.diff, 3.9 KB (added by , 17 years ago) |
---|
-
django/template/__init__.py
499 499 (?:%(filter_sep)s 500 500 (?P<filter_name>\w+) 501 501 (?:%(arg_sep)s 502 (?P<args> 502 503 (?: 503 %(i18n_open)s" (?P<i18n_arg>%(str)s)"%(i18n_close)s|504 " (?P<constant_arg>%(str)s)"|505 (?P<var_arg>[%(var_chars)s]+)504 %(i18n_open)s"%(str)s"%(i18n_close)s| 505 "%(str)s"| 506 [%(var_chars)s]+ 506 507 ) 508 (?: 509 ,%(i18n_open)s"%(str)s"%(i18n_close)s| 510 ,"%(str)s"| 511 ,[%(var_chars)s]+ 512 )* 513 ) 507 514 )? 508 515 )""" % { 509 516 'str': r"""[^"\\]*(?:\\.[^"\\]*)*""", … … 517 524 filter_raw_string = filter_raw_string.replace("\n", "").replace(" ", "") 518 525 filter_re = re.compile(filter_raw_string, re.UNICODE) 519 526 527 arg_raw_string = r""" 528 %(i18n_open)s"(?P<i18n_arg>%(str)s)"%(i18n_close)s| 529 "(?P<constant_arg>%(str)s)"| 530 (?P<var_arg>[%(var_chars)s]+)""" % { 531 'str': r"""[^"\\]*(?:\\.[^"\\]*)*""", 532 'var_chars': "\w\." , 533 'i18n_open' : re.escape("_("), 534 'i18n_close' : re.escape(")"), 535 } 536 537 arg_raw_string = arg_raw_string.replace("\n", "").replace(" ", "") 538 arg_re = re.compile(arg_raw_string, re.UNICODE) 539 520 540 class FilterExpression(object): 521 541 """ 522 542 Parses a variable token and its optional filters (all as a single string), … … 558 578 else: 559 579 filter_name = match.group("filter_name") 560 580 args = [] 561 constant_arg, i18n_arg, var_arg = match.group("constant_arg", "i18n_arg", "var_arg") 562 if i18n_arg: 563 args.append((False, _(i18n_arg.replace(r'\"', '"')))) 564 elif constant_arg is not None: 565 args.append((False, constant_arg.replace(r'\"', '"'))) 566 elif var_arg: 567 args.append((True, var_arg)) 581 arg_group = match.group("args") 582 if arg_group: 583 for arg_match in arg_re.finditer(arg_group): 584 constant_arg, i18n_arg, var_arg = arg_match.group("constant_arg", "i18n_arg", "var_arg") 585 if i18n_arg: 586 args.append((False, _(i18n_arg.replace(r'\"', '"')))) 587 elif constant_arg is not None: 588 args.append((False, constant_arg.replace(r'\"', '"'))) 589 elif var_arg: 590 args.append((True, var_arg)) 568 591 filter_func = parser.find_filter(filter_name) 569 592 self.args_check(filter_name,filter_func, args) 570 593 filters.append( (filter_func,args)) -
tests/regressiontests/templates/tests.py
41 41 42 42 register.tag("echo", do_echo) 43 43 44 def multi_args(arg1, arg2, arg3): 45 return " ".join([arg1, arg2, arg3]) 46 47 register.filter("multi_args", multi_args) 48 44 49 template.libraries['django.templatetags.testtags'] = register 45 50 46 51 ##################################### … … 272 277 # Numbers as filter arguments should work 273 278 'filter-syntax19': ('{{ var|truncatewords:1 }}', {"var": "hello world"}, "hello ..."), 274 279 280 # Filters can accept multiple arguments 281 'filter-syntax20': ('{% load testtags %}{{ var|multi_args:two,"three" }}', {"var": "one", "two": "see you"}, "one see you three"), 282 275 283 ### COMMENT SYNTAX ######################################################## 276 284 'comment-syntax01': ("{# this is hidden #}hello", {}, "hello"), 277 285 'comment-syntax02': ("{# this is hidden #}hello{# foo #}", {}, "hello"),