eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityUtils.py

changeset 7622
384e2aa5c073
parent 7615
ca2949b1a29a
child 7628
f904d0eef264
equal deleted inserted replaced
7621:ffd1f00ca376 7622:384e2aa5c073
7 Module implementing utility functions used by the security checks. 7 Module implementing utility functions used by the security checks.
8 """ 8 """
9 9
10 import ast 10 import ast
11 import os 11 import os
12
13 import AstUtilities
12 14
13 15
14 class InvalidModulePath(Exception): 16 class InvalidModulePath(Exception):
15 """ 17 """
16 Class defining an exception for invalid module paths. 18 Class defining an exception for invalid module paths.
262 264
263 def concatString(node, stop=None): 265 def concatString(node, stop=None):
264 """ 266 """
265 Function to build a string from an ast.BinOp chain. 267 Function to build a string from an ast.BinOp chain.
266 268
267 This will build a string from a series of ast.Str nodes wrapped in 269 This will build a string from a series of ast.Str/ast.Constant nodes
268 ast.BinOp nodes. Something like "a" + "b" + "c" or "a %s" % val etc. 270 wrapped in ast.BinOp nodes. Something like "a" + "b" + "c" or "a %s" % val
269 The provided node can be any participant in the BinOp chain. 271 etc. The provided node can be any participant in the BinOp chain.
270 272
271 @param node node to be processed 273 @param node node to be processed
272 @type ast.BinOp or ast.Str 274 @type ast.BinOp or ast.Str/ast.Constant
273 @param stop base node to stop at 275 @param stop base node to stop at
274 @type ast.BinOp or ast.Str 276 @type ast.BinOp or ast.Str/ast.Constant
275 @return tuple containing the root node of the expression and the string 277 @return tuple containing the root node of the expression and the string
276 value 278 value
277 @rtype tuple of (ast.AST, str) 279 @rtype tuple of (ast.AST, str)
278 """ 280 """
279 def _get(node, bits, stop=None): 281 def _get(node, bits, stop=None):
295 if isinstance(node, ast.BinOp): 297 if isinstance(node, ast.BinOp):
296 _get(node, bits, stop) 298 _get(node, bits, stop)
297 299
298 return ( 300 return (
299 node, 301 node,
300 " ".join([x.s for x in bits if isinstance(x, ast.Str)]) 302 " ".join([x.s for x in bits if AstUtilities.isString(x)])
301 ) 303 )
302 304
303 305
304 def getCalledName(node): 306 def getCalledName(node):
305 """ 307 """

eric ide

mercurial