37 |
37 |
38 |
38 |
39 def checkTryExceptPass(reportError, context, config): |
39 def checkTryExceptPass(reportError, context, config): |
40 """ |
40 """ |
41 Function to check for a pass in the except block. |
41 Function to check for a pass in the except block. |
42 |
42 |
43 @param reportError function to be used to report errors |
43 @param reportError function to be used to report errors |
44 @type func |
44 @type func |
45 @param context security context object |
45 @param context security context object |
46 @type SecurityContext |
46 @type SecurityContext |
47 @param config dictionary with configuration data |
47 @param config dictionary with configuration data |
48 @type dict |
48 @type dict |
49 """ |
49 """ |
50 checkTypedException = ( |
50 checkTypedException = ( |
51 config["check_typed_exception"] |
51 config["check_typed_exception"] |
52 if config and "check_typed_exception" in config else |
52 if config and "check_typed_exception" in config |
53 SecurityDefaults["check_typed_exception"] |
53 else SecurityDefaults["check_typed_exception"] |
54 ) |
54 ) |
55 |
55 |
56 node = context.node |
56 node = context.node |
57 if len(node.body) == 1: |
57 if len(node.body) == 1: |
58 if ( |
58 if ( |
59 not checkTypedException and |
59 not checkTypedException |
60 node.type is not None and |
60 and node.type is not None |
61 getattr(node.type, 'id', None) != 'Exception' |
61 and getattr(node.type, "id", None) != "Exception" |
62 ): |
62 ): |
63 return |
63 return |
64 |
64 |
65 if isinstance(node.body[0], ast.Pass): |
65 if isinstance(node.body[0], ast.Pass): |
66 reportError( |
66 reportError( |
67 context.node.lineno - 1, |
67 context.node.lineno - 1, |
68 context.node.col_offset, |
68 context.node.col_offset, |
69 "S110", |
69 "S110", |
73 |
73 |
74 |
74 |
75 def checkTryExceptContinue(reportError, context, config): |
75 def checkTryExceptContinue(reportError, context, config): |
76 """ |
76 """ |
77 Function to check for a continue in the except block. |
77 Function to check for a continue in the except block. |
78 |
78 |
79 @param reportError function to be used to report errors |
79 @param reportError function to be used to report errors |
80 @type func |
80 @type func |
81 @param context security context object |
81 @param context security context object |
82 @type SecurityContext |
82 @type SecurityContext |
83 @param config dictionary with configuration data |
83 @param config dictionary with configuration data |
84 @type dict |
84 @type dict |
85 """ |
85 """ |
86 checkTypedException = ( |
86 checkTypedException = ( |
87 config["check_typed_exception"] |
87 config["check_typed_exception"] |
88 if config and "check_typed_exception" in config else |
88 if config and "check_typed_exception" in config |
89 SecurityDefaults["check_typed_exception"] |
89 else SecurityDefaults["check_typed_exception"] |
90 ) |
90 ) |
91 |
91 |
92 node = context.node |
92 node = context.node |
93 if len(node.body) == 1: |
93 if len(node.body) == 1: |
94 if ( |
94 if ( |
95 not checkTypedException and |
95 not checkTypedException |
96 node.type is not None and |
96 and node.type is not None |
97 getattr(node.type, 'id', None) != 'Exception' |
97 and getattr(node.type, "id", None) != "Exception" |
98 ): |
98 ): |
99 return |
99 return |
100 |
100 |
101 if isinstance(node.body[0], ast.Continue): |
101 if isinstance(node.body[0], ast.Continue): |
102 reportError( |
102 reportError( |
103 context.node.lineno - 1, |
103 context.node.lineno - 1, |
104 context.node.col_offset, |
104 context.node.col_offset, |
105 "S112", |
105 "S112", |