<commit_before>import re

_pkg_url_re = re.compile(u"^'([^']+)' ([^ ]+) (\d+) (([^:]+:)?.+)")
def _parse_pkg_url(line):
    return _pkg_url_re.match(line).groups()

def parse_apt_install(out):
    res = []

    extra = []
    suggested = []
    recommended = []
    install = []
    packages = []
    newest = []

    out2 = out.replace("\n  ", "  ")
    for line in out2.splitlines():
        if line.endswith('is already the newest version.'):
            newest.append(line.split(' ', 1)[0])
        elif line.startswith('The following extra packages will be installed:'):
            extra = line.split(':', 1)[1].strip().split()
        elif line.startswith('Suggested packages:'):
            suggested = line.split(':', 1)[1].strip().split()
        elif line.startswith('Recommended packages:'):
            recommended = line.split(':', 1)[1].strip().split()
        elif line.startswith('The following NEW packages will be installed:'):
            install = line.split(':', 1)[1].strip().split()
        elif line.startswith("'"):
            packages.append(_parse_pkg_url(line))

    return extra, suggested, recommended, install, packages, newest

def parse_apt_search(out):
    res = []
    
    for line in out.splitlines():
        p = line.split(' ', 2)
        res.append((p[0], p[2]))

    return res

def parse_apt_show(out):
    res = {}
    keys = []
    field = None
    
    for line in out.splitlines():
        if line.strip() == '':
            continue

        if line.startswith(' '):
            content = line.strip()
            if content == '.':
                content = ''
        else:
            field, content = line.split(':', 1)
            content = content.strip()
            keys.append(field)

        c = res.get(field, [])
        c.append(content)
        res[field] = c

    for key in keys:
        res[key] = "\n".join(res[key])

    return res, keys
    
if __name__ == '__main__':
    #print parse_apt_install(open('/tmp/apt-install.txt').read())
    #print parse_apt_search(open('/tmp/apt-search.txt').read())
    print parse_apt_show(open('/tmp/apt-show.txt').read())
<commit_msg>Fix bug<commit_after>import re

_pkg_url_re = re.compile(u"^'([^']+)' ([^ ]+) (\d+) (([^:]+:)?.+)")
def _parse_pkg_url(line):
    return _pkg_url_re.match(line).groups()

def parse_apt_install(out):
    res = []

    extra = []
    suggested = []
    recommended = []
    install = []
    packages = []
    newest = []

    out2 = out.replace("\n  ", "  ")
    for line in out2.splitlines():
        if line.endswith('is already the newest version.'):
            newest.append(line.split(' ', 1)[0])
        elif line.startswith('The following extra packages will be installed:'):
            extra = line.split(':', 1)[1].strip().split()
        elif line.startswith('Suggested packages:'):
            suggested = line.split(':', 1)[1].strip().split()
        elif line.startswith('Recommended packages:'):
            recommended = line.split(':', 1)[1].strip().split()
        elif line.startswith('The following NEW packages will be installed:'):
            install = line.split(':', 1)[1].strip().split()
        elif line.startswith("'"):
            packages.append(_parse_pkg_url(line))

    return extra, suggested, recommended, install, packages, newest

def parse_apt_search(out):
    res = []
    
    for line in out.splitlines():
        p = line.split(' ', 2)
        res.append((p[0], p[2]))

    return res

def parse_apt_show(out):
    res = {}
    keys = []
    field = None
    
    for line in out.splitlines():
        if line.strip() == '':
            continue

        if line.startswith(' '):
            content = line.strip()
            if content == '.':
                content = ''
        else:
            field, content = line.split(':', 1)
            content = content.strip()
            keys.append(field)

        c = res.get(field, [])
        c.append(content)
        res[field] = c

    values = {}
    for key in keys:
        values[key] = "\n".join(res[key])

    return values, keys
    
if __name__ == '__main__':
    #print parse_apt_install(open('/tmp/apt-install.txt').read())
    #print parse_apt_search(open('/tmp/apt-search.txt').read())
    print parse_apt_show(open('/tmp/apt-show.txt').read())

{'fraction_non_alphanumeric': 0.1744294364229157, 'fraction_numerical': 0.007452258965999069, 'mean_word_length': 2.2661596958174903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2866952', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1340, 'n_words': 284}