src/eric7/Plugins/CheckerPlugins/CodeStyleChecker/Security/Checks/__init__.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9274
86fab0c74430
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
12 12
13 13
14 def generateCheckersDict(): 14 def generateCheckersDict():
15 """ 15 """
16 Function to generate the dictionary with checkers. 16 Function to generate the dictionary with checkers.
17 17
18 Checker modules are searched for inside this package. Each module 18 Checker modules are searched for inside this package. Each module
19 defining some checks must contain a function 'getChecks()' returning 19 defining some checks must contain a function 'getChecks()' returning
20 a dictionary containing the check type as key and a list of tuples 20 a dictionary containing the check type as key and a list of tuples
21 with the check function and associated message codes. 21 with the check function and associated message codes.
22 22
23 @return dictionary containing list of tuples with checker data 23 @return dictionary containing list of tuples with checker data
24 @rtype dict 24 @rtype dict
25 """ 25 """
26 checkersDict = collections.defaultdict(list) 26 checkersDict = collections.defaultdict(list)
27 27
28 checkersDirectory = os.path.dirname(__file__) 28 checkersDirectory = os.path.dirname(__file__)
29 checkerModules = [os.path.splitext(m)[0] 29 checkerModules = [
30 for m in os.listdir(checkersDirectory) 30 os.path.splitext(m)[0]
31 if m != "__init__.py" and m.endswith(".py")] 31 for m in os.listdir(checkersDirectory)
32 32 if m != "__init__.py" and m.endswith(".py")
33 ]
34
33 for checkerModule in checkerModules: 35 for checkerModule in checkerModules:
34 modName = "Security.Checks.{0}".format(checkerModule) 36 modName = "Security.Checks.{0}".format(checkerModule)
35 try: 37 try:
36 mod = __import__(modName) 38 mod = __import__(modName)
37 components = modName.split('.') 39 components = modName.split(".")
38 for comp in components[1:]: 40 for comp in components[1:]:
39 mod = getattr(mod, comp) 41 mod = getattr(mod, comp)
40 except ImportError: 42 except ImportError:
41 continue 43 continue
42 44
43 if not hasattr(mod, "getChecks"): 45 if not hasattr(mod, "getChecks"):
44 continue 46 continue
45 47
46 modCheckersDict = mod.getChecks() 48 modCheckersDict = mod.getChecks()
47 for checktype, checks in modCheckersDict.items(): 49 for checktype, checks in modCheckersDict.items():
48 checkersDict[checktype].extend(checks) 50 checkersDict[checktype].extend(checks)
49 51
50 return checkersDict 52 return checkersDict

eric ide

mercurial