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

changeset 7613
382f89c11e27
parent 7612
ca1ce1e0fcff
child 7614
646742c260bd
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityContext.py	Mon Jun 08 08:17:14 2020 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/SecurityContext.py	Mon Jun 08 20:08:27 2020 +0200
@@ -16,6 +16,7 @@
 #
 
 import ast
+import copy
 import sys
 
 from . import SecurityUtils
@@ -37,13 +38,13 @@
         @type dict
         """
         if contextObject is not None:
-            self.__context = contextObject
+            self.__context = copy.copy(contextObject)
         else:
             self.__context = {}
     
     def __repr__(self):
         """
-        Private method to generate representation of object for printing or
+        Special method to generate representation of object for printing or
         interactive use.
         
         @return string representation of the object
@@ -79,7 +80,10 @@
         @return number of args a function call has
         @rtype int
         """
-        if 'call' in self.__context and hasattr(self.__context['call'], 'args'):
+        if (
+            'call' in self.__context and
+            hasattr(self.__context['call'], 'args')
+        ):
             return len(self.__context['call'].args)
         else:
             return None
@@ -231,13 +235,13 @@
             literalValue = literal.s
         
         elif isinstance(literal, ast.List):
-            returnList = list()
+            returnList = []
             for li in literal.elts:
                 returnList.append(self.__getLiteralValue(li))
             literalValue = returnList
         
         elif isinstance(literal, ast.Tuple):
-            returnTuple = tuple()
+            returnTuple = ()
             for ti in literal.elts:
                 returnTuple = returnTuple + (self.__getLiteralValue(ti),)
             literalValue = returnTuple
@@ -291,6 +295,8 @@
         kwdValues = self.callKeywords
         if kwdValues is not None and argumentName in kwdValues:
             return kwdValues[argumentName]
+        
+        return None
     
     def checkCallArgValue(self, argumentName, argumentValues=None):
         """
@@ -309,7 +315,7 @@
         if argValue is not None:
             if not isinstance(argumentValues, list):
                 # if passed a single value, or a tuple, convert to a list
-                argumentValues = list((argumentValues,))
+                argumentValues = [argumentValues]
             for val in argumentValues:
                 if argValue == val:
                     return True
@@ -332,6 +338,24 @@
             for key in self.node.keywords:
                 if key.arg == argumentName:
                     return key.value.lineno
+        
+        return -1
+    
+    def getOffsetForCallArg(self, argumentName):
+        """
+        Public method to get the offset for a specific named argument.
+        
+        @param argumentName name of the argument to get the line number for
+        @type str
+        @return offset of the found argument or -1
+        @rtype int
+        """
+        if hasattr(self.node, 'keywords'):
+            for key in self.node.keywords:
+                if key.arg == argumentName:
+                    return key.value.col_offset
+        
+        return -1
     
     def getCallArgAtPosition(self, positionNum):
         """

eric ide

mercurial