def shlex_split(x):
    """Helper function to split lines into segments.
    """
    # 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 __HOLE__:
            endofline = [x[-1:]]+endofline
            x = x[:-1]

    return [''.join(endofline)]
dataset/ETHPy150Open ipython/ipython-py3k/IPython/core/completerlib.py/shlex_split