Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Changed django.utils.text.smart_split to return strings, not tuples

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3111 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0f0560a9ac7827e54966d6460ab6c016626c78c2 1 parent a88e0ec
Adrian Holovaty authored June 08, 2006

Showing 1 changed file with 11 additions and 3 deletions. Show diff stats Hide diff stats

  1. 14  django/utils/text.py
14  django/utils/text.py
@@ -111,11 +111,19 @@ def fix(match):
111 111
 
112 112
 smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')
113 113
 def smart_split(text):
  114
+    """
  115
+    Generator that splits a string by spaces, leaving quoted phrases together.
  116
+    Supports both single and double quotes, and supports escaping quotes with
  117
+    backslashes. In the output, strings will keep their initial and trailing
  118
+    quote marks.
  119
+    >>> list(smart_split('This is "a person\'s" test.'))
  120
+    ['This', 'is', '"a person\'s"', 'test.']
  121
+    """
114 122
     for bit in smart_split_re.finditer(text):
115 123
         bit = bit.group(0)
116 124
         if bit[0] == '"':
117  
-            yield (bit[1:-1].replace('\\"', '"').replace('\\\\', '\\'), True)
  125
+            yield '"' + bit[1:-1].replace('\\"', '"').replace('\\\\', '\\') + '"'
118 126
         elif bit[0] == "'":
119  
-            yield (bit[1:-1].replace("\\'", "'").replace("\\\\", "\\"), True)
  127
+            yield "'" + bit[1:-1].replace("\\'", "'").replace("\\\\", "\\") + "'"
120 128
         else:
121  
-            yield (bit, False)
  129
+            yield bit

0 notes on commit 0f0560a

Please sign in to comment.
Something went wrong with that request. Please try again.