from io import StringIO


def parseParam(line):
    """Chew one dqstring or atom from beginning of line and return (param, remaningline)"""
    if line == '':
        return (None, '')
    elif line[0] != '"': # atom
        mode = 1
    else: # dqstring
        mode = 2
    res = ""
    io = StringIO(line)
    if mode == 2: # skip the opening quote
        io.read(1)
    while 1:
        a = io.read(1)
        if a == '"':
            if mode == 2:
                io.read(1) # skip the separating space
                return (res, io.read())
        elif a == '\\':
            a = io.read(1)
            if a == '':
                return (None, line) # unexpected end of string
        elif a == '':
            if mode == 1:
                return (res, io.read())
            else:
                return (None, line) # unexpected end of string
        elif a == ' ':
            if mode == 1:
                return (res, io.read())
        res += a