Ticket #10001: ticket10001-0.1.patch
File ticket10001-0.1.patch, 2.5 KB (added by , 16 years ago) |
---|
-
django/utils/text.py
197 197 return str(ustring_re.sub(fix, s)) 198 198 javascript_quote = allow_lazy(javascript_quote, unicode) 199 199 200 smart_split_re = re.compile(' ("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')200 smart_split_re = re.compile('[^\\s"\'\\\\]*("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)') 201 201 def smart_split(text): 202 202 r""" 203 203 Generator that splits a string by spaces, leaving quoted phrases together. … … 211 211 [u'Another', u"'person's'", u'test.'] 212 212 >>> list(smart_split(r'A "\"funky\" style" test.')) 213 213 [u'A', u'""funky" style"', u'test.'] 214 >>> list(smart_split(r"A variable='value' should work.")) 215 [u'A', u"variable='value'", u'should', u'work.'] 216 >>> list(smart_split(r"A variable='value with spaces' should also work.")) 217 [u'A', u"variable='value with spaces'", u'should', u'also', u'work.'] 218 >>> list(smart_split(r'A variable="value with spaces" should also work.')) 219 [u'A', u'variable="value with spaces"', u'should', u'also', u'work.'] 220 >>> list(smart_split(r'A variable="value with spaces and \'escaped quotes\'" should also work.')) 221 [u'A', u'variable="value with spaces and \\\'escaped quotes\\\'"', u'should', u'also', u'work.'] 214 222 """ 215 223 text = force_unicode(text) 216 224 for bit in smart_split_re.finditer(text): -
tests/regressiontests/text/tests.py
15 15 [u'"a', u"'one"] 16 16 >>> print list(smart_split(r'''all friends' tests'''))[1] 17 17 friends' 18 >>> list(smart_split(r"A variable='value' should work.")) 19 [u'A', u"variable='value'", u'should', u'work.'] 20 >>> list(smart_split(r"A variable='value with spaces' should also work.")) 21 [u'A', u"variable='value with spaces'", u'should', u'also', u'work.'] 22 >>> list(smart_split(r'A variable="value with spaces" should also work.')) 23 [u'A', u'variable="value with spaces"', u'should', u'also', u'work.'] 24 >>> list(smart_split(r'A variable="value with spaces and \'escaped quotes\'" should also work.')) 25 [u'A', u'variable="value with spaces and \\\'escaped quotes\\\'"', u'should', u'also', u'work.'] 18 26 19 27 ### urlquote ############################################################# 20 28 >>> from django.utils.http import urlquote, urlquote_plus