Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@adrianholovaty adrianholovaty authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 django/utils/text.py
View
14 django/utils/text.py
@@ -111,11 +111,19 @@ def fix(match):
smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')
def smart_split(text):
+ """
+ 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.']
+ """
for bit in smart_split_re.finditer(text):
bit = bit.group(0)
if bit[0] == '"':
- yield (bit[1:-1].replace('\\"', '"').replace('\\\\', '\\'), True)
+ yield '"' + bit[1:-1].replace('\\"', '"').replace('\\\\', '\\') + '"'
elif bit[0] == "'":
- yield (bit[1:-1].replace("\\'", "'").replace("\\\\", "\\"), True)
+ yield "'" + bit[1:-1].replace("\\'", "'").replace("\\\\", "\\") + "'"
else:
- yield (bit, False)
+ yield bit
Please sign in to comment.
Something went wrong with that request. Please try again.