Code

Ticket #7297: 7297.1.diff

File 7297.1.diff, 2.0 KB (added by akaihola, 6 years ago)

Work-around for #7297 doctest problem and corrections to code examples in utils.text

Line 
1Index: ../django/utils/text.py
2===================================================================
3--- ../django/utils/text.py     (revision 7547)
4+++ ../django/utils/text.py     (working copy)
5@@ -118,7 +118,7 @@
6     spaces are converted to underscores; and all non-filename-safe characters
7     are removed.
8     >>> get_valid_filename("john's portrait in 2004.jpg")
9-    'johns_portrait_in_2004.jpg'
10+    u'johns_portrait_in_2004.jpg'
11     """
12     s = force_unicode(s).strip().replace(' ', '_')
13     return re.sub(r'[^-A-Za-z0-9_.]', '', s)
14@@ -127,15 +127,15 @@
15 def get_text_list(list_, last_word=ugettext_lazy(u'or')):
16     """
17     >>> get_text_list(['a', 'b', 'c', 'd'])
18-    'a, b, c or d'
19+    u'a, b, c or d'
20     >>> get_text_list(['a', 'b', 'c'], 'and')
21-    'a, b and c'
22+    u'a, b and c'
23     >>> get_text_list(['a', 'b'], 'and')
24-    'a and b'
25+    u'a and b'
26     >>> get_text_list(['a'])
27-    'a'
28+    u'a'
29     >>> get_text_list([])
30-    ''
31+    u''
32     """
33     if len(list_) == 0: return u''
34     if len(list_) == 1: return force_unicode(list_[0])
35@@ -198,14 +198,14 @@
36 
37 smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')
38 def smart_split(text):
39-    """
40+    r"""
41     Generator that splits a string by spaces, leaving quoted phrases together.
42     Supports both single and double quotes, and supports escaping quotes with
43     backslashes. In the output, strings will keep their initial and trailing
44     quote marks.
45 
46-    >>> list(smart_split('This is "a person\'s" test.'))
47-    ['This', 'is', '"a person\'s"', 'test.']
48+    >>> list(smart_split(r'This is "a person\'s" test.'))
49+    [u'This', u'is', u'"a person\\\'s"', u'test.']
50     """
51     text = force_unicode(text)
52     for bit in smart_split_re.finditer(text):
53@@ -218,3 +218,10 @@
54             yield bit
55 smart_split = allow_lazy(smart_split, unicode)
56 
57+# Work-around for http://bugs.python.org/issue1108
58+__doc__ = ''.join((
59+    get_valid_filename.__doc__,
60+    get_text_list.__doc__,
61+    smart_split.__doc__,
62+))
63+