Ticket #12072: patch-12072-d.diff
File patch-12072-d.diff, 4.1 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/templates/tests.py
1031 1031 'url08': (u'{% url метка_оператора v %}', {'v': 'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 1032 1032 'url09': (u'{% url метка_оператора_2 tag=v %}', {'v': 'Ω'}, '/url_tag/%D0%AE%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4/%CE%A9/'), 1033 1033 'url10': ('{% url regressiontests.templates.views.client_action id=client.id,action="two words" %}', {'client': {'id': 1}}, '/url_tag/client/1/two%20words/'), 1034 'url11': ('{% url regressiontests.templates.views.client_action id=client.id,action="==" %}', {'client': {'id': 1}}, '/url_tag/client/1/==/'), 1035 'url12': ('{% url regressiontests.templates.views.client_action id=client.id,action="," %}', {'client': {'id': 1}}, '/url_tag/client/1/,/'), 1036 'url12': ('{% url regressiontests.templates.views.client_action id=client.id,action=arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'), 1034 1037 1035 1038 # Failures 1036 1039 'url-fail01': ('{% url %}', {}, template.TemplateSyntaxError), 1037 1040 'url-fail02': ('{% url no_such_view %}', {}, urlresolvers.NoReverseMatch), 1038 1041 'url-fail03': ('{% url regressiontests.templates.views.client %}', {}, urlresolvers.NoReverseMatch), 1042 'url-fail04': ('{% url view id, %}', {}, template.TemplateSyntaxError), 1043 'url-fail05': ('{% url view id= %}', {}, template.TemplateSyntaxError), 1044 'url-fail06': ('{% url view a.id=id %}', {}, template.TemplateSyntaxError), 1045 'url-fail07': ('{% url view a.id!id %}', {}, template.TemplateSyntaxError), 1046 'url-fail08': ('{% url view id="unterminatedstring %}', {}, template.TemplateSyntaxError), 1047 'url-fail09': ('{% url view id=", %}', {}, template.TemplateSyntaxError), 1039 1048 1040 1049 # {% url ... as var %} 1041 1050 'url-asvar01': ('{% url regressiontests.templates.views.index as url %}', {}, ''), -
django/template/defaulttags.py
1071 1071 return TemplateTagNode(tag) 1072 1072 templatetag = register.tag(templatetag) 1073 1073 1074 # Regex for URL arguments including filters 1075 value = '''(?:(?:'[^']*')|(?:"[^"]*")|(?:[\w\.-]+))''' 1076 value = r"(%(value)s(?:\|%(name)s(?::%(value)s)?)*)" % {'name':'(?:\w+)', 'value':value} 1077 url_arg_re = re.compile(''' 1078 ([a-zA-Z_]\w*)=%(value)s 1079 | 1080 %(value)s 1081 ''' % { 'value': value }, re.VERBOSE) 1082 1074 1083 def url(parser, token): 1075 1084 """ 1076 1085 Returns an absolute URL matching given view with its parameters. … … 1118 1127 asvar = bits.next() 1119 1128 break 1120 1129 else: 1121 for arg in bit.split(","): 1122 if '=' in arg: 1123 k, v = arg.split('=', 1) 1124 k = k.strip() 1125 kwargs[k] = parser.compile_filter(v) 1126 elif arg: 1127 args.append(parser.compile_filter(arg)) 1130 for i, match in enumerate(url_arg_re.finditer(bit)): 1131 if (i == 0 and match.start() != 0) or \ 1132 (i > 0 and (bit[end:match.start()] != ',')): 1133 raise TemplateSyntaxError("Malformed arguments to url tag") 1134 end = match.end() 1135 name, value = match.group(1), match.group(2) or match.group(3) 1136 if name: 1137 kwargs[name] = parser.compile_filter(value) 1138 else: 1139 args.append(parser.compile_filter(value)) 1140 if end != len(bit): 1141 raise TemplateSyntaxError("Malformed arguments to url tag") 1142 1128 1143 return URLNode(viewname, args, kwargs, asvar) 1129 1144 url = register.tag(url) 1130 1145