Utility for key management in dig/dug

    If first elem of key list contains an index[], spread it out as a second
    numeric index.

    >>> _splice_index('abc[0]', 'def')
    ('abc', 0, 'def')
    >>> _splice_index('abc[a]', 'def')
    ('abc[a]', 'def')
    >>> _splice_index('abc[200]', 'def')
    ('abc', 200, 'def')
    >>> _splice_index('abc', 'def')
    ('abc', 'def')
    >>> _splice_index(0, 'abc', 'def')
    (0, 'abc', 'def')

def _splice_index(*key):
    """
    Utility for key management in dig/dug

    If first elem of key list contains an index[], spread it out as a second
    numeric index.

    >>> _splice_index('abc[0]', 'def')
    ('abc', 0, 'def')
    >>> _splice_index('abc[a]', 'def')
    ('abc[a]', 'def')
    >>> _splice_index('abc[200]', 'def')
    ('abc', 200, 'def')
    >>> _splice_index('abc', 'def')
    ('abc', 'def')
    >>> _splice_index(0, 'abc', 'def')
    (0, 'abc', 'def')
    """
    if isinstance(key[0], str):
        result = rx_index.search(key[0])
        if result:
            return tuple([result.group(1), int(result.group(2))] + list(key[1:]))
    return key