Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
token.split_contents() behavior
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tom von Schwerdtner  
View profile  
 More options Nov 7, 1:28 pm
From: Tom von Schwerdtner <tomv...@gmail.com>
Date: Fri, 6 Nov 2009 18:28:57 -0800 (PST)
Local: Sat, Nov 7 2009 1:28 pm
Subject: token.split_contents() behavior
This confuses me a bit, so I thought I'd see if anyone knows why this
works the way it does.

If I have this custom tag:

    {% foo bar baz %}

token.split_contents() will give me three strings:

    ['foo', 'bar', 'baz']

Yet if I have:

    {% foo "bar baz" %}

token.split_contents() will give two strings, the second of which
includes the quotes:

    ['foo', '"bar baz"']

Is that the intended behavior? It seems a bit wonky...

-Tom


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tomasz Zieliński  
View profile  
 More options Nov 8, 4:33 am
From: Tomasz Zieliński <tomasz.zielin...@pyconsultant.eu>
Date: Sat, 7 Nov 2009 09:33:02 -0800 (PST)
Local: Sun, Nov 8 2009 4:33 am
Subject: Re: token.split_contents() behavior
On 7 Lis, 03:28, Tom von Schwerdtner <tomv...@gmail.com> wrote:

> Is that the intended behavior? It seems a bit wonky...

http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writ...

"""
if not (format_string[0] == format_string[-1] and format_string[0] in
('"', "'")):
        raise template.TemplateSyntaxError, "%r tag's argument should
be in quotes" % tag_name
"""

"""
The token.split_contents() method separates the arguments on spaces
while keeping quoted strings together. The more straightforward
token.contents.split() wouldn't be as robust, as it would naively
split on all spaces, including those within quoted strings. It's a
good idea to always use token.split_contents().
"""

So - yes, it is intended

--
Tomasz Zieliński
http://pyconsultant.eu


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google