Ticket #10001: ticket10001-0.1.patch

File ticket10001-0.1.patch, 2.5 KB (added by Paul O’Shannessy, 16 years ago)

Patch v0.1

  • django/utils/text.py

     
    197197    return str(ustring_re.sub(fix, s))
    198198javascript_quote = allow_lazy(javascript_quote, unicode)
    199199
    200 smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')
     200smart_split_re = re.compile('[^\\s"\'\\\\]*("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')
    201201def smart_split(text):
    202202    r"""
    203203    Generator that splits a string by spaces, leaving quoted phrases together.
     
    211211    [u'Another', u"'person's'", u'test.']
    212212    >>> list(smart_split(r'A "\"funky\" style" test.'))
    213213    [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.']
    214222    """
    215223    text = force_unicode(text)
    216224    for bit in smart_split_re.finditer(text):
  • tests/regressiontests/text/tests.py

     
    1515[u'"a', u"'one"]
    1616>>> print list(smart_split(r'''all friends' tests'''))[1]
    1717friends'
     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.']
    1826
    1927### urlquote #############################################################
    2028>>> from django.utils.http import urlquote, urlquote_plus
Back to Top