

def _split_keyvals(keyval_str, dialect=None):
    '\n    Given the string attributes field of a GFF-like line, split it into an\n    attributes dictionary and a "dialect" dictionary which contains information\n    needed to reconstruct the original string.\n\n    Lots of logic here to handle all the corner cases.\n\n    If `dialect` is None, then do all the logic to infer a dialect from this\n    attribute string.\n\n    Otherwise, use the provided dialect (and return it at the end).\n    '
    infer_dialect = False
    if (dialect is None):
        dialect = copy.copy(constants.dialect)
        infer_dialect = True
    from gffutils import feature
    quals = feature.dict_class()
    if (not keyval_str):
        return (quals, dialect)
    if (not infer_dialect):
        if dialect['trailing semicolon']:
            keyval_str = keyval_str.rstrip(';')
        parts = keyval_str.split(dialect['field separator'])
        kvsep = dialect['keyval separator']
        if dialect['leading semicolon']:
            pieces = []
            for p in parts:
                if (p and (p[0] == ';')):
                    p = p[1:]
                pieces.append(p.strip().split(kvsep))
                key_vals = [(p[0], ' '.join(p[1:])) for p in pieces]
        if (dialect['fmt'] == 'gff3'):
            key_vals = [p.split(kvsep) for p in parts]
        else:
            leadingsemicolon = dialect['leading semicolon']
            pieces = []
            for (i, p) in enumerate(parts):
                if ((i == 0) and leadingsemicolon):
                    p = p[1:]
                pieces.append(p.strip().split(kvsep))
                key_vals = [(p[0], ' '.join(p[1:])) for p in pieces]
        quoted = dialect['quoted GFF2 values']
        for item in key_vals:
            if (len(item) == 2):
                (key, val) = item
            else:
                assert (len(item) == 1), item
                key = item[0]
                val = ''
            try:
                quals[key]
            except KeyError:
                quals[key] = []
            if quoted:
                if ((len(val) > 0) and (val[0] == '"') and (val[(- 1)] == '"')):
                    val = val[1:(- 1)]
            if val:
                vals = val.split(',')
                quals[key].extend(vals)
        return (quals, dialect)
    dialect['order'] = []
    if (keyval_str[(- 1)] == ';'):
        keyval_str = keyval_str[:(- 1)]
        dialect['trailing semicolon'] = True
    for sep in (' ; ', '; ', ';'):
        parts = keyval_str.split(sep)
        if (len(parts) > 1):
            dialect['field separator'] = sep
            break
    if gff3_kw_pat.match(parts[0]):
        key_vals = [p.split('=') for p in parts]
        dialect['fmt'] = 'gff3'
        dialect['keyval separator'] = '='
    else:
        dialect['keyval separator'] = ' '
        pieces = []
        for p in parts:
            if (p and (p[0] == ';')):
                p = p[1:]
                dialect['leading semicolon'] = True
            pieces.append(p.strip().split(' '))
        key_vals = [(p[0], ' '.join(p[1:])) for p in pieces]
    for item in key_vals:
        if (len(item) == 2):
            (key, val) = item
        else:
            assert (len(item) == 1), item
            key = item[0]
            val = ''
        if (key in quals):
            dialect['repeated keys'] = True
        else:
            quals[key] = []
        if ((len(val) > 0) and (val[0] == '"') and (val[(- 1)] == '"')):
            val = val[1:(- 1)]
            dialect['quoted GFF2 values'] = True
        if val:
            vals = val.split(',')
            if ((len(vals) > 1) and dialect['repeated keys']):
                raise AttributeStringError('Internally inconsistent attributes formatting: some have repeated keys, some do not.')
            quals[key].extend(vals)
        dialect['order'].append(key)
    if ((dialect['keyval separator'] == ' ') and dialect['quoted GFF2 values']):
        dialect['fmt'] = 'gtf'
    return (quals, dialect)

dataset/ETHPy150Open daler/gffutils/gffutils/parser.py _split_keyvals/original