Exemplo n.º 1
0
def show_module(mod):
	
	for key, value in inspect.getmembers(mod, inspect.ismodule):
		print 'import ' + key
	for key, value in inspect.getmembers(mod, 
										lambda obj: is_imported_obj(mod, obj)):
		print 'from ' + value.__module__ + ' import ' + key

	print
	known_globals = set([])
	for name, value in get_data(mod):	
		print name, '=', repr(value)
		known_globals.add(name)
	
	print
	
	for key, value in inspect.getmembers(mod, inspect.isclass):
		if inspect.getmodule(value) == mod:
			show_class(key, value, known_globals)
	
	print
	
	for key, value in inspect.getmembers(mod, inspect.isfunction):
		if inspect.getmodule(value) == mod:
			show_function(key, value, known_globals)
			print
Exemplo n.º 2
0
def show_class(class_name, cls, known_globals):
	base_names = []
	for base in cls.__bases__:
		baseclass_fullname = str(base).split("'")[1]
		baseclass_name = baseclass_fullname.split('.')[-1]
		base_names.append(baseclass_name)
	print 'class %s(%s):' % (class_name, ', '.join(base_names))
	print_doc_string(1, cls)
	# retrieve class attributes
	for name, value in get_data(cls):	
		print_code_line(1, name + ' = ' + repr(value))
	# retrieve methods
	for class_attr in inspect.classify_class_attrs(cls):
		#print '#', class_attr 
		name, kind, owner_cls, attr = class_attr
		# a method may be inherited from a parent class
		# we want to only print methods defined in this 
		# object.
		# also we only print methods.
		if owner_cls == cls and kind != 'data':
			show_function(name, attr, known_globals, indent=1)
			print
#			print class_name, name
#			if class_name.startswith('rs232') and name == 'reset':
	print
Exemplo n.º 3
0
def show_class(class_name, cls, known_globals):
    base_names = []
    for base in cls.__bases__:
        baseclass_fullname = str(base).split("'")[1]
        baseclass_name = baseclass_fullname.split('.')[-1]
        base_names.append(baseclass_name)
    print 'class %s(%s):' % (class_name, ', '.join(base_names))
    print_doc_string(1, cls)
    # retrieve class attributes
    for name, value in get_data(cls):
        print_code_line(1, name + ' = ' + repr(value))
    # retrieve methods
    for class_attr in inspect.classify_class_attrs(cls):
        #print '#', class_attr
        name, kind, owner_cls, attr = class_attr
        # a method may be inherited from a parent class
        # we want to only print methods defined in this
        # object.
        # also we only print methods.
        if owner_cls == cls and kind != 'data':
            show_function(name, attr, known_globals, indent=1)
            print
#			print class_name, name
#			if class_name.startswith('rs232') and name == 'reset':
    print
Exemplo n.º 4
0
def show_module(mod):

    for key, value in inspect.getmembers(mod, inspect.ismodule):
        print 'import ' + key
    for key, value in inspect.getmembers(
            mod, lambda obj: is_imported_obj(mod, obj)):
        print 'from ' + value.__module__ + ' import ' + key

    print
    known_globals = set([])
    for name, value in get_data(mod):
        print name, '=', repr(value)
        known_globals.add(name)

    print

    for key, value in inspect.getmembers(mod, inspect.isclass):
        if inspect.getmodule(value) == mod:
            show_class(key, value, known_globals)

    print

    for key, value in inspect.getmembers(mod, inspect.isfunction):
        if inspect.getmodule(value) == mod:
            show_function(key, value, known_globals)
            print