def shlex_split(x):
    # shlex.split raises an exception if there is a syntax error in sh syntax
    # for example if no closing " is found. This function keeps dropping the
    # last character of the line until shlex.split does not raise
    # an exception. It adds end of the line to the result of shlex.split
    #
    # Example:
    # %run "c:/python -> ['%run','"c:/python']
    endofline = []
    while x != '':
        try:
            comps = shlex.split(x)
            if len(endofline) >= 1:
                comps.append(''.join(endofline))
            return comps
        
        except ValueError:
            endofline = [x[-1:]]+endofline
            x = x[:-1]

    return [''.join(endofline)]
Helper function to split lines into segments.
dataset/ETHPy150Open ipython/ipython-py3k/IPython/core/completerlib.py/shlex_split