如何在不编写文档字符串的情况下从 Python 文件创建文档?我想从所有对象、类和函数中创建一棵树。例如,这是我的 python 文件:
from core.server import handler
from core.ras import ras_main,ras
from core.lib.sort import SortedList,SortedDic
from core.lib.general import *
from core.lib.multi_strs import MultiStr
from core.ippool import ippool_main
class RasHandler(handler.Handler):
def __init__(self):
handler.Handler.__init__(self,"ras")
self.registerHandlerMethod("addNewRas")
self.registerHandlerMethod("getRasInfo")
self.registerHandlerMethod("getActiveRasIPs")
self.registerHandlerMethod("getRasDescriptions")
self.registerHandlerMethod("getInActiveRases")
self.registerHandlerMethod("getRasTypes")
self.registerHandlerMethod("getRasAttributes")
self.registerHandlerMethod("getRasPorts")
self.registerHandlerMethod("updateRasInfo")
self.registerHandlerMethod("updateAttributes")
self.registerHandlerMethod("resetAttributes")
self.registerHandlerMethod("getPortTypes")
self.registerHandlerMethod("addPort")
self.registerHandlerMethod("delPort")
self.registerHandlerMethod("updatePort")
self.registerHandlerMethod("deActiveRas")
self.registerHandlerMethod("deleteRas")
self.registerHandlerMethod("reActiveRas")
self.registerHandlerMethod("getRasPortInfo")
self.registerHandlerMethod("getRasIPpools")
self.registerHandlerMethod("addIPpoolToRas")
self.registerHandlerMethod("delIPpoolFromRas")
def addNewRas(self,request):
request.needAuthType(request.ADMIN)
creator_obj=request.getAuthNameObj()
creator_obj.canDo("CHANGE RAS")
request.checkArgs("ras_ip","ras_type","radius_secret","ras_description","comment")
ras_id=ras_main.getActionManager().addNewRas(request["ras_ip"].strip(),
request["ras_description"].strip(),
request["ras_type"],
request["radius_secret"],
request["comment"],
creator_obj.getAdminID(),
creator_obj.getISPID(),
request.getRemoteAddr()
)
return ras_id
def getRasInfo(self,request):
request.needAuthType(request.ADMIN)
requester_obj=request.getAuthNameObj()
requester_obj.canDo("GET RAS INFORMATION")
request.checkArgs("ras_ip")
requester_obj.checkAccessToRasByIP(request["ras_ip"])
ras_obj=ras_main.getLoader().getRasByIP(request["ras_ip"])
return ras_obj.getInfo()
def getActiveRasIPs(self,request):
request.needAuthType(request.ADMIN)
creator_obj=request.getAuthNameObj()
if request.has_key("type_filter"):
types = request.fixList("type_filter")
def typeFilter(ras_obj):
if ras_obj.getType() in types:
return ras_obj.getRasIP()
return None
ras_ips = filter(None, ras_main.getLoader().runOnAllRases(typeFilter))
else:
ras_ips = ras_main.getLoader().getAllRasIPs()
ras_ips = filter(creator_obj.hasAccessToRasByIP, ras_ips)
sorted=SortedList(ras_ips)
sorted.sort(False)
return sorted.getList()
def getRasDescriptions(self,request):
"""
return list of tuples in format [(ras_description,ras_ip)]
"""
request.needAuthType(request.ADMIN)
requester_obj=request.getAuthNameObj()
desc_to_ip_map = ras_main.getLoader().getRasDescToIPMap()
for ras_desc, ras_ip in desc_to_ip_map.items():
if not requester_obj.hasAccessToRasByIP(ras_ip):
del(desc_to_ip_map[ras_desc])
sorted=SortedDic(desc_to_ip_map)
sorted.sortByKey(False)
return sorted.getList()
def getInActiveRases(self,request):
request.needAuthType(request.ADMIN)
creator_obj=request.getAuthNameObj()
creator_obj.canDo("LIST RAS")
return ras_main.getActionManager().getInActiveRases()
def getRasTypes(self,request):
"""
return a list of all available ras types
"""
request.needAuthType(request.ADMIN)
creator_obj=request.getAuthNameObj()
creator_obj.canDo("GET RAS INFORMATION")
type_list=ras_main.getFactory().getAllTypes()
sorted = SortedList(type_list)
sorted.sort(False)
return sorted.getList()
def getRasAttributes(self,request):
request.needAuthType(request.ADMIN)
request.checkArgs("ras_ip")
requester_obj=request.getAuthNameObj()
requester_obj.canDo("GET RAS INFORMATION")
requester_obj.checkAccessToRasByIP(request["ras_ip"])
return ras_main.getLoader().getRasByIP(request["ras_ip"]).getAllAttributes()
例如,我想要我的结果信息,例如我们有多少个函数、类?以及函数和类的关系。我不会使用help()
anddir()
方法,因为我没有任何依赖模块。我认为应该是使用re
模块解析Python文件和使用正则表达式。