Django

Code

Changeset 2713

Show
Ignore:
Timestamp:
04/18/06 08:41:21 (3 years ago)
Author:
russellm
Message:

magic-removal: Fixed #1198 -- Modified handling of escape characters in filter arguments, and updated unit tests to reflect the change.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/template/__init__.py

    r2604 r2713  
    520520                constant_arg, i18n_arg, var_arg = match.group("constant_arg", "i18n_arg", "var_arg") 
    521521                if i18n_arg: 
    522                     args.append((False, _(i18n_arg.replace('\\', '')))) 
     522                    args.append((False, _(i18n_arg.replace(r'\"', '"')))) 
    523523                elif constant_arg: 
    524                     args.append((False, constant_arg.replace('\\', ''))) 
     524                    args.append((False, constant_arg.replace(r'\"', '"'))) 
    525525                elif var_arg: 
    526526                    args.append((True, var_arg)) 
  • django/branches/magic-removal/tests/othertests/dateformat.py

    r1146 r2713  
    1 """ 
     1r""" 
    22>>> format(my_birthday, '') 
    33'' 
     
    66>>> format(my_birthday, 'A') 
    77'PM' 
     8>>> format(my_birthday, 'd') 
     9'08' 
    810>>> format(my_birthday, 'j') 
    9 '7
     11'8
    1012>>> format(my_birthday, 'l') 
    11 'Saturday' 
     13'Sunday' 
    1214>>> format(my_birthday, 'L') 
    1315'False' 
     
    2527'10 p.m.' 
    2628>>> format(my_birthday, 'r') 
    27 'Sat, 7 Jul 1979 22:00:00 +0100' 
     29'Sun, 8 Jul 1979 22:00:00 +0100' 
    2830>>> format(my_birthday, 's') 
    2931'00' 
     
    3537'CET' 
    3638>>> format(my_birthday, 'U') 
    37 '300445200' 
     39'300531600' 
    3840>>> format(my_birthday, 'w') 
    39 '6
     41'0
    4042>>> format(my_birthday, 'W') 
    4143'27' 
     
    4547'1979' 
    4648>>> format(my_birthday, 'z') 
    47 '188
     49'189
    4850>>> format(my_birthday, 'Z') 
    4951'3600' 
     
    5860'+0100' 
    5961 
    60 >>> format(my_birthday, 'Y z \\C\\E\\T') 
    61 '1979 188 CET' 
     62>>> format(my_birthday, r'Y z \C\E\T') 
     63'1979 189 CET' 
     64 
     65>>> format(my_birthday, r'jS o\f F') 
     66'8th of July' 
    6267""" 
    6368 
     
    7176time.tzset() 
    7277 
    73 my_birthday = datetime.datetime(1979, 7, 7, 22, 00) 
     78my_birthday = datetime.datetime(1979, 7, 8, 22, 00) 
    7479summertime = datetime.datetime(2005, 10, 30, 1, 00) 
    7580wintertime = datetime.datetime(2005, 10, 30, 4, 00) 
  • django/branches/magic-removal/tests/othertests/defaultfilters.py

    r2393 r2713  
    1 """ 
     1r""" 
    22>>> floatformat(7.7) 
    33'7.7' 
     
    1313'0' 
    1414 
    15 >>> addslashes('"double quotes" and \\'single quotes\\'') 
    16 '\\\\"double quotes\\\\" and \\\\\\'single quotes\\\\\\'' 
     15>>> addslashes('"double quotes" and \'single quotes\'') 
     16'\\"double quotes\\" and \\\'single quotes\\\'' 
    1717 
    1818>>> capfirst('hello world') 
     
    2222'Jack & Jill & Jeroboam' 
    2323 
    24 >>> linenumbers('line 1\\nline 2') 
    25 '1. line 1\\n2. line 2' 
    26  
    27 >>> linenumbers('\\n'.join(['x'] * 10)) 
    28 '01. x\\n02. x\\n03. x\\n04. x\\n05. x\\n06. x\\n07. x\\n08. x\\n09. x\\n10. x' 
     24>>> linenumbers('line 1\nline 2') 
     25'1. line 1\n2. line 2' 
     26 
     27>>> linenumbers('\n'.join(['x'] * 10)) 
     28'01. x\n02. x\n03. x\n04. x\n05. x\n06. x\n07. x\n08. x\n09. x\n10. x' 
    2929 
    3030>>> lower('TEST') 
    3131'test' 
    3232 
    33 >>> lower(u'\\xcb') # uppercase E umlaut 
    34 u'\\xeb' 
     33>>> lower(u'\xcb') # uppercase E umlaut 
     34u'\xeb' 
    3535 
    3636>>> make_list('abc') 
     
    4949'' 
    5050 
    51 >>> title('a nice title, isn\\'t it?') 
     51>>> title('a nice title, isn\'t it?') 
    5252"A Nice Title, Isn't It?" 
    5353 
     
    6969'MIXED CASE INPUT' 
    7070 
    71 >>> upper(u'\\xeb') # lowercase e umlaut 
    72 u'\\xcb' 
     71>>> upper(u'\xeb') # lowercase e umlaut 
     72u'\xcb' 
    7373 
    7474 
     
    92923 
    9393 
    94 >>> wordwrap('this is a long paragraph of text that really needs to be wrapped I\\'m afraid', 14) 
    95 "this is a long\\nparagraph of\\ntext that\\nreally needs\\nto be wrapped\\nI'm afraid" 
     94>>> wordwrap('this is a long paragraph of text that really needs to be wrapped I\'m afraid', 14) 
     95"this is a long\nparagraph of\ntext that\nreally needs\nto be wrapped\nI'm afraid" 
    9696 
    9797>>> ljust('test', 10) 
     
    125125'<p>line 1</p>' 
    126126 
    127 >>> linebreaks('line 1\\nline 2') 
     127>>> linebreaks('line 1\nline 2') 
    128128'<p>line 1<br />line 2</p>' 
    129129 
     
    134134'some html with alert("You smell") disallowed  tags' 
    135135 
    136 >>> dictsort([{'age': 23, 'name': 'Barbara-Ann'},\ 
    137               {'age': 63, 'name': 'Ra Ra Rasputin'},\ 
    138               {'name': 'Jonny B Goode', 'age': 18}], 'age') 
    139 [{'age': 18, 'name': 'Jonny B Goode'},\ 
    140  {'age': 23, 'name': 'Barbara-Ann'},\ 
    141  {'age': 63, 'name': 'Ra Ra Rasputin'}] 
    142  
    143 >>> dictsortreversed([{'age': 23, 'name': 'Barbara-Ann'},\ 
    144               {'age': 63, 'name': 'Ra Ra Rasputin'},\ 
    145               {'name': 'Jonny B Goode', 'age': 18}], 'age') 
    146 [{'age': 63, 'name': 'Ra Ra Rasputin'},\ 
    147  {'age': 23, 'name': 'Barbara-Ann'},\ 
    148  {'age': 18, 'name': 'Jonny B Goode'}] 
     136>>> dictsort([{'age': 23, 'name': 'Barbara-Ann'}, 
     137...           {'age': 63, 'name': 'Ra Ra Rasputin'}, 
     138...           {'name': 'Jonny B Goode', 'age': 18}], 'age') 
     139[{'age': 18, 'name': 'Jonny B Goode'}, {'age': 23, 'name': 'Barbara-Ann'}, {'age': 63, 'name': 'Ra Ra Rasputin'}] 
     140 
     141>>> dictsortreversed([{'age': 23, 'name': 'Barbara-Ann'}, 
     142...           {'age': 63, 'name': 'Ra Ra Rasputin'}, 
     143...           {'name': 'Jonny B Goode', 'age': 18}], 'age') 
     144[{'age': 63, 'name': 'Ra Ra Rasputin'}, {'age': 23, 'name': 'Barbara-Ann'}, {'age': 18, 'name': 'Jonny B Goode'}] 
    149145 
    150146>>> first([0,1,2]) 
     
    197193 
    198194>>> unordered_list(['item 1', []]) 
    199 '\\t<li>item 1</li>' 
     195'\t<li>item 1</li>' 
    200196 
    201197>>> unordered_list(['item 1', [['item 1.1', []]]]) 
    202 '\\t<li>item 1\\n\\t<ul>\\n\\t\\t<li>item 1.1</li>\\n\\t</ul>\\n\\t</li>' 
     198'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1</li>\n\t</ul>\n\t</li>' 
    203199 
    204200>>> unordered_list(['item 1', [['item 1.1', []], ['item 1.2', []]]]) 
    205 '\\t<li>item 1\\n\\t<ul>\\n\\t\\t<li>item 1.1</li>\\n\\t\\t<li>item 1.2</li>\\n\\t</ul>\\n\\t</li>' 
     201'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1</li>\n\t\t<li>item 1.2</li>\n\t</ul>\n\t</li>' 
    206202 
    207203>>> add('1', '2') 
     
    229225>>> date(datetime.datetime(2005, 12, 29), "d F Y") 
    230226'29 December 2005' 
     227>>> date(datetime.datetime(2005, 12, 29), r'jS o\f F') 
     228'29th of December' 
    231229 
    232230# real testing of time() is done in dateformat.py 
  • django/branches/magic-removal/tests/othertests/templates.py

    r2030 r2713  
    55from django.template import loader 
    66from django.utils.translation import activate, deactivate, install 
     7from datetime import datetime 
    78import traceback 
    89 
     
    152153    # the exception propogates 
    153154    'basic-syntax34': (r'1{{ var.method4 }}2', {"var": SomeClass()}, SomeOtherException), 
     155 
     156    # Escaped backslash in argument 
     157    'basic-syntax35': (r'{{ var|default_if_none:"foo\bar" }}', {"var": None}, r'foo\bar'), 
     158 
     159    # Escaped backslash using known escape char 
     160    'basic-syntax35': (r'{{ var|default_if_none:"foo\now" }}', {"var": None}, r'foo\now'), 
    154161 
    155162    ### COMMENT TAG ########################################################### 
     
    434441    'widthratio09': ('{% widthratio a b %}', {'a':50,'b':100}, template.TemplateSyntaxError), 
    435442    'widthratio10': ('{% widthratio a b 100.0 %}', {'a':50,'b':100}, template.TemplateSyntaxError), 
     443     
     444    ### NOW TAG ######################################################## 
     445    # Simple case 
     446    'now01' : ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)), 
     447     
     448    # Check parsing of escaped and special characters 
     449    'now02' : ('{% now "j "n" Y"%}', {}, template.TemplateSyntaxError), 
     450#    'now03' : ('{% now "j \"n\" Y"%}', {}, str(datetime.now().day) + '"' + str(datetime.now().month) + '"' + str(datetime.now().year)), 
     451#    'now04' : ('{% now "j \nn\n Y"%}', {}, str(datetime.now().day) + '\n' + str(datetime.now().month) + '\n' + str(datetime.now().year)) 
    436452} 
    437453