Permalink
Browse files

Refs #7297 -- Corrected some doctest strings internal to the utils.te…

…xt module. Thanks, akaihola.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7581 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 0433ffa commit 0586239660892f4a9fc4301a9c913241c457c876 @freakboy3742 freakboy3742 committed Jun 6, 2008
Showing with 13 additions and 9 deletions.
  1. +13 −9 django/utils/text.py
View
22 django/utils/text.py
@@ -118,7 +118,7 @@ def get_valid_filename(s):
spaces are converted to underscores; and all non-filename-safe characters
are removed.
>>> get_valid_filename("john's portrait in 2004.jpg")
- 'johns_portrait_in_2004.jpg'
+ u'johns_portrait_in_2004.jpg'
"""
s = force_unicode(s).strip().replace(' ', '_')
return re.sub(r'[^-A-Za-z0-9_.]', '', s)
@@ -127,15 +127,15 @@ def get_valid_filename(s):
def get_text_list(list_, last_word=ugettext_lazy(u'or')):
"""
>>> get_text_list(['a', 'b', 'c', 'd'])
- 'a, b, c or d'
+ u'a, b, c or d'
>>> get_text_list(['a', 'b', 'c'], 'and')
- 'a, b and c'
+ u'a, b and c'
>>> get_text_list(['a', 'b'], 'and')
- 'a and b'
+ u'a and b'
>>> get_text_list(['a'])
- 'a'
+ u'a'
>>> get_text_list([])
- ''
+ u''
"""
if len(list_) == 0: return u''
if len(list_) == 1: return force_unicode(list_[0])
@@ -198,14 +198,18 @@ def fix(match):
smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')
def smart_split(text):
- """
+ r"""
Generator that splits a string by spaces, leaving quoted phrases together.
Supports both single and double quotes, and supports escaping quotes with
backslashes. In the output, strings will keep their initial and trailing
quote marks.
- >>> list(smart_split('This is "a person\'s" test.'))
- ['This', 'is', '"a person\'s"', 'test.']
+ >>> list(smart_split(r'This is "a person\'s" test.'))
+ [u'This', u'is', u'"a person\\\'s"', u'test.']
+ >>> list(smart_split(r"Another 'person\'s' test."))
+ [u'Another', u"'person's'", u'test.']
+ >>> list(smart_split(r'A "\"funky\" style" test.'))
+ [u'A', u'""funky" style"', u'test.']
"""
text = force_unicode(text)
for bit in smart_split_re.finditer(text):

0 comments on commit 0586239

Please sign in to comment.