ScoutSuite icon indicating copy to clipboard operation
ScoutSuite copied to clipboard

Increase the usage of augmented assignment statements

Open elfring opened this issue 4 years ago • 0 comments

:eyes: Some source code analysis tools can help to find opportunities for improving software components. :thought_balloon: I propose to increase the usage of augmented assignment statements accordingly.

diff --git a/ScoutSuite/core/console.py b/ScoutSuite/core/console.py
index 2383ad84..021f157c 100755
--- a/ScoutSuite/core/console.py
+++ b/ScoutSuite/core/console.py
@@ -173,7 +173,7 @@ def prompt_value(question, choices=None, default=None, display_choices=True, dis
     int_choice = 0
 
     if choices and display_choices and not display_indices:
-        question = question + ' (' + '/'.join(choices) + ')'
+        question += ' (' + '/'.join(choices) + ')'
     lap_n = 0
     while True:
         if lap_n >= max_laps:
@@ -183,7 +183,7 @@ def prompt_value(question, choices=None, default=None, display_choices=True, dis
         can_return = False
         # Display the question, choices, and prompt for the answer
         if is_question:
-            question = question + '? '
+            question += '? '
         print_error(question)
         if choices and display_indices:
             for c in choices:
diff --git a/ScoutSuite/core/utils.py b/ScoutSuite/core/utils.py
index e210bac4..cec6653c 100755
--- a/ScoutSuite/core/utils.py
+++ b/ScoutSuite/core/utils.py
@@ -55,14 +55,14 @@ def recurse(all_info, current_info, target_path, current_path, config, add_suffi
         if attribute in current_info:
             split_path = copy.deepcopy(current_path)
             split_path.append(attribute)
-            results = results + recurse(all_info, current_info[attribute], target_path, split_path, config, add_suffix)
+            results += recurse(all_info, current_info[attribute], target_path, split_path, config, add_suffix)
         elif attribute == 'id':
             for key in current_info:
                 split_target_path = copy.deepcopy(target_path)
                 split_current_path = copy.deepcopy(current_path)
                 split_current_path.append(key)
                 split_current_info = current_info[key]
-                results = results + recurse(all_info, split_current_info, split_target_path, split_current_path,
+                results += recurse(all_info, split_current_info, split_target_path, split_current_path,
                                             config, add_suffix)
     # To handle lists properly, I would have to make sure the list is properly ordered and I can use the index to
     # consistently access an object... Investigate (or do not use lists)
@@ -70,12 +70,12 @@ def recurse(all_info, current_info, target_path, current_path, config, add_suffi
         for index, split_current_info in enumerate(current_info):
             split_current_path = copy.deepcopy(current_path)
             split_current_path.append(str(index))
-            results = results + recurse(all_info, split_current_info, copy.deepcopy(target_path), split_current_path,
+            results += recurse(all_info, split_current_info, copy.deepcopy(target_path), split_current_path,
                                         config, add_suffix)
     # Python 2-3 compatible way to check for string type
     elif isinstance(current_info, str):
         split_current_path = copy.deepcopy(current_path)
-        results = results + recurse(all_info, current_info, [], split_current_path,
+        results += recurse(all_info, current_info, [], split_current_path,
                                     config, add_suffix)
     else:
         print_exception('Unable to recursively test condition for path {}: '
diff --git a/ScoutSuite/output/html.py b/ScoutSuite/output/html.py
index 4c49a9ec..a0b67590 100755
--- a/ScoutSuite/output/html.py
+++ b/ScoutSuite/output/html.py
@@ -45,7 +45,7 @@ class HTMLReport:
         for filename in template_files:
             try:
                 with open('%s' % filename) as f:
-                    contents = contents + f.read()
+                    contents += f.read()
             except Exception as e:
                 print_exception(f'Error reading filename {filename}: {e}')
         return contents
@@ -56,7 +56,7 @@ class HTMLReport:
         filename = template_dir + filename
         try:
             with open('%s' % filename) as f:
-                contents = contents + f.read()
+                contents += f.read()
         except Exception as e:
             print_exception(f'Error reading filename {filename}: {e}')
         return contents
diff --git a/ScoutSuite/providers/aws/provider.py b/ScoutSuite/providers/aws/provider.py
index 5ce6ffe1..63614928 100755
--- a/ScoutSuite/providers/aws/provider.py
+++ b/ScoutSuite/providers/aws/provider.py
@@ -545,7 +545,7 @@ class AWSProvider(BaseProvider):
                         vpc_id = self.sg_map[sg_id]['vpc_id']
                         sg_base_path = copy.deepcopy(current_path[0:4])
                         sg_base_path[1] = 'ec2'
-                        sg_base_path = sg_base_path + \
+                        sg_base_path += \
                                        ['vpcs', vpc_id, 'security_groups']
                     else:
                         sg_base_path = copy.deepcopy(current_path[0:6])
diff --git a/ScoutSuite/providers/aws/resources/ec2/securitygroups.py b/ScoutSuite/providers/aws/resources/ec2/securitygroups.py
index ce688a78..600b457f 100755
--- a/ScoutSuite/providers/aws/resources/ec2/securitygroups.py
+++ b/ScoutSuite/providers/aws/resources/ec2/securitygroups.py
@@ -94,13 +94,13 @@ class SecurityGroups(AWSResources):
                     protocols[ip_protocol]['ports'][port_value], 'security_groups', [])
                 protocols[ip_protocol]['ports'][port_value]['security_groups'].append(
                     grant)
-                rules_count = rules_count + 1
+                rules_count += 1
             for grant in rule['IpRanges']:
                 manage_dictionary(
                     protocols[ip_protocol]['ports'][port_value], 'cidrs', [])
                 protocols[ip_protocol]['ports'][port_value]['cidrs'].append(
                     {'CIDR': grant['CidrIp']})
-                rules_count = rules_count + 1
+                rules_count += 1
 
             # IPv6
             for grant in rule['Ipv6Ranges']:
@@ -108,6 +108,6 @@ class SecurityGroups(AWSResources):
                     protocols[ip_protocol]['ports'][port_value], 'cidrs', [])
                 protocols[ip_protocol]['ports'][port_value]['cidrs'].append(
                     {'CIDR': grant['CidrIpv6']})
-                rules_count = rules_count + 1
+                rules_count += 1
 
         return protocols, rules_count
diff --git a/ScoutSuite/providers/base/configs/browser.py b/ScoutSuite/providers/base/configs/browser.py
index dfa4be90..3a0b9e6f 100755
--- a/ScoutSuite/providers/base/configs/browser.py
+++ b/ScoutSuite/providers/base/configs/browser.py
@@ -86,7 +86,7 @@ def get_value_at(all_info, current_path, key, to_string=False):
                                                         'i': i})
                     return None
             if len(keys) > len(current_path):
-                target_path = target_path + keys[len(target_path):]
+                target_path += keys[len(target_path):]
         else:
             target_path = copy.deepcopy(current_path)
             target_path.append(key)

elfring avatar Nov 22 '21 21:11 elfring