def split_key(key, max_keys=0):
    """Splits a key but allows dots in the key name if they're scaped properly.

    Splitting this complex key:

    complex_key = ".dont\.splitme.d\.o\. origen.splitme\.dontsplit.splitme."
    split_key(complex_key)

    results in:

    ['', 'dont\.splitme', 'd\.o\. origen', 'splitme\.dontsplit', 'splitme', '']


    Args:
        key (basestring): The key to be splitted.
        max_keys (int): The maximum number of keys to be extracted. 0 means no
            limits.

    Returns:
        A list of keys
    """
    parts = [x for x in re.split(SPLIT_REGEX, key) if x != "."]
    result = []
    while len(parts) > 0:
        if max_keys > 0 and len(result) == max_keys:
            break
        result.append(parts.pop(0))

    if len(parts) > 0:
        result.append(".".join(parts))
    return result
def split_key ( key , max_keys = 0 ) : parts = [ x for x in re . split ( SPLIT_REGEX , key ) if x != "." ] result = [ ] while len ( parts ) > 0 : if max_keys > 0 and len ( result ) == max_keys : break result . append ( parts . pop ( 0 ) ) if len ( parts ) > 0 : result . append ( "." . join ( parts ) ) return result
Splits a key but allows dots in the key name if they're scaped properly.

    Splitting this complex key:

    complex_key = ".dont\.splitme.d\.o\. origen.splitme\.dontsplit.splitme."
    split_key(complex_key)

    results in:

    ['', 'dont\.splitme', 'd\.o\. origen', 'splitme\.dontsplit', 'splitme', '']


    Args:
        key (basestring): The key to be splitted.
        max_keys (int): The maximum number of keys to be extracted. 0 means no
            limits.

    Returns:
        A list of keys