181 |
181 |
182 @param node reference to the node being inspected |
182 @param node reference to the node being inspected |
183 @type ast.Constant |
183 @type ast.Constant |
184 """ |
184 """ |
185 if isinstance(node.value, str): |
185 if isinstance(node.value, str): |
186 self.visit_Str(node) |
186 self.__context["str"] = node.value |
|
187 if not isinstance(node._securityParent, ast.Expr): # docstring |
|
188 self.__context["linerange"] = SecurityUtils.linerange_fix( |
|
189 node._securityParent |
|
190 ) |
|
191 self.__runChecks("Str") |
187 elif isinstance(node.value, bytes): |
192 elif isinstance(node.value, bytes): |
188 self.visit_Bytes(node) |
193 self.__context["bytes"] = node.value |
189 |
194 if not isinstance(node._securityParent, ast.Expr): # docstring |
190 def visit_Str(self, node): |
195 self.__context["linerange"] = SecurityUtils.linerange_fix( |
191 """ |
196 node._securityParent |
192 Public method defining a visitor for String nodes. |
197 ) |
193 |
198 self.__runChecks("Bytes") |
194 This adds relevant information about node to |
|
195 the context for use in tests which inspect strings. |
|
196 |
|
197 @param node reference to the node being inspected |
|
198 @type ast.Str |
|
199 """ |
|
200 self.__context["str"] = node.s |
|
201 if not isinstance(node._securityParent, ast.Expr): # docstring |
|
202 self.__context["linerange"] = SecurityUtils.linerange_fix( |
|
203 node._securityParent |
|
204 ) |
|
205 self.__runChecks("Str") |
|
206 |
|
207 def visit_Bytes(self, node): |
|
208 """ |
|
209 Public method defining a visitor for Bytes nodes. |
|
210 |
|
211 This adds relevant information about node to |
|
212 the context for use in tests which inspect strings. |
|
213 |
|
214 @param node reference to the node being inspected |
|
215 @type ast.Bytes |
|
216 """ |
|
217 self.__context["bytes"] = node.s |
|
218 if not isinstance(node._securityParent, ast.Expr): # docstring |
|
219 self.__context["linerange"] = SecurityUtils.linerange_fix( |
|
220 node._securityParent |
|
221 ) |
|
222 self.__runChecks("Bytes") |
|
223 |
199 |
224 def __preVisit(self, node): |
200 def __preVisit(self, node): |
225 """ |
201 """ |
226 Private method to set up a context for the visit method. |
202 Private method to set up a context for the visit method. |
227 |
203 |