Django

Code

Changeset 3111

Show
Ignore:
Timestamp:
06/07/06 23:26:23 (2 years ago)
Author:
adrian
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/utils/text.py

    r3101 r3111  
    112112smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)') 
    113113def 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    """ 
    114122    for bit in smart_split_re.finditer(text): 
    115123        bit = bit.group(0) 
    116124        if bit[0] == '"': 
    117             yield (bit[1:-1].replace('\\"', '"').replace('\\\\', '\\'), True) 
     125            yield '"' + bit[1:-1].replace('\\"', '"').replace('\\\\', '\\') + '"' 
    118126        elif bit[0] == "'": 
    119             yield (bit[1:-1].replace("\\'", "'").replace("\\\\", "\\"), True) 
     127            yield "'" + bit[1:-1].replace("\\'", "'").replace("\\\\", "\\") + "'" 
    120128        else: 
    121             yield (bit, False) 
     129            yield bit