Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 14:11:04 +02:00
|
|
|
# coding: utf-8
|
|
|
|
r"""
|
|
|
|
# Tests for stuff in django.utils.text and other text munging util functions.
|
2007-03-30 13:57:50 +02:00
|
|
|
|
|
|
|
>>> from django.utils.text import *
|
|
|
|
|
|
|
|
### smart_split ###########################################################
|
|
|
|
>>> list(smart_split(r'''This is "a person" test.'''))
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 14:11:04 +02:00
|
|
|
[u'This', u'is', u'"a person"', u'test.']
|
2007-03-30 13:57:50 +02:00
|
|
|
>>> print list(smart_split(r'''This is "a person's" test.'''))[2]
|
|
|
|
"a person's"
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 14:11:04 +02:00
|
|
|
>>> print list(smart_split(r'''This is "a person\"s" test.'''))[2]
|
2009-03-23 10:40:25 +01:00
|
|
|
"a person\"s"
|
2007-03-30 13:57:50 +02:00
|
|
|
>>> list(smart_split('''"a 'one'''))
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 14:11:04 +02:00
|
|
|
[u'"a', u"'one"]
|
2007-03-30 13:57:50 +02:00
|
|
|
>>> print list(smart_split(r'''all friends' tests'''))[1]
|
|
|
|
friends'
|
2009-04-10 06:13:27 +02:00
|
|
|
>>> list(smart_split(u'url search_page words="something else"'))
|
|
|
|
[u'url', u'search_page', u'words="something else"']
|
|
|
|
>>> list(smart_split(u"url search_page words='something else'"))
|
|
|
|
[u'url', u'search_page', u"words='something else'"]
|
|
|
|
>>> list(smart_split(u'url search_page words "something else"'))
|
|
|
|
[u'url', u'search_page', u'words', u'"something else"']
|
|
|
|
>>> list(smart_split(u'url search_page words-"something else"'))
|
|
|
|
[u'url', u'search_page', u'words-"something else"']
|
|
|
|
>>> list(smart_split(u'url search_page words=hello'))
|
|
|
|
[u'url', u'search_page', u'words=hello']
|
|
|
|
>>> list(smart_split(u'url search_page words="something else'))
|
|
|
|
[u'url', u'search_page', u'words="something', u'else']
|
2010-02-24 21:52:14 +01:00
|
|
|
>>> list(smart_split("cut:','|cut:' '"))
|
|
|
|
[u"cut:','|cut:' '"]
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 14:11:04 +02:00
|
|
|
|
|
|
|
### urlquote #############################################################
|
|
|
|
>>> from django.utils.http import urlquote, urlquote_plus
|
|
|
|
>>> urlquote(u'Paris & Orl\xe9ans')
|
|
|
|
u'Paris%20%26%20Orl%C3%A9ans'
|
2007-10-20 10:38:59 +02:00
|
|
|
>>> urlquote(u'Paris & Orl\xe9ans', safe="&")
|
|
|
|
u'Paris%20&%20Orl%C3%A9ans'
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 14:11:04 +02:00
|
|
|
>>> urlquote_plus(u'Paris & Orl\xe9ans')
|
|
|
|
u'Paris+%26+Orl%C3%A9ans'
|
2007-10-20 10:38:59 +02:00
|
|
|
>>> urlquote_plus(u'Paris & Orl\xe9ans', safe="&")
|
|
|
|
u'Paris+&+Orl%C3%A9ans'
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 14:11:04 +02:00
|
|
|
|
2007-10-31 04:59:40 +01:00
|
|
|
### cookie_date, http_date ###############################################
|
|
|
|
>>> from django.utils.http import cookie_date, http_date
|
|
|
|
>>> t = 1167616461.0
|
|
|
|
>>> cookie_date(t)
|
|
|
|
'Mon, 01-Jan-2007 01:54:21 GMT'
|
|
|
|
>>> http_date(t)
|
|
|
|
'Mon, 01 Jan 2007 01:54:21 GMT'
|
|
|
|
|
Merged Unicode branch into trunk (r4952:5608). This should be fully
backwards compatible for all practical purposes.
Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2007-07-04 14:11:04 +02:00
|
|
|
### iri_to_uri ###########################################################
|
|
|
|
>>> from django.utils.encoding import iri_to_uri
|
|
|
|
>>> iri_to_uri(u'red%09ros\xe9#red')
|
|
|
|
'red%09ros%C3%A9#red'
|
|
|
|
>>> iri_to_uri(u'/blog/for/J\xfcrgen M\xfcnster/')
|
|
|
|
'/blog/for/J%C3%BCrgen%20M%C3%BCnster/'
|
|
|
|
>>> iri_to_uri(u'locations/%s' % urlquote_plus(u'Paris & Orl\xe9ans'))
|
|
|
|
'locations/Paris+%26+Orl%C3%A9ans'
|
|
|
|
|
|
|
|
iri_to_uri() is idempotent:
|
|
|
|
>>> iri_to_uri(iri_to_uri(u'red%09ros\xe9#red'))
|
|
|
|
'red%09ros%C3%A9#red'
|
2007-03-30 13:57:50 +02:00
|
|
|
"""
|