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

changeset 7622
384e2aa5c073
parent 7614
646742c260bd
child 7637
c878e8255972
equal deleted inserted replaced
7621:ffd1f00ca376 7622:384e2aa5c073
17 17
18 import ast 18 import ast
19 import copy 19 import copy
20 import sys 20 import sys
21 21
22 import AstUtilities
23
22 from . import SecurityUtils 24 from . import SecurityUtils
23 25
24 26
25 class SecurityContext(object): 27 class SecurityContext(object):
26 """ 28 """
226 @param literal AST literal to be converted 228 @param literal AST literal to be converted
227 @type ast.AST 229 @type ast.AST
228 @return converted Python object 230 @return converted Python object
229 @rtype Any 231 @rtype Any
230 """ 232 """
231 if isinstance(literal, ast.Num): 233 if AstUtilities.isNumber(literal):
232 literalValue = literal.n 234 literalValue = literal.n
233 235
234 elif isinstance(literal, ast.Str): 236 elif AstUtilities.isString(literal):
235 literalValue = literal.s 237 literalValue = literal.s
236 238
237 elif isinstance(literal, ast.List): 239 elif isinstance(literal, ast.List):
238 returnList = [] 240 returnList = []
239 for li in literal.elts: 241 for li in literal.elts:
253 literalValue = returnSet 255 literalValue = returnSet
254 256
255 elif isinstance(literal, ast.Dict): 257 elif isinstance(literal, ast.Dict):
256 literalValue = dict(zip(literal.keys, literal.values)) 258 literalValue = dict(zip(literal.keys, literal.values))
257 259
258 elif isinstance(literal, ast.Ellipsis): 260 elif (
261 sys.version_info <= (3, 8, 0) and
262 isinstance(literal, ast.Ellipsis)
263 ):
259 # what do we want to do with this? 264 # what do we want to do with this?
260 literalValue = None 265 literalValue = None
261 266
262 elif isinstance(literal, ast.Name): 267 elif isinstance(literal, ast.Name):
263 literalValue = literal.id 268 literalValue = literal.id
265 # NameConstants are only part of the AST in Python 3. NameConstants 270 # NameConstants are only part of the AST in Python 3. NameConstants
266 # tend to refer to things like True and False. This prevents them from 271 # tend to refer to things like True and False. This prevents them from
267 # being re-assigned in Python 3. 272 # being re-assigned in Python 3.
268 elif ( 273 elif (
269 sys.version_info[0] >= 3 and 274 sys.version_info[0] >= 3 and
270 isinstance(literal, ast.NameConstant) 275 AstUtilities.isNameConstant(literal)
271 ): 276 ):
272 literalValue = str(literal.value) 277 literalValue = str(literal.value)
273 278
274 # Bytes are only part of the AST in Python 3 279 # Bytes are only part of the AST in Python 3
275 elif ( 280 elif (
276 sys.version_info[0] >= 3 and 281 sys.version_info[0] >= 3 and
277 isinstance(literal, ast.Bytes) 282 AstUtilities.isBytes(literal)
278 ): 283 ):
279 literalValue = literal.s 284 literalValue = literal.s
280 285
281 else: 286 else:
282 literalValue = None 287 literalValue = None

eric ide

mercurial