eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/__init__.py

changeset 7613
382f89c11e27
parent 7612
ca1ce1e0fcff
child 7923
91e843545d9a
equal deleted inserted replaced
7612:ca1ce1e0fcff 7613:382f89c11e27
6 """ 6 """
7 Package containing the various security checker modules. 7 Package containing the various security checker modules.
8 """ 8 """
9 9
10 import collections 10 import collections
11 11 import os
12 _checkermodules = [
13 "blackListCalls",
14 "blackListImports",
15 ]
16 12
17 13
18 def generateCheckersDict(): 14 def generateCheckersDict():
19 """ 15 """
20 Function generate the dictionary with checkers. 16 Function to generate the dictionary with checkers.
17
18 Checker modules are searched for inside this package. Each module
19 defining some checks must contain a function 'getChecks()' returning
20 a dictionary containing the check type as key and a list of tuples
21 with the check function and associated message codes.
21 22
22 @return dictionary containing list of tuples with checker data 23 @return dictionary containing list of tuples with checker data
23 @rtype dict 24 @rtype dict
24 """ 25 """
25 checkersDict = collections.defaultdict(list) 26 checkersDict = collections.defaultdict(list)
26 27
27 for checkerModule in _checkermodules: 28 checkersDirectory = os.path.dirname(__file__)
29 checkerModules = [os.path.splitext(m)[0]
30 for m in os.listdir(checkersDirectory)
31 if m != "__init__.py" and m.endswith(".py")]
32
33 for checkerModule in checkerModules:
28 modName = "Security.Checks.{0}".format(checkerModule) 34 modName = "Security.Checks.{0}".format(checkerModule)
29 try: 35 try:
30 mod = __import__(modName) 36 mod = __import__(modName)
31 components = modName.split('.') 37 components = modName.split('.')
32 for comp in components[1:]: 38 for comp in components[1:]:
36 42
37 if not hasattr(mod, "getChecks"): 43 if not hasattr(mod, "getChecks"):
38 continue 44 continue
39 45
40 modCheckersDict = mod.getChecks() 46 modCheckersDict = mod.getChecks()
41 for checktype, check in modCheckersDict.items(): 47 for checktype, checks in modCheckersDict.items():
42 checkersDict[checktype].append(check) 48 checkersDict[checktype].extend(checks)
43 49
44 return checkersDict 50 return checkersDict

eric ide

mercurial