<commit_before>#! /usr/bin/env python

import marshal
import dis
import types

def dump(obj):
    print obj
    for attr in dir(obj):
        print "\t", attr, repr(getattr(obj, attr))

def loadCode(path):
    f = open(path)
    f.read(8)
    co = marshal.load(f)
    f.close()
    return co

def walk(co, match=None):
    if match is None or co.co_name == match:
        dump(co)
        print
        dis.dis(co)
    for obj in co.co_consts:
        if type(obj) == types.CodeType:
            walk(obj, match)

def main(filename, codename=None):
    co = loadCode(filename)
    walk(co, codename)

if __name__ == "__main__":
    import sys
    if len(sys.argv) == 3:
        filename, codename = sys.argv[1:]
    else:
        filename = sys.argv[1]
        codename = None
    main(filename, codename)<commit_msg>Only print attributes that start with co_. If passed a .py file as an argument, try to find its accompanying .pyc.<commit_after>#! /usr/bin/env python

import marshal
import os
import dis
import types

def dump(obj):
    print obj
    for attr in dir(obj):
        if attr.startswith('co_'):
            val = getattr(obj, attr)
            print "\t", attr, repr(val)

def loadCode(path):
    f = open(path)
    f.read(8)
    co = marshal.load(f)
    f.close()
    return co

def walk(co, match=None):
    if match is None or co.co_name == match:
        dump(co)
        print
        dis.dis(co)
    for obj in co.co_consts:
        if type(obj) == types.CodeType:
            walk(obj, match)

def main(filename, codename=None):
    co = loadCode(filename)
    walk(co, codename)

if __name__ == "__main__":
    import sys
    if len(sys.argv) == 3:
        filename, codename = sys.argv[1:]
    else:
        filename = sys.argv[1]
        codename = None
    if filename.endswith('.py') and os.path.exists(filename+"c"):
        filename += "c"
    main(filename, codename)
{'fraction_non_alphanumeric': 0.12341772151898735, 'fraction_numerical': 0.004219409282700422, 'mean_word_length': 2.339788732394366, 'pattern_counts': {'":': 2, '<': 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': '1327090', 'n_tokens_mistral': 652, 'n_tokens_neox': 646, 'n_words': 189}