def parseParam(line):
    """Chew one dqstring or atom from beginning of line and return (param, remaningline)"""
    if line == b'':
        return (None, b'')
    elif line[0:1] != b'"': # atom
        mode = 1
    else: # dqstring
        mode = 2
    res = b""
    io = BytesIO(line)
    if mode == 2: # skip the opening quote
        io.read(1)
    while 1:
        a = io.read(1)
        if a == b'"':
            if mode == 2:
                io.read(1) # skip the separating space
                return (res, io.read())
        elif a == b'\\':
            a = io.read(1)
            if a == b'':
                return (None, line) # unexpected end of string
        elif a == b'':
            if mode == 1:
                return (res, io.read())
            else:
                return (None, line) # unexpected end of string
        elif a == b' ':
            if mode == 1:
                return (res, io.read())
        res += a
Chew one dqstring or atom from beginning of line and return (param, remaningline)
stackoverflow/venv/lib/python3.6/site-packages/twisted/protocols/dict.py