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

branch
maintenance
changeset 8273
698ae46f40a4
parent 8043
0acf98cd089a
parent 8228
772103b14c18
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
22 import AstUtilities 22 import AstUtilities
23 23
24 from . import SecurityUtils 24 from . import SecurityUtils
25 25
26 26
27 class SecurityContext(object): 27 class SecurityContext:
28 """ 28 """
29 Class implementing a context class for security related checks. 29 Class implementing a context class for security related checks.
30 """ 30 """
31 def __init__(self, contextObject=None): 31 def __init__(self, contextObject=None):
32 """ 32 """
229 @rtype Any 229 @rtype Any
230 """ 230 """
231 if AstUtilities.isNumber(literal): 231 if AstUtilities.isNumber(literal):
232 literalValue = literal.n 232 literalValue = literal.n
233 233
234 elif AstUtilities.isString(literal): 234 elif AstUtilities.isString(literal) or AstUtilities.isBytes(literal):
235 literalValue = literal.s 235 literalValue = literal.s
236 236
237 elif isinstance(literal, ast.List): 237 elif isinstance(literal, ast.List):
238 returnList = [] 238 returnList = []
239 for li in literal.elts: 239 for li in literal.elts:
266 literalValue = literal.id 266 literalValue = literal.id
267 267
268 elif AstUtilities.isNameConstant(literal): 268 elif AstUtilities.isNameConstant(literal):
269 literalValue = str(literal.value) 269 literalValue = str(literal.value)
270 270
271 elif AstUtilities.isBytes(literal):
272 literalValue = literal.s
273
274 else: 271 else:
275 literalValue = None 272 literalValue = None
276 273
277 return literalValue 274 return literalValue
278 275
307 argValue = self.getCallArgValue(argumentName) 304 argValue = self.getCallArgValue(argumentName)
308 if argValue is not None: 305 if argValue is not None:
309 if not isinstance(argumentValues, list): 306 if not isinstance(argumentValues, list):
310 # if passed a single value, or a tuple, convert to a list 307 # if passed a single value, or a tuple, convert to a list
311 argumentValues = [argumentValues] 308 argumentValues = [argumentValues]
312 for val in argumentValues: 309 return any(argValue == val for val in argumentValues)
313 if argValue == val:
314 return True
315 return False
316 else: 310 else:
317 # argument name not found, return None to allow testing for this 311 # argument name not found, return None to allow testing for this
318 # eventuality 312 # eventuality
319 return None 313 return None
320 314
400 @param module module name to look for 394 @param module module name to look for
401 @type str 395 @type str
402 @return flag indicating the given module was found 396 @return flag indicating the given module was found
403 @rtype bool 397 @rtype bool
404 """ 398 """
405 if 'imports' in self.__context: 399 try:
406 for imp in self.__context['imports']: 400 return any(module in imp for imp in self.__context['imports'])
407 if module in imp: 401 except KeyError:
408 return True 402 return False
409
410 return False

eric ide

mercurial